index.vue 24 KB

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