list.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item label="任务列表">
  7. </el-form-item>
  8. <el-form-item >
  9. <div>
  10. <el-input style="float:left;" v-model="keyword" class="input-with-select" placeholder="请输入项目名称关键字" clearable="true">
  11. <el-select v-model="searchField" style="width:120px;" slot="prepend" placeholder="请选择">
  12. <el-option label="项目名称" value=1 ></el-option>
  13. <el-option label="项目编码" value=2></el-option>
  14. </el-select>
  15. <el-button slot="append" @click="searchList" icon="el-icon-search"></el-button>
  16. </el-input>
  17. </div>
  18. </el-form-item>
  19. <el-form-item style="float:right;">
  20. <el-link type="primary" :underline="false" @click="handleAdd(-1,null)">新增项目</el-link>
  21. </el-form-item>
  22. </el-form>
  23. </el-col>
  24. <!--列表-->
  25. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  26. <el-table-column type="index" width="60">
  27. <template slot-scope="scope" >
  28. {{scope.$index+1+(page-1)*size}}
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="projectCode" label="项目编码" sortable width="150"></el-table-column>
  32. <el-table-column prop="projectName" label="项目名称" sortable></el-table-column>
  33. <el-table-column prop="inchargerName" label="负责人" sortable width="150">
  34. <template slot-scope="scope">
  35. <el-link type="primary" @click="showUser(scope.row.inchargerId)">{{scope.row.inchargerName}}</el-link>
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="participator" label="参与者" sortable>
  39. <template slot-scope="scope">
  40. <v-for v-for="par in scope.row.participator" :key="par.id" >
  41. <el-link style="margin-right:10px;" type="primary" @click="showUser(par.id)">{{par.name}}</el-link>
  42. </v-for>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="操作" width="290">
  46. <template slot-scope="scope">
  47. <el-button v-if="user.role>0" size="small" type="primary" @click="subProject(scope.row)">子项目</el-button>
  48. <el-button size="small" type="primary" @click="handleAdd(scope.$index, scope.row)">编辑</el-button>
  49. <el-button v-if="user.role>0" size="small" type="danger" @click="deletePro(scope.$index, scope.row)">删除</el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <!--工具条-->
  54. <el-col :span="24" class="toolbar">
  55. <el-pagination
  56. @size-change="handleSizeChange"
  57. @current-change="handleCurrentChange"
  58. :page-sizes="[20 , 50 , 80 , 100]"
  59. :page-size="20"
  60. layout="total, sizes, prev, pager, next"
  61. :total="total"
  62. style="float:right;"
  63. ></el-pagination>
  64. </el-col>
  65. <!--新增界面-->
  66. <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
  67. <el-form ref="form1" :model="addForm" :rules="rules" label-width="100px">
  68. <el-form-item label="项目编号" >
  69. <el-input v-model="addForm.code" :disabled="user.role==0" placeholder="请输入项目编号" clearable></el-input>
  70. </el-form-item>
  71. <el-form-item label="项目名称" prop="name">
  72. <el-input v-model="addForm.name" :disabled="user.role==0" placeholder="请输入项目名称" clearable></el-input>
  73. </el-form-item>
  74. <el-form-item label="全部参与者">
  75. <el-select v-model="addForm.userId" multiple filterable placeholder="请选择参与者" style="width:100%;" @change="changeParticipator">
  76. <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item label="主要负责人" >
  80. <el-select v-model="addForm.inchargerId" :disabled="addForm.userId.length==0 || user.role==0" filterable placeholder="请选择负责人" style="width:100%;" @change="changeIncharger">
  81. <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id"></el-option>
  82. </el-select>
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer" class="dialog-footer">
  86. <el-button @click.native="addFormVisible = false">取消</el-button>
  87. <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
  88. </div>
  89. </el-dialog>
  90. <!--用户详细信息弹出框-->
  91. <el-dialog title="查看详情" v-if="userDetailVisible" :visible.sync="userDetailVisible" :close-on-click-modal="false" customClass="customWidth" width="400px">
  92. <div class="line"><span>姓名</span><span>{{userDetail.name}}</span></div>
  93. <div class="line"><span>手机号码</span><span>{{userDetail.phone}}</span></div>
  94. <div class="line"><span>部门</span><span>{{userDetail.departmentName}}</span></div>
  95. <div class="line"><span>成本</span><span>{{userDetail.cost}}元/小时</span></div>
  96. <div slot="footer" class="dialog-footer">
  97. <el-button type="primary" @click="userDetailVisible = false" >确定</el-button>
  98. </div>
  99. </el-dialog>
  100. <!-- 子项目列表 -->
  101. <el-dialog title="子项目列表" show-header="false" v-if="subProjectVisible" :visible.sync="subProjectVisible" :close-on-click-modal="false" customClass="customWidth" width="500px">
  102. <el-table :data="subProjectList" highlight-current-row height="400" style="width: 100%;">
  103. <el-table-column type="index" width="60" label="序号">
  104. <template slot-scope="scope" >
  105. {{scope.$index+1+(page-1)*size}}
  106. </template>
  107. </el-table-column>
  108. <el-table-column prop="name" label="名称" ></el-table-column>
  109. <el-table-column label="操作" width="150">
  110. <template slot-scope="scope" >
  111. <el-button size="small" type="primary" @click="addNewSubProject(scope.row)">编辑</el-button>
  112. <el-button size="small" type="danger" @click="deleteSubPro(scope.row)">删除</el-button>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <div slot="footer" class="dialog-footer">
  117. <el-button type="primary" @click="subProjectVisible = false" >关闭</el-button>
  118. <el-button type="primary" @click="addNewSubProject()" >新增子项目</el-button>
  119. </div>
  120. </el-dialog>
  121. <!-- 新增子项目弹出框 -->
  122. <el-dialog title="新增/修改子项目" v-if="addSubProject" :visible.sync="addSubProject" :close-on-click-modal="false" customClass="customWidth" width="500px">
  123. <el-form ref="form2" :model="addForm" :rules="rules" label-width="100px">
  124. <el-form-item label="项目名称" prop="name">
  125. <el-input v-model="addForm.name" placeholder="请输入项目名称" clearable></el-input>
  126. </el-form-item>
  127. </el-form>
  128. <div slot="footer" class="dialog-footer">
  129. <el-button @click.native="addSubProject = false">取消</el-button>
  130. <el-button type="primary" @click="submitInsertSubProject" :loading="addLoading">提交</el-button>
  131. </div>
  132. </el-dialog>
  133. </section>
  134. </template>
  135. <style scoped>
  136. .input-with-select .el-input-group__prepend {
  137. background-color: #fff;
  138. }
  139. .line {
  140. padding:10px;
  141. }
  142. .line span{
  143. font-size:18px;
  144. }
  145. .line span:nth-child(even){
  146. float:right;
  147. }
  148. </style>
  149. <script>
  150. import util from "../../common/js/util";
  151. export default {
  152. data() {
  153. return {
  154. searchField:null,
  155. keyword:null,
  156. user: JSON.parse(sessionStorage.getItem("user")),
  157. userDetailVisible: false,
  158. userDetail:{},
  159. date: new Date(),
  160. users: [],
  161. participator:[],
  162. tableHeight: 0,
  163. listLoading: false,
  164. total: 0,
  165. page: 1,
  166. size: 20,
  167. list: [],
  168. subProjectVisible: false,
  169. subProjectList: [],//子项目列表
  170. currentProject:{},
  171. addSubProject: false,
  172. addFormVisible: false,
  173. addLoading: false,
  174. title: "",
  175. addForm: {
  176. name: '',
  177. userId: [],
  178. },
  179. rules: {
  180. name: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
  181. }
  182. };
  183. },
  184. methods: {
  185. deleteSubPro(subProject) {
  186. this.$confirm("确定要删除子项目" + subProject.name + "吗?","删除子项目", {
  187. confirmButtonText: "确定",
  188. cancelButtonText: "取消",
  189. type: "warning"
  190. })
  191. .then(() => {
  192. this.listLoading = true;
  193. this.http.post('/sub-project/deleteProject',{
  194. id: subProject.id
  195. },
  196. res => {
  197. this.listLoading = false;
  198. if (res.code == "ok") {
  199. this.$message({
  200. message: "删除成功",
  201. type: "success"
  202. });
  203. this.subProject(this.currentProject);
  204. } else {
  205. this.$message({
  206. message: res.msg,
  207. type: "error"
  208. });
  209. }
  210. },
  211. error => {
  212. this.listLoading = false;
  213. this.$message({
  214. message: error,
  215. type: "error"
  216. });
  217. }
  218. );
  219. })
  220. .catch(() => {});
  221. },
  222. searchList() {
  223. this.page = 1;
  224. this.getList();
  225. },
  226. addNewSubProject(subProject) {
  227. if (subProject == null) {
  228. this.addForm = {projectId: this.currentProject.id}
  229. } else {
  230. this.addForm = subProject;
  231. }
  232. this.addSubProject = true;
  233. },
  234. //显示子项目
  235. subProject(item) {
  236. this.subProjectVisible = true;
  237. this.currentProject = item;
  238. this.http.post('/sub-project/list', {
  239. projectId: item.id
  240. },
  241. res => {
  242. if (res.code == "ok") {
  243. this.subProjectList = res.data;
  244. } else {
  245. this.$message({
  246. message: res.msg,
  247. type: "error"
  248. });
  249. }
  250. },
  251. error => {
  252. this.$message({
  253. message: error,
  254. type: "error"
  255. });
  256. });
  257. },
  258. //显示用户详情
  259. showUser(userId) {
  260. this.userDetailVisible = true;
  261. this.http.post(this.port.manage.userDetail, {
  262. userId: userId
  263. },
  264. res => {
  265. if (res.code == "ok") {
  266. this.userDetail = res.data;
  267. } else {
  268. this.$message({
  269. message: res.msg,
  270. type: "error"
  271. });
  272. }
  273. },
  274. error => {
  275. this.$message({
  276. message: error,
  277. type: "error"
  278. });
  279. });
  280. },
  281. //选择参与人
  282. changeParticipator() {
  283. //检查是否在参与人中,如果没有需要加入到参与人中
  284. console.log(this.addForm.userId);
  285. var find = false;
  286. this.participator = [];
  287. this.addForm.userId.forEach(u=>{
  288. var findUser = this.users.filter(au=>au.id == u)[0];
  289. this.participator.push(findUser);
  290. })
  291. },
  292. getUsers() {
  293. this.http.post(this.port.manage.list, {
  294. departmentId: -1,
  295. pageIndex: 1,
  296. pageSize: 99999
  297. },
  298. res => {
  299. if (res.code == "ok") {
  300. this.users = res.data.records;
  301. } else {
  302. this.$message({
  303. message: res.msg,
  304. type: "error"
  305. });
  306. }
  307. },
  308. error => {
  309. this.$message({
  310. message: error,
  311. type: "error"
  312. });
  313. });
  314. },
  315. //分页
  316. handleCurrentChange(val) {
  317. this.page = val;
  318. this.getList();
  319. },
  320. handleSizeChange(val) {
  321. this.size = val;
  322. this.getList();
  323. },
  324. //获取项目列表
  325. getList() {
  326. this.listLoading = true;
  327. this.http.post(this.port.project.listPage, {
  328. pageIndex: this.page,
  329. pageSize: this.size,
  330. keyword:this.keyword,
  331. searchField: this.searchField,
  332. },
  333. res => {
  334. this.listLoading = false;
  335. if (res.code == "ok") {
  336. var list = res.data.records;
  337. for(var i in list) {
  338. var participator = list[i].participator , str = "";
  339. for(var j in participator) {
  340. if(j == participator.length-1) {
  341. str += participator[j].name
  342. } else {
  343. str += participator[j].name + ','
  344. }
  345. }
  346. list[i].userNames = str;
  347. }
  348. this.list = list;
  349. this.total = res.data.total;
  350. } else {
  351. this.$message({
  352. message: res.msg,
  353. type: "error"
  354. });
  355. }
  356. },
  357. error => {
  358. this.listLoading = false;
  359. this.$message({
  360. message: error,
  361. type: "error"
  362. });
  363. });
  364. },
  365. //显示新增界面
  366. handleAdd(i, item) {
  367. if(i == -1) {
  368. this.title = "新增项目";
  369. this.addForm = {
  370. name: '',
  371. userId: [],
  372. code:'',
  373. inchargerId:null,
  374. }
  375. } else {
  376. this.title = "修改项目";
  377. var list = item.participator , arr = [];
  378. for(var j in list) {
  379. arr.push(list[j].id)
  380. }
  381. this.addForm = {
  382. id: item.id,
  383. name: item.projectName,
  384. userId: arr,
  385. code:item.projectCode,
  386. inchargerId: item.inchargerId
  387. }
  388. this.changeParticipator();
  389. }
  390. this.addFormVisible = true;
  391. },
  392. //提交子项目创建修改请求
  393. submitInsertSubProject () {
  394. this.$refs.form2.validate(valid => {
  395. if (valid) {
  396. this.http.post('/sub-project/saveOrUpdate',this.addForm,
  397. res => {
  398. if (res.code == "ok") {
  399. this.$message({
  400. message: "操作成功",
  401. type: "success"
  402. });
  403. this.subProject(this.currentProject);
  404. this.addSubProject = false;
  405. } else {
  406. this.$message({
  407. message: res.msg,
  408. type: "error"
  409. });
  410. }
  411. },
  412. error => {
  413. this.listLoading = false;
  414. this.$message({
  415. message: error,
  416. type: "error"
  417. });
  418. }
  419. );
  420. }
  421. });
  422. },
  423. submitInsert() {
  424. this.$refs.form1.validate(valid => {
  425. if (valid) {
  426. this.addLoading = true;
  427. let formData = new FormData();
  428. formData.append("name", this.addForm.name);
  429. if(this.addForm.id != null) {
  430. formData.append("id", this.addForm.id);
  431. }
  432. if(this.addForm.userId.length != 0) {
  433. for(var j in this.addForm.userId) {
  434. formData.append("userId", this.addForm.userId[j]);
  435. }
  436. }
  437. if(this.addForm.inchargerId != null) {
  438. formData.append("inchargerId", this.addForm.inchargerId);
  439. }
  440. if(this.addForm.code != null) {
  441. formData.append("code", this.addForm.code);
  442. }
  443. this.http.uploadFile(this.port.project.add,formData,
  444. res => {
  445. this.addLoading = false;
  446. if (res.code == "ok") {
  447. this.$message({
  448. message: this.addForm.id!=null?'修改':'创建'+"成功",
  449. type: "success"
  450. });
  451. this.addFormVisible = false;
  452. this.getList();
  453. } else {
  454. this.$message({
  455. message: res.msg,
  456. type: "error"
  457. });
  458. }
  459. },
  460. error => {
  461. this.addLoading = false;
  462. this.$message({
  463. message: error,
  464. type: "error"
  465. });
  466. });
  467. }
  468. });
  469. },
  470. // 删除
  471. deletePro(i, item) {
  472. this.$confirm("确定要项目" + item.projectName + "吗?","删除项目", {
  473. confirmButtonText: "确定",
  474. cancelButtonText: "取消",
  475. type: "warning"
  476. })
  477. .then(() => {
  478. this.listLoading = true;
  479. this.http.post(this.port.project.delete,{
  480. id: item.id
  481. },
  482. res => {
  483. this.listLoading = false;
  484. if (res.code == "ok") {
  485. this.$message({
  486. message: "删除成功",
  487. type: "success"
  488. });
  489. this.getList();
  490. } else {
  491. this.$message({
  492. message: res.msg,
  493. type: "error"
  494. });
  495. }
  496. },
  497. error => {
  498. this.listLoading = false;
  499. this.$message({
  500. message: error,
  501. type: "error"
  502. });
  503. }
  504. );
  505. })
  506. .catch(() => {});
  507. },
  508. detail(i) {
  509. this.$router.push("/list/" + this.list[i].id + "/" + this.list[i].projectName);
  510. }
  511. },
  512. created() {
  513. let height = window.innerHeight;
  514. this.tableHeight = height - 195;
  515. const that = this;
  516. window.onresize = function temp() {
  517. that.tableHeight = window.innerHeight - 195;
  518. };
  519. },
  520. mounted() {
  521. this.getList();
  522. this.getUsers();
  523. }
  524. };
  525. </script>
  526. <style lang="scss" scoped>
  527. </style>