index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div>
  3. <van-nav-bar title="项目管理" left-text="返回" @click-left="back" :right-text="projectAdd?'新增项目':''" @click-right="openDialog(-1)" fixed left-arrow/>
  4. <div class="login_form">
  5. <!-- <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  6. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :error.sync="error" error-text="请求失败,点击重新加载" @load="getProject">
  7. <van-swipe-cell v-for="(item,index) in list" :key="index">
  8. <van-cell :border="false" :title="item.projectName" :value="item.projectCode"/>
  9. <template slot="right" v-if="projectManagement || item.creatorId == user.id">
  10. <van-button square type="info" text="编辑" @click="openDialog(index)"/>
  11. <van-button square type="danger" text="删除" @click="delPro(index)"/>
  12. </template>
  13. </van-swipe-cell>
  14. </van-list>
  15. </van-pull-refresh> -->
  16. <van-pull-refresh v-model="isDownLoading" @refresh="onDownRefresh">
  17. <van-list v-model="isUpLoading" :finished="upFinished" :immediate-check="false" :offset="100" finished-text="没有更多了" @load="onLoadList">
  18. <van-swipe-cell v-for="(item,index) in list" :key="index">
  19. <van-cell :border="false" :title="item.projectName" :value="item.projectCode"/>
  20. <template slot="right" v-if="projectManagement || item.creatorId == user.id">
  21. <van-button square type="info" text="编辑" @click="openDialog(index)"/>
  22. <van-button square type="danger" text="删除" @click="delPro(index)"/>
  23. </template>
  24. </van-swipe-cell>
  25. </van-list>
  26. </van-pull-refresh>
  27. <van-dialog v-model="show" :title="title" show-cancel-button :beforeClose="chargeBtn">
  28. <van-form style="margin: 0.4rem 0;">
  29. <van-field v-model="form.projectCode" name="项目编号" label="项目编号" placeholder="请填写项目编号" />
  30. <van-field v-model="form.projectName" name="项目名称" label="项目名称" placeholder="请填写项目名称" :rules="[{ required: true, message: '请填写项目名称' }]"/>
  31. <van-field readonly clickable name="userNames" v-model="form.userNames" label="参与人"
  32. placeholder="请选择参与人" @click="clickPicker()" />
  33. <van-field readonly clickable v-model="form.inchargerName" label="负责人"
  34. placeholder="请选择负责人" @click="showPickerIncharger = true" />
  35. <!-- 研究中心 -->
  36. <van-field v-if="user.timeType.customDegreeActive == 1" readonly clickable name="userNames" v-model="form.associateDegreeNames" label="研究中心"
  37. placeholder="请选择" @click="clikls()"/>
  38. </van-form>
  39. </van-dialog>
  40. <van-popup v-model="showPickerUser" position="bottom">
  41. <van-search v-model="userName" placeholder="输入员工姓名搜索" @search="onSearch"></van-search>
  42. <div style="minHeight:300px;">
  43. <van-checkbox class="userCheckbox" v-for="(item) in userList" :key="item.id" v-model="item.isChecked" >{{item.name}}</van-checkbox>
  44. <van-button style="width:100%;" @click="refreshParticipate();showPickerUser=false">确定</van-button>
  45. </div>
  46. </van-popup>
  47. <van-popup v-model="showPickerIncharger" position="bottom">
  48. <van-picker show-toolbar :columns="inchargerUserList" value-key="name" @confirm="choseIncharger" @cancel="showPickerIncharger = false" />
  49. </van-popup>
  50. <!-- 研究中心 -->
  51. <van-popup v-model="cliklss" position="bottom">
  52. <div style="minHeight:300px;">
  53. <van-checkbox class="userCheckbox" v-for="(item) in ause" :key="item.id" v-model="item.isChecked" @change="fuxuan()" @click="ddd()">{{item.name}}</van-checkbox>
  54. <van-button style="width:100%;" @click="refreshParticipatess();cliklss=false">确定</van-button>
  55. </div>
  56. </van-popup>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. canEdit:false,
  65. user: JSON.parse(localStorage.userInfo),
  66. showPickerUser: false,
  67. showPickerIncharger: false,
  68. userName:null,
  69. total: 0,
  70. page: 1,
  71. size: 1000,
  72. list: [],
  73. loading: false,
  74. finished: false,
  75. error: false,
  76. refreshing: false,
  77. allUserList:[],
  78. userList:[],
  79. inchargerUserList:[],
  80. show: false,
  81. title: "修改项目",
  82. form: {
  83. id: null,
  84. projectName: "",
  85. },
  86. cliklss: false,
  87. ause: [],
  88. projectAdd: false, // 新增项目
  89. projectManagement: false, // 管理项目
  90. isDownLoading: false, // 下拉刷新
  91. isUpLoading: false, // 上拉加载
  92. upFinished: false, // 上拉加载完毕
  93. offset: 100, // 滚动条与底部距离小于 offset 时触发load事件
  94. pageSize: 25, // 每页条数
  95. pageIndex: 1, // 页码
  96. dpp: false,
  97. };
  98. },
  99. created() {
  100. },
  101. methods: {
  102. fuxuan() {
  103. console.log(this.ause)
  104. },
  105. ddd() {
  106. let aes = this.ause
  107. this.ause = aes
  108. console.log(this.ause, '12345')
  109. },
  110. yanjiuzx() {
  111. this.$axios.post("/report-extra-degree/getAll", {})
  112. .then(res => {
  113. if(res.code == "ok") {
  114. for(var i in res.data) {
  115. res.data[i].isChecked = false
  116. }
  117. this.ause = res.data
  118. } else {
  119. this.$toast.fail('获取失败');
  120. }
  121. }).catch(err=> {this.$toast.clear();});
  122. },
  123. choseIncharger(value, index) {
  124. this.showPickerIncharger = false;
  125. this.form.inchargerName = value.name;
  126. this.form.inchargerId = value.id;
  127. },
  128. onSearch(val) {
  129. console.log(val);
  130. this.userList = [];
  131. this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
  132. this.userList.push(u);
  133. }})
  134. },
  135. //刷新参与人
  136. refreshParticipate() {
  137. this.form.userNames = '';
  138. var that = this;
  139. that.inchargerUserList = [];
  140. that.form.userId = [];
  141. this.userList.filter(u=>u.isChecked).forEach(u=>{
  142. that.form.userNames+=(u.name+',');
  143. that.form.userId.push(u.id);
  144. that.inchargerUserList.push(u);
  145. });
  146. if (this.form.userNames.length > 0) {
  147. this.form.userNames = this.form.userNames.substring(0, this.form.userNames.length-1);
  148. }
  149. },
  150. // 刷新研究中心
  151. refreshParticipatess() {
  152. var auseNme = []
  153. var auseList = []
  154. for(var i in this.ause) {
  155. if(this.ause[i].isChecked) {
  156. if(this.ause[i].isChecked == true) {
  157. auseNme.push(this.ause[i].name)
  158. auseList.push(this.ause[i].id)
  159. }
  160. }
  161. }
  162. this.form.associateDegreeNames = auseNme.toString()
  163. this.form.associateDegrees = auseList
  164. console.log(this.form, '刷新')
  165. },
  166. onChange() {
  167. console.log('===');
  168. },
  169. choseUsers() {
  170. },
  171. clickPicker() {
  172. this.showPickerUser = true;
  173. },
  174. clikls() {
  175. this.cliklss = true
  176. for(var i in this.ause) {
  177. if(this.form.associateDegrees.length > 0) {
  178. for(var j in this.form.associateDegrees) {
  179. if(this.form.associateDegrees[j] == this.ause[i].id) {
  180. this.ause[i].isChecked = true
  181. }
  182. }
  183. }
  184. }
  185. this.ause = this.ause
  186. console.log(this.ause)
  187. },
  188. // 返回
  189. back() {
  190. history.back();
  191. },
  192. //获取用户列表
  193. getUsers() {
  194. this.$axios.post("/user/getEmployeeList", {
  195. departmentId: -1,
  196. pageIndex: 1,
  197. pageSize: 99999
  198. })
  199. .then(res => {
  200. if(res.code == "ok") {
  201. this.loading = false;
  202. var sj = res.data.records
  203. for (var i in sj) {
  204. sj[i].isChecked = false
  205. }
  206. // this.userList = res.data.records;
  207. this.userList = sj;
  208. this.allUserList = res.data.records;
  209. } else {
  210. this.$toast.fail('获取失败');
  211. }
  212. }).catch(err=> {this.$toast.clear();});
  213. },
  214. // 获取项目
  215. getProject() {
  216. // if (this.refreshing) {
  217. // this.list = [];
  218. // this.refreshing = false;
  219. // }
  220. // if(this.total == this.list.length && this.list.length != 0) {
  221. // this.loading = false;
  222. // this.finished = true;
  223. // return false;
  224. // }
  225. // this.$axios.post("/project/getProjectPage", {
  226. // pageIndex: this.page,
  227. // pageSize: this.size,
  228. // })
  229. // .then(res => {
  230. // if(res.code == "ok") {
  231. // this.loading = false;
  232. // if (this.list.length == 0) {
  233. // this.finished = true;
  234. // }
  235. // this.list = [];
  236. // for(var i in res.data.records) {
  237. // this.list.push(res.data.records[i])
  238. // }
  239. // this.total = res.data.total;
  240. // this.page++;
  241. // } else {
  242. // this.$toast.fail('获取失败:'+res.msg);
  243. // }
  244. // }).catch(err=> {toast.clear();});
  245. this.$axios.post("/project/getProjectPage", {
  246. pageIndex: this.pageIndex,
  247. pageSize: this.pageSize,
  248. })
  249. .then(res => {
  250. if(res.code == "ok") {
  251. this.isDownLoading = false
  252. this.isUpLoading = false
  253. this.total = res.data.total
  254. var datas = res.data.records
  255. if(res.data.records.length <= 0) {
  256. this.total = 0,
  257. this.list = []
  258. this.$toast('已全部加载完成');
  259. return
  260. } else {
  261. console.log(this.dpp)
  262. if(this.dpp) this.list = []
  263. if(this.list.length == 0) {
  264. this.list = datas
  265. } else {
  266. for(var i in datas) {
  267. this.list.push(datas[i])
  268. }
  269. }
  270. }
  271. } else {
  272. this.$toast.fail('获取失败');
  273. this.isDownLoading = false
  274. this.isUpLoading = false
  275. }
  276. }).catch(err=> {
  277. this.$toast.clear();
  278. this.isDownLoading = false
  279. this.isUpLoading = false
  280. });
  281. },
  282. onDownRefresh() {
  283. console.log(123)
  284. this.dpp = true
  285. this.pageIndex = 1
  286. this.upFinished = false // 不写这句会导致你上拉到底过后在下拉刷新将不能触发下拉加载事件
  287. this.getProject()
  288. },
  289. onLoadList() {
  290. if(this.total <= this.list.length) {
  291. this.upFinished = true
  292. this.isUpLoading = false
  293. return
  294. }
  295. this.pageIndex = +this.pageIndex + 1
  296. this.dpp = false
  297. this.getProject()
  298. },
  299. onRefresh() {
  300. this.finished = false;
  301. this.loading = true;
  302. this.page = 1;
  303. this.getProject();
  304. },
  305. // 新增、编辑项目
  306. openDialog(i) {
  307. if(i == -1) {
  308. this.title = "新增项目";
  309. this.form = {
  310. id: null,
  311. projectName: "",
  312. projectCode:null,
  313. inchargerName:null,
  314. inchargerId:null,
  315. userId:null,
  316. userNames:null,
  317. associateDegreeNames: null,
  318. associateDegrees: null
  319. }
  320. // this.userList.forEach(u=>u.isChecked=false);
  321. // this.refreshParticipate();
  322. } else {
  323. this.title = "修改项目";
  324. var arrs
  325. if(this.list[i].associateDegrees) {
  326. arrs = this.list[i].associateDegrees.split(',')
  327. for(var j in arrs) {
  328. arrs[j] = +arrs[j] + 0
  329. }
  330. } else {
  331. arrs = []
  332. }
  333. var name
  334. if(this.list[i].associateDegreeNames != null && this.list[i].associateDegreeNames != 'null') {
  335. name = this.list[i].associateDegreeNames
  336. } else {
  337. name = ''
  338. }
  339. console.log(name, '看看')
  340. this.form = {
  341. id: this.list[i].id,
  342. projectName: this.list[i].projectName,
  343. projectCode: this.list[i].projectCode,
  344. inchargerId: this.list[i].inchargerId,
  345. inchargerName: this.list[i].inchargerName,
  346. associateDegreeNames: name,
  347. associateDegrees: arrs
  348. }
  349. var part = this.list[i].participator;
  350. if (part.length>0) {
  351. for (var j in part) {
  352. this.userList.filter(u=>u.id == part[j].id)[0].isChecked = true;
  353. }
  354. this.refreshParticipate();
  355. }
  356. }
  357. this.show = true;
  358. },
  359. chargeBtn(action, done) {
  360. if (action === 'confirm') {
  361. this.show = false;
  362. const toast = this.$toast.loading({
  363. forbidClick: true,
  364. duration: 0
  365. });
  366. let formData = new FormData();
  367. formData.append("name", this.form.projectName);
  368. formData.append("code", this.form.projectCode);
  369. formData.append("inchargerId", this.form.inchargerId);
  370. for (var j in this.form.userId) {
  371. formData.append("userId", this.form.userId[j]);
  372. }
  373. let form = {
  374. name: this.form.projectName,
  375. code:this.form.projectCode,
  376. inchargerId: this.form.inchargerId,
  377. userId:this.form.userId
  378. }
  379. if(this.form.id != null) {
  380. // form.id = this.form.id;
  381. formData.append("id", this.form.id);
  382. }
  383. if(this.form.associateDegreeNames != '' && this.form.associateDegreeNames != null) {
  384. formData.append("associateDegreeNames", this.form.associateDegreeNames);
  385. } else {
  386. formData.append("associateDegreeNames", null);
  387. }
  388. if(this.form.associateDegrees.length > 0) {
  389. var sss = this.form.associateDegrees.toString()
  390. formData.append("associateDegrees", sss);
  391. } else {
  392. formData.append("associateDegrees", null);
  393. }
  394. const config = {
  395. headers: {
  396. 'Content-Type': 'multipart/form-data'
  397. }
  398. }
  399. this.$axios.post("/project/editProject", formData, config)
  400. .then(res => {
  401. if(res.code == "ok") {
  402. this.$toast.clear();
  403. this.$toast.success(this.form.id==null?'新增成功':'修改成功');
  404. this.list = [];
  405. this.page = 1;
  406. this.getProject();
  407. this.yanjiuzx()
  408. } else {
  409. this.$toast.clear();
  410. this.$toast.fail(this.form.id==null?'新增失败':'修改失败');
  411. }
  412. }).catch(err=> {this.$toast.clear();});
  413. } else {
  414. this.show = false;
  415. this.yanjiuzx()
  416. }
  417. done();
  418. },
  419. // 删除项目
  420. delPro(i) {
  421. this.$dialog.confirm({
  422. title: '删除项目',
  423. message: '确定要项目'+this.list[i].projectName+'吗?'
  424. }).then(() => {
  425. const toast = this.$toast.loading({
  426. forbidClick: true,
  427. duration: 0
  428. });
  429. this.$axios.post("/project/deleteProject", {id: this.list[i].id})
  430. .then(res => {
  431. if(res.code == "ok") {
  432. this.$toast.clear();
  433. this.$toast.success('删除成功');
  434. this.list = [];
  435. this.page = 1;
  436. this.getProject();
  437. } else {
  438. this.$toast.clear();
  439. this.$toast.fail(res.msg);
  440. }
  441. }).catch(err=> {this.$toast.clear();});
  442. }).catch(() => {});
  443. },
  444. },
  445. mounted() {
  446. this.getUsers();
  447. this.yanjiuzx()
  448. this.getProject()
  449. // this.canEdit = (this.user.role==1||this.user.role==2||this.user.role==5);
  450. var list = this.user.functionList
  451. for(var i in list) {
  452. if(list[i].name == '新增项目') {
  453. this.projectAdd = true
  454. }
  455. if(list[i].name == '管理全部项目') {
  456. this.projectManagement = true
  457. }
  458. }
  459. }
  460. };
  461. </script>
  462. <style lang="less" scoped>
  463. .login_form {
  464. margin-top: 46px;
  465. }
  466. .one_report {
  467. margin-bottom: 15px;
  468. }
  469. .form_text {
  470. margin: 15px 0 30px;
  471. padding: 0 12px;
  472. }
  473. .form_btn {
  474. text-align: right;
  475. }
  476. .form_btn button {
  477. margin-left: 10px;
  478. }
  479. .one_report_data {
  480. margin-bottom: 20px;
  481. padding: 0 22px;
  482. div {
  483. line-height: 30px;
  484. }
  485. }
  486. .userCheckbox {
  487. padding: 10px;;
  488. }
  489. </style>
  490. <style lang="less">
  491. .van-nav-bar .van-icon , .van-nav-bar__text {
  492. color: #20a0ff;
  493. }
  494. </style>