index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div>
  3. <van-nav-bar title="项目管理" left-text="返回" @click-left="back" :right-text="canEdit?'新增项目':''" @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="canEdit">
  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-dialog v-model="show" :title="title" show-cancel-button :beforeClose="chargeBtn">
  17. <van-form style="margin: 0.4rem 0;">
  18. <van-field v-model="form.projectCode" name="项目编号" label="项目编号" placeholder="请填写项目编号" />
  19. <van-field v-model="form.projectName" name="项目名称" label="项目名称" placeholder="请填写项目名称" :rules="[{ required: true, message: '请填写项目名称' }]"/>
  20. <van-field readonly clickable name="userNames" v-model="form.userNames" label="参与人"
  21. placeholder="请选择参与人" @click="clickPicker()" />
  22. <van-field readonly clickable v-model="form.inchargerName" label="负责人"
  23. placeholder="请选择负责人" @click="showPickerIncharger = true" />
  24. <!-- 研究中心 -->
  25. <van-field v-if="user.timeType.customDegreeActive == 1" readonly clickable name="userNames" v-model="form.associateDegreeNames" label="研究中心"
  26. placeholder="请选择" @click="clikls()"/>
  27. </van-form>
  28. </van-dialog>
  29. <van-popup v-model="showPickerUser" position="bottom">
  30. <van-search v-model="userName" placeholder="输入员工姓名搜索" @search="onSearch"></van-search>
  31. <div style="minHeight:300px;">
  32. <van-checkbox class="userCheckbox" v-for="(item) in userList" :key="item.id" v-model="item.isChecked" >{{item.name}}</van-checkbox>
  33. <van-button style="width:100%;" @click="refreshParticipate();showPickerUser=false">确定</van-button>
  34. </div>
  35. </van-popup>
  36. <van-popup v-model="showPickerIncharger" position="bottom">
  37. <van-picker show-toolbar :columns="inchargerUserList" value-key="name" @confirm="choseIncharger" @cancel="showPickerIncharger = false" />
  38. </van-popup>
  39. <!-- 研究中心 -->
  40. <van-popup v-model="cliklss" position="bottom">
  41. <div style="minHeight:300px;">
  42. <van-checkbox class="userCheckbox" v-for="(item) in ause" :key="item.id" v-model="item.isChecked" @change="fuxuan()" @click="ddd()">{{item.name}}</van-checkbox>
  43. <van-button style="width:100%;" @click="refreshParticipatess();cliklss=false">确定</van-button>
  44. </div>
  45. </van-popup>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. canEdit:false,
  54. user: JSON.parse(localStorage.userInfo),
  55. showPickerUser: false,
  56. showPickerIncharger: false,
  57. userName:null,
  58. total: 0,
  59. page: 1,
  60. size: 1000,
  61. list: [],
  62. loading: false,
  63. finished: false,
  64. error: false,
  65. refreshing: false,
  66. allUserList:[],
  67. userList:[],
  68. inchargerUserList:[],
  69. show: false,
  70. title: "修改项目",
  71. form: {
  72. id: null,
  73. projectName: "",
  74. },
  75. cliklss: false,
  76. ause: []
  77. };
  78. },
  79. created() {
  80. },
  81. methods: {
  82. fuxuan() {
  83. console.log(this.ause)
  84. },
  85. ddd() {
  86. let aes = this.ause
  87. this.ause = aes
  88. console.log(this.ause, '12345')
  89. },
  90. yanjiuzx() {
  91. this.$axios.post("/report-extra-degree/getAll", {})
  92. .then(res => {
  93. if(res.code == "ok") {
  94. for(var i in res.data) {
  95. res.data[i].isChecked = false
  96. }
  97. this.ause = res.data
  98. } else {
  99. this.$toast.fail('获取失败');
  100. }
  101. }).catch(err=> {toast.clear();});
  102. },
  103. choseIncharger(value, index) {
  104. this.showPickerIncharger = false;
  105. this.form.inchargerName = value.name;
  106. this.form.inchargerId = value.id;
  107. },
  108. onSearch(val) {
  109. console.log(val);
  110. this.userList = [];
  111. this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
  112. this.userList.push(u);
  113. }})
  114. },
  115. //刷新参与人
  116. refreshParticipate() {
  117. this.form.userNames = '';
  118. var that = this;
  119. that.inchargerUserList = [];
  120. that.form.userId = [];
  121. this.userList.filter(u=>u.isChecked).forEach(u=>{
  122. that.form.userNames+=(u.name+',');
  123. that.form.userId.push(u.id);
  124. that.inchargerUserList.push(u);
  125. });
  126. if (this.form.userNames.length > 0) {
  127. this.form.userNames = this.form.userNames.substring(0, this.form.userNames.length-1);
  128. }
  129. },
  130. // 刷新研究中心
  131. refreshParticipatess() {
  132. var auseNme = []
  133. var auseList = []
  134. for(var i in this.ause) {
  135. if(this.ause[i].isChecked) {
  136. if(this.ause[i].isChecked == true) {
  137. auseNme.push(this.ause[i].name)
  138. auseList.push(this.ause[i].id)
  139. }
  140. }
  141. }
  142. this.form.associateDegreeNames = auseNme.toString()
  143. this.form.associateDegrees = auseList
  144. console.log(this.form, '刷新')
  145. },
  146. onChange() {
  147. console.log('===');
  148. },
  149. choseUsers() {
  150. },
  151. clickPicker() {
  152. this.showPickerUser = true;
  153. },
  154. clikls() {
  155. this.cliklss = true
  156. for(var i in this.ause) {
  157. if(this.form.associateDegrees.length > 0) {
  158. for(var j in this.form.associateDegrees) {
  159. if(this.form.associateDegrees[j] == this.ause[i].id) {
  160. this.ause[i].isChecked = true
  161. }
  162. }
  163. }
  164. }
  165. this.ause = this.ause
  166. console.log(this.ause)
  167. },
  168. // 返回
  169. back() {
  170. history.back();
  171. },
  172. //获取用户列表
  173. getUsers() {
  174. this.$axios.post("/user/getEmployeeList", {
  175. departmentId: -1,
  176. pageIndex: 1,
  177. pageSize: 99999
  178. })
  179. .then(res => {
  180. if(res.code == "ok") {
  181. this.loading = false;
  182. var sj = res.data.records
  183. for (var i in sj) {
  184. sj[i].isChecked = false
  185. }
  186. // this.userList = res.data.records;
  187. this.userList = sj;
  188. this.allUserList = res.data.records;
  189. } else {
  190. this.$toast.fail('获取失败');
  191. }
  192. }).catch(err=> {toast.clear();});
  193. },
  194. // 获取项目
  195. getProject() {
  196. if (this.refreshing) {
  197. this.list = [];
  198. this.refreshing = false;
  199. }
  200. if(this.total == this.list.length && this.list.length != 0) {
  201. this.loading = false;
  202. this.finished = true;
  203. return false;
  204. }
  205. this.$axios.post("/project/getProjectPage", {
  206. pageIndex: this.page,
  207. pageSize: this.size,
  208. })
  209. .then(res => {
  210. if(res.code == "ok") {
  211. this.loading = false;
  212. if (this.list.length == 0) {
  213. this.finished = true;
  214. }
  215. this.list = [];
  216. for(var i in res.data.records) {
  217. this.list.push(res.data.records[i])
  218. }
  219. this.total = res.data.total;
  220. this.page++;
  221. } else {
  222. this.$toast.fail('获取失败:'+res.msg);
  223. }
  224. }).catch(err=> {toast.clear();});
  225. },
  226. onRefresh() {
  227. this.finished = false;
  228. this.loading = true;
  229. this.page = 1;
  230. this.getProject();
  231. },
  232. // 新增、编辑项目
  233. openDialog(i) {
  234. if(i == -1) {
  235. this.title = "新增项目";
  236. this.form = {
  237. id: null,
  238. projectName: "",
  239. projectCode:null,
  240. inchargerName:null,
  241. inchargerId:null,
  242. userId:null,
  243. userNames:null,
  244. associateDegreeNames: null,
  245. associateDegrees: null
  246. }
  247. // this.userList.forEach(u=>u.isChecked=false);
  248. // this.refreshParticipate();
  249. } else {
  250. this.title = "修改项目";
  251. var arrs
  252. if(this.list[i].associateDegrees) {
  253. arrs = this.list[i].associateDegrees.split(',')
  254. for(var j in arrs) {
  255. arrs[j] = +arrs[j] + 0
  256. }
  257. } else {
  258. arrs = []
  259. }
  260. var name
  261. if(this.list[i].associateDegreeNames != null && this.list[i].associateDegreeNames != 'null') {
  262. name = this.list[i].associateDegreeNames
  263. } else {
  264. name = ''
  265. }
  266. console.log(name, '看看')
  267. this.form = {
  268. id: this.list[i].id,
  269. projectName: this.list[i].projectName,
  270. projectCode: this.list[i].projectCode,
  271. inchargerId: this.list[i].inchargerId,
  272. inchargerName: this.list[i].inchargerName,
  273. associateDegreeNames: name,
  274. associateDegrees: arrs
  275. }
  276. var part = this.list[i].participator;
  277. if (part.length>0) {
  278. for (var j in part) {
  279. this.userList.filter(u=>u.id == part[j].id)[0].isChecked = true;
  280. }
  281. this.refreshParticipate();
  282. }
  283. }
  284. this.show = true;
  285. },
  286. chargeBtn(action, done) {
  287. if (action === 'confirm') {
  288. this.show = false;
  289. const toast = this.$toast.loading({
  290. forbidClick: true,
  291. duration: 0
  292. });
  293. let formData = new FormData();
  294. formData.append("name", this.form.projectName);
  295. formData.append("code", this.form.projectCode);
  296. formData.append("inchargerId", this.form.inchargerId);
  297. for (var j in this.form.userId) {
  298. formData.append("userId", this.form.userId[j]);
  299. }
  300. let form = {
  301. name: this.form.projectName,
  302. code:this.form.projectCode,
  303. inchargerId: this.form.inchargerId,
  304. userId:this.form.userId
  305. }
  306. if(this.form.id != null) {
  307. // form.id = this.form.id;
  308. formData.append("id", this.form.id);
  309. }
  310. if(this.form.associateDegreeNames != '' && this.form.associateDegreeNames != null) {
  311. formData.append("associateDegreeNames", this.form.associateDegreeNames);
  312. } else {
  313. formData.append("associateDegreeNames", null);
  314. }
  315. if(this.form.associateDegrees.length > 0) {
  316. var sss = this.form.associateDegrees.toString()
  317. formData.append("associateDegrees", sss);
  318. } else {
  319. formData.append("associateDegrees", null);
  320. }
  321. const config = {
  322. headers: {
  323. 'Content-Type': 'multipart/form-data'
  324. }
  325. }
  326. this.$axios.post("/project/editProject", formData, config)
  327. .then(res => {
  328. if(res.code == "ok") {
  329. toast.clear();
  330. this.$toast.success(this.form.id==null?'新增成功':'修改成功');
  331. this.list = [];
  332. this.page = 1;
  333. this.getProject();
  334. this.yanjiuzx()
  335. } else {
  336. toast.clear();
  337. this.$toast.fail(this.form.id==null?'新增失败':'修改失败');
  338. }
  339. }).catch(err=> {toast.clear();});
  340. } else {
  341. this.show = false;
  342. this.yanjiuzx()
  343. }
  344. done();
  345. },
  346. // 删除项目
  347. delPro(i) {
  348. this.$dialog.confirm({
  349. title: '删除项目',
  350. message: '确定要项目'+this.list[i].projectName+'吗?'
  351. }).then(() => {
  352. const toast = this.$toast.loading({
  353. forbidClick: true,
  354. duration: 0
  355. });
  356. this.$axios.post("/project/deleteProject", {id: this.list[i].id})
  357. .then(res => {
  358. if(res.code == "ok") {
  359. toast.clear();
  360. this.$toast.success('删除成功');
  361. this.list = [];
  362. this.page = 1;
  363. this.getProject();
  364. } else {
  365. toast.clear();
  366. this.$toast.fail(res.msg);
  367. }
  368. }).catch(err=> {toast.clear();});
  369. }).catch(() => {});
  370. },
  371. },
  372. mounted() {
  373. this.getUsers();
  374. this.yanjiuzx()
  375. this.canEdit = (this.user.role==1||this.user.role==2||this.user.role==5);
  376. }
  377. };
  378. </script>
  379. <style lang="less" scoped>
  380. .login_form {
  381. margin-top: 46px;
  382. }
  383. .one_report {
  384. margin-bottom: 15px;
  385. }
  386. .form_text {
  387. margin: 15px 0 30px;
  388. padding: 0 12px;
  389. }
  390. .form_btn {
  391. text-align: right;
  392. }
  393. .form_btn button {
  394. margin-left: 10px;
  395. }
  396. .one_report_data {
  397. margin-bottom: 20px;
  398. padding: 0 22px;
  399. div {
  400. line-height: 30px;
  401. }
  402. }
  403. .userCheckbox {
  404. padding: 10px;;
  405. }
  406. </style>
  407. <style lang="less">
  408. .van-nav-bar .van-icon , .van-nav-bar__text {
  409. color: #20a0ff;
  410. }
  411. </style>