project.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true" :model="filters">
  6. <el-form-item>
  7. <el-input v-model="filters.keyName" placeholder="请输入项目名称"></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" v-on:click="getProject">查询</el-button>
  11. </el-form-item>
  12. <el-form-item style="float:right;" v-if="user.parentId == 1">
  13. <el-button type="primary" @click="handleAdd">新增</el-button>
  14. </el-form-item>
  15. </el-form>
  16. </el-col>
  17. <!--列表-->
  18. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  19. <el-table-column type="index" width="60">
  20. </el-table-column>
  21. <el-table-column prop="projectName" label="项目名称" width="200" sortable>
  22. </el-table-column>
  23. <el-table-column prop="ownerCompanyName" label="生产方" min-width="200" sortable>
  24. </el-table-column>
  25. <el-table-column prop="charger" label="生产方负责人" sortable>
  26. </el-table-column>
  27. <el-table-column prop="creator" label="项目创建人" sortable>
  28. </el-table-column>
  29. <el-table-column prop="indate" label="创建时间" width="180" sortable>
  30. </el-table-column>
  31. <el-table-column label="操作" width="250">
  32. <template slot-scope="scope">
  33. <el-button size="small" type="primary" @click="toDetail(scope.row.id)">详情</el-button>
  34. <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  35. <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <!--工具条-->
  40. <el-col :span="24" class="toolbar">
  41. <el-pagination
  42. @size-change="handleSizeChange"
  43. @current-change="handleCurrentChange"
  44. :page-sizes="[20 , 50 , 80 , 100]"
  45. :page-size="20"
  46. layout="total, sizes, prev, pager, next"
  47. :total="total"
  48. style="float:right;">
  49. </el-pagination>
  50. </el-col>
  51. <!--新增界面-->
  52. <el-dialog title="新增项目" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  53. <el-form :model="addForm" label-width="120px" :rules="formRules" ref="addForm">
  54. <el-col :span="24">
  55. <el-form-item label="项目名称" prop="projectName">
  56. <el-input v-model="addForm.projectName" autocomplete="off" placeholder="请输入项目名称" style="width:510px"></el-input>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="24">
  60. <el-form-item label="生产方公司" prop="customerCompany">
  61. <el-select v-model="addForm.customerCompany" clearable filterable multiple placeholder="请选择生产方公司" @change="companyChange" value-key='id' style="width:510px">
  62. <!-- @change="companyChange(0)" -->
  63. <el-option v-for="item in company" :key="item.id" :label="item.companyName" :value="item">
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. </el-col>
  68. <el-col :span="24">
  69. <el-form-item label="项目经理" prop="managerId">
  70. <el-select v-model="addForm.managerId" clearable filterable placeholder="请选择项目经理" value-key='id' style="width:510px">
  71. <el-option v-for="item in charger" :key="item.id" :label="item.username" :value="item">
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. </el-col>
  76. <!-- <el-col :span="24">
  77. <el-form-item label="本方参与人">
  78. <el-select v-model="addForm.userA" clearable filterable multiple placeholder="请选择本方参与人" style="width:510px">
  79. <el-option v-for="item in userA" :key="item.id" :label="item.username" :value="item.id">
  80. </el-option>
  81. </el-select>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="24">
  85. <el-form-item label="生产方参与人">
  86. <el-select v-model="addForm.userB" clearable filterable multiple placeholder="请选择生产方参与人" style="width:510px">
  87. <el-option v-for="item in userB" :key="item.id" :label="item.username" :value="item.id">
  88. </el-option>
  89. </el-select>
  90. </el-form-item>
  91. </el-col> -->
  92. </el-form>
  93. <div slot="footer" class="dialog-footer">
  94. <el-button @click.native="addFormVisible = false">取消</el-button>
  95. <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
  96. </div>
  97. </el-dialog>
  98. </section>
  99. </template>
  100. <script>
  101. import util from '../../common/js/util'
  102. export default {
  103. data() {
  104. return {
  105. filters: {
  106. keyName: ''
  107. },
  108. user: JSON.parse(sessionStorage.getItem('user')),
  109. company:[],
  110. charger: [],
  111. // userA: [],
  112. // userB: [],
  113. list: [],
  114. total: 0,
  115. page: 1,
  116. size: 20,
  117. listLoading: false,
  118. tableHeight: 0,
  119. formRules: {
  120. projectName: [
  121. { required: true, message: '请输入项目名称', trigger: 'blur' }
  122. ],
  123. customerCompany: [
  124. { required: true, message: '请选择客户公司', trigger: 'blur' }
  125. ],
  126. managerId: [
  127. { required: true, message: '请选择项目经理', trigger: ['blur','change'] }
  128. ]
  129. },
  130. addFormVisible: false,//新增界面是否显示
  131. addLoading: false,
  132. //新增界面数据
  133. addForm: {
  134. projectName: '',
  135. customerCompany: [],
  136. managerId: '',
  137. // userA: [],
  138. // userB: []
  139. }
  140. }
  141. },
  142. methods: {
  143. // 获取基础数据
  144. getMsg(){
  145. this.http.post(this.port.project.getUserById, {
  146. companyIds: this.user.companyId
  147. } , res => {
  148. if (res.code == "ok") {
  149. this.charger = res.data;
  150. } else {
  151. this.$message({
  152. message: res.msg,
  153. type: 'error'
  154. });
  155. }
  156. }, error => {
  157. this.$message({
  158. message: error,
  159. type: 'error'
  160. });
  161. })
  162. this.http.post(this.port.base.companys, {
  163. parentId: this.user.parentId,
  164. id: this.user.id
  165. }, res => {
  166. if (res.code == "ok") {
  167. var list = res.data , array = [];
  168. for(var i in list){
  169. if(list[i].id != this.user.companyId){
  170. array.push(list[i])
  171. }
  172. }
  173. this.company = array;
  174. } else {
  175. this.$message({
  176. message: res.msg,
  177. type: 'error'
  178. });
  179. }
  180. }, error => {
  181. this.$message({
  182. message: error,
  183. type: 'error'
  184. });
  185. })
  186. },
  187. //分页
  188. handleCurrentChange(val) {
  189. this.page = val;
  190. this.getProject();
  191. },
  192. handleSizeChange(val) {
  193. this.size = val;
  194. this.getProject();
  195. },
  196. //获取项目列表
  197. getProject() {
  198. this.listLoading = true;
  199. this.http.post(this.port.project.projectList, {
  200. keyName: this.filters.keyName,
  201. currentPage: this.page,
  202. pageSize: this.size,
  203. }, res => {
  204. this.listLoading = false;
  205. if (res.code == "ok") {
  206. this.list = res.data.list;
  207. this.total = res.data.total;
  208. } else {
  209. this.$message({
  210. message: res.msg,
  211. type: 'error'
  212. });
  213. }
  214. }, error => {
  215. this.listLoading = false;
  216. this.$message({
  217. message: error,
  218. type: 'error'
  219. });
  220. })
  221. },
  222. //详情
  223. toDetail(id) {
  224. this.$router.push("/project/" + id);
  225. },
  226. //选择公司切换人员
  227. companyChange() {
  228. var param = {} ,
  229. str = this.user.companyId;
  230. for(var i in this.addForm.customerCompany){
  231. str += "," + this.addForm.customerCompany[i].id;
  232. }
  233. param.companyIds = str;
  234. this.http.post(this.port.project.getUserById, param , res => {
  235. if (res.code == "ok") {
  236. this.charger = res.data;
  237. } else {
  238. this.$message({
  239. message: res.msg,
  240. type: 'error'
  241. });
  242. }
  243. }, error => {
  244. this.$message({
  245. message: error,
  246. type: 'error'
  247. });
  248. })
  249. },
  250. //显示新增界面
  251. handleAdd() {
  252. this.addFormVisible = true;
  253. this.addForm = {
  254. projectName: '',
  255. customerCompany: '',
  256. managerId: '',
  257. // userA: [],
  258. // userB: []
  259. };
  260. },
  261. //新增
  262. addSubmit() {
  263. this.$refs.addForm.validate((valid) => {
  264. if (valid) {
  265. // console.log(this.addForm)
  266. // var userIds = "";
  267. // if(this.addForm.userA.length != 0){
  268. // for(var i in this.addForm.userA){
  269. // userIds += this.addForm.userA[i] + ","
  270. // }
  271. // }
  272. // if(this.addForm.userB.length != 0){
  273. // for(var i in this.addForm.userB){
  274. // userIds += this.addForm.userB[i] + ","
  275. // }
  276. // }
  277. // userIds = userIds.substring(0,userIds.length-1)
  278. var cId = "",
  279. cName = "";
  280. for(var i in this.addForm.customerCompany){
  281. console.log(this.addForm.customerCompany[i])
  282. cId += this.addForm.customerCompany[i].id + ",";
  283. cName += this.addForm.customerCompany[i].companyName + ",";
  284. }
  285. cId = cId.substring(0,cId.length-1);
  286. cName = cName.substring(0,cName.length-1);
  287. this.addLoading = true;
  288. this.http.post(this.port.project.addProject, {
  289. projectName: this.addForm.projectName,
  290. customerCompanyIds: cId,
  291. customerCompanyNames: cName,
  292. managerName: this.addForm.managerId.username,
  293. managerId: this.addForm.managerId.id,
  294. // userIds: userIds,
  295. flag: 0
  296. } , res => {
  297. this.addLoading = false;
  298. this.addFormVisible = false;
  299. if (res.code == "ok") {
  300. this.$message({
  301. message: '创建成功',
  302. type: 'success'
  303. });
  304. this.getProject();
  305. } else {
  306. this.$message({
  307. message: res.msg,
  308. type: 'error'
  309. });
  310. }
  311. }, error => {
  312. this.addLoading = false;
  313. this.addFormVisible = false;
  314. this.$message({
  315. message: error,
  316. type: 'error'
  317. });
  318. })
  319. }
  320. });
  321. },
  322. //删除
  323. // handleDel: function (index, row) {
  324. // this.$confirm('确认删除该记录吗?', '提示', {
  325. // type: 'warning'
  326. // }).then(() => {
  327. // this.listLoading = true;
  328. // let para = { id: row.id };
  329. // removeUser(para).then((res) => {
  330. // this.listLoading = false;
  331. // this.$message({
  332. // message: '删除成功',
  333. // type: 'success'
  334. // });
  335. // this.getProject();
  336. // });
  337. // }).catch(() => {
  338. // });
  339. // }
  340. },
  341. created() {
  342. let height = window.innerHeight;
  343. this.tableHeight = height - 210;
  344. },
  345. mounted() {
  346. this.getMsg();
  347. this.getProject();
  348. }
  349. }
  350. </script>
  351. <style scoped>
  352. </style>