index.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. if(this.user.company.packageProject == 1){
  163. sessionStorage.setItem('projectId',JSON.stringify(item.id))
  164. this.$router.push("/projectInside");
  165. }
  166. },
  167. popoverSelect(action){
  168. if(this.popoverType == action.type){
  169. return
  170. }else{
  171. this.popoverType = action.type
  172. this.popoverValue = ''
  173. // this.isDownLoading = true
  174. this.list = []
  175. this.isUpLoading = true
  176. this.onDownRefresh()
  177. }
  178. },
  179. popoverSearch(){
  180. // this.isDownLoading = true
  181. this.list = []
  182. this.isUpLoading = true
  183. this.onDownRefresh()
  184. },
  185. fuxuan() {
  186. console.log(this.ause)
  187. },
  188. ddd() {
  189. let aes = this.ause
  190. this.ause = aes
  191. console.log(this.ause, '12345')
  192. },
  193. yanjiuzx() {
  194. this.$axios.post("/report-extra-degree/getAll", {})
  195. .then(res => {
  196. if(res.code == "ok") {
  197. for(var i in res.data) {
  198. res.data[i].isChecked = false
  199. }
  200. this.ause = res.data
  201. } else {
  202. this.$toast.fail('获取失败');
  203. }
  204. }).catch(err=> {this.$toast.clear();});
  205. },
  206. choseIncharger(value, index) {
  207. this.showPickerIncharger = false;
  208. this.form.inchargerName = value.name;
  209. this.form.inchargerId = value.id;
  210. },
  211. onSearch(val) {
  212. console.log(val);
  213. this.userList = [];
  214. this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
  215. this.userList.push(u);
  216. }})
  217. },
  218. //刷新参与人
  219. refreshParticipate() {
  220. var that = this;
  221. that.inchargerUserList = [];
  222. that.form.userId = [];
  223. let userNames = ''
  224. this.userList.filter(u=>u.isChecked).forEach(u=>{
  225. userNames+=(u.name+',');
  226. that.form.userId.push(u.id);
  227. that.inchargerUserList.push(u);
  228. });
  229. // this.form.userNames = userNames
  230. if (userNames.length > 0) {
  231. userNames = userNames.substring(0, userNames.length-1);
  232. }
  233. this.$set(this.form,'userNames',userNames)
  234. },
  235. // 刷新研究中心
  236. refreshParticipatess() {
  237. var auseNme = []
  238. var auseList = []
  239. for(var i in this.ause) {
  240. if(this.ause[i].isChecked) {
  241. if(this.ause[i].isChecked == true) {
  242. auseNme.push(this.ause[i].name)
  243. auseList.push(this.ause[i].id)
  244. }
  245. }
  246. }
  247. this.form.associateDegreeNames = auseNme.toString()
  248. this.form.associateDegrees = auseList
  249. console.log(this.form, '刷新')
  250. },
  251. onChange() {
  252. console.log('===');
  253. },
  254. choseUsers() {
  255. },
  256. clickPicker() {
  257. this.showPickerUser = true;
  258. },
  259. clikls() {
  260. this.cliklss = true
  261. for(var i in this.ause) {
  262. if(this.form.associateDegrees.length > 0) {
  263. for(var j in this.form.associateDegrees) {
  264. if(this.form.associateDegrees[j] == this.ause[i].id) {
  265. this.ause[i].isChecked = true
  266. }
  267. }
  268. }
  269. }
  270. this.ause = this.ause
  271. console.log(this.ause)
  272. },
  273. // 返回
  274. back() {
  275. history.back();
  276. },
  277. //获取用户列表
  278. getUsers() {
  279. this.$axios.post("/user/getEmployeeList", {
  280. departmentId: -1,
  281. pageIndex: 1,
  282. // pageSize: 99999
  283. pageSize: -1
  284. })
  285. .then(res => {
  286. if(res.code == "ok") {
  287. this.loading = false;
  288. var sj = res.data.records
  289. for (var i in sj) {
  290. sj[i].isChecked = false
  291. }
  292. // this.userList = res.data.records;
  293. this.userList = sj;
  294. this.allUserList = res.data.records;
  295. } else {
  296. this.$toast.fail('获取失败');
  297. }
  298. }).catch(err=> {this.$toast.clear();});
  299. },
  300. // 获取项目
  301. getProject() {
  302. let parameter = {
  303. pageIndex: this.pageIndex,
  304. pageSize: this.pageSize,
  305. }
  306. if(this.popoverValue){
  307. parameter.keyword = this.popoverValue
  308. parameter.searchField = this.popoverType
  309. }
  310. this.$axios.post("/project/getProjectPage", parameter)
  311. .then(res => {
  312. if(res.code == "ok") {
  313. this.isDownLoading = false
  314. this.isUpLoading = false
  315. this.total = res.data.total
  316. var datas = res.data.records
  317. if(res.data.records.length <= 0) {
  318. this.total = 0,
  319. this.list = []
  320. this.$toast('已全部加载完成');
  321. return
  322. } else {
  323. // console.log(this.dpp)
  324. if(this.dpp) this.list = []
  325. if(this.list.length == 0) {
  326. this.list = datas
  327. } else {
  328. for(var i in datas) {
  329. this.list.push(datas[i])
  330. }
  331. }
  332. }
  333. } else {
  334. this.$toast.fail('获取失败');
  335. this.isDownLoading = false
  336. this.isUpLoading = false
  337. }
  338. }).catch(err=> {
  339. this.$toast.clear();
  340. this.isDownLoading = false
  341. this.isUpLoading = false
  342. });
  343. },
  344. onDownRefresh() {
  345. console.log(123)
  346. this.dpp = true
  347. this.pageIndex = 1
  348. this.upFinished = false // 不写这句会导致你上拉到底过后在下拉刷新将不能触发下拉加载事件
  349. this.getProject()
  350. },
  351. onLoadList() {
  352. if(this.total <= this.list.length) {
  353. this.upFinished = true
  354. this.isUpLoading = false
  355. return
  356. }
  357. this.pageIndex = +this.pageIndex + 1
  358. this.dpp = false
  359. this.getProject()
  360. },
  361. onRefresh() {
  362. this.finished = false;
  363. this.loading = true;
  364. this.page = 1;
  365. this.getProject();
  366. },
  367. // 新增、编辑项目
  368. openDialog(i) {
  369. if(i == -1) {
  370. this.title = "新增项目";
  371. this.form = {
  372. id: null,
  373. projectName: "",
  374. projectCode:null,
  375. inchargerName:null,
  376. inchargerId:null,
  377. userId:null,
  378. userNames:null,
  379. associateDegreeNames: null,
  380. associateDegrees: null
  381. }
  382. // this.userList.forEach(u=>u.isChecked=false);
  383. // this.refreshParticipate();
  384. } else {
  385. this.title = "修改项目";
  386. var arrs
  387. if(this.list[i].associateDegrees) {
  388. arrs = this.list[i].associateDegrees.split(',')
  389. for(var j in arrs) {
  390. arrs[j] = +arrs[j] + 0
  391. }
  392. } else {
  393. arrs = []
  394. }
  395. var name
  396. if(this.list[i].associateDegreeNames != null && this.list[i].associateDegreeNames != 'null') {
  397. name = this.list[i].associateDegreeNames
  398. } else {
  399. name = ''
  400. }
  401. console.log(name, '看看')
  402. this.form = {
  403. id: this.list[i].id,
  404. projectName: this.list[i].projectName,
  405. projectCode: this.list[i].projectCode,
  406. inchargerId: this.list[i].inchargerId,
  407. inchargerName: this.list[i].inchargerName,
  408. associateDegreeNames: name,
  409. associateDegrees: arrs
  410. }
  411. var part = this.list[i].participator;
  412. if (part.length>0) {
  413. for (var j in part) {
  414. this.userList.filter(u=>u.id == part[j].id)[0].isChecked = true;
  415. }
  416. this.refreshParticipate();
  417. }
  418. }
  419. this.show = true;
  420. },
  421. chargeBtn(action, done) {
  422. if (action === 'confirm') {
  423. this.show = false;
  424. const toast = this.$toast.loading({
  425. forbidClick: true,
  426. duration: 0
  427. });
  428. let formData = new URLSearchParams();
  429. formData.append("name", this.form.projectName);
  430. formData.append("code", this.form.projectCode);
  431. formData.append("inchargerId", this.form.inchargerId);
  432. for (var j in this.form.userId) {
  433. formData.append("userId", this.form.userId[j]);
  434. }
  435. if(this.form.id != null) {
  436. // form.id = this.form.id;
  437. formData.append("id", this.form.id);
  438. }
  439. if(this.form.associateDegreeNames != '' && this.form.associateDegreeNames != null) {
  440. formData.append("associateDegreeNames", this.form.associateDegreeNames);
  441. } else {
  442. formData.append("associateDegreeNames", null);
  443. }
  444. if(this.form.associateDegrees != null && this.form.associateDegrees.length != 0) {
  445. var sss = this.form.associateDegrees.toString()
  446. formData.append("associateDegrees", sss);
  447. } else {
  448. formData.append("associateDegrees", null);
  449. }
  450. // const config = {
  451. // // headers: {
  452. // // 'Content-Type': 'multipart/form-data',
  453. // // // 'Content-Type': 'application/x-www-form-urlencoded'
  454. // // },
  455. // // transformRequest: [function (data, headers) {
  456. // // return data;
  457. // // }],
  458. // }
  459. this.$axios.post("/project/editProject", formData)
  460. .then(res => {
  461. if(res.code == "ok") {
  462. this.$toast.clear();
  463. this.$toast.success(this.form.id==null?'新增成功':'修改成功');
  464. this.list = [];
  465. this.page = 1;
  466. this.getProject();
  467. this.yanjiuzx()
  468. } else {
  469. this.$toast.clear();
  470. this.$toast.fail(this.form.id==null?'新增失败':'修改失败');
  471. }
  472. }).catch(err=> {this.$toast.clear();});
  473. } else {
  474. this.show = false;
  475. this.yanjiuzx()
  476. }
  477. done();
  478. },
  479. // 删除项目
  480. delPro(i) {
  481. this.$dialog.confirm({
  482. title: '删除项目',
  483. message: '确定要项目'+this.list[i].projectName+'吗?'
  484. }).then(() => {
  485. const toast = this.$toast.loading({
  486. forbidClick: true,
  487. duration: 0
  488. });
  489. this.$axios.post("/project/deleteProject", {id: this.list[i].id})
  490. .then(res => {
  491. if(res.code == "ok") {
  492. this.$toast.clear();
  493. this.$toast.success('删除成功');
  494. this.list = [];
  495. this.page = 1;
  496. this.getProject();
  497. } else {
  498. this.$toast.clear();
  499. this.$toast.fail(res.msg);
  500. }
  501. }).catch(err=> {this.$toast.clear();});
  502. }).catch(() => {});
  503. },
  504. },
  505. mounted() {
  506. this.getUsers();
  507. this.yanjiuzx()
  508. this.getProject()
  509. // this.canEdit = (this.user.role==1||this.user.role==2||this.user.role==5);
  510. var list = this.user.functionList
  511. for(var i in list) {
  512. if(list[i].name == '新增项目') {
  513. this.projectAdd = true
  514. }
  515. if(list[i].name == '管理全部项目') {
  516. this.projectManagement = true
  517. }
  518. }
  519. }
  520. };
  521. </script>
  522. <style lang="less" scoped>
  523. .login_form {
  524. margin-top: 46px;
  525. }
  526. .one_report {
  527. margin-bottom: 15px;
  528. }
  529. .form_text {
  530. margin: 15px 0 30px;
  531. padding: 0 12px;
  532. }
  533. .form_btn {
  534. text-align: right;
  535. }
  536. .form_btn button {
  537. margin-left: 10px;
  538. }
  539. .one_report_data {
  540. margin-bottom: 20px;
  541. padding: 0 22px;
  542. div {
  543. line-height: 30px;
  544. }
  545. }
  546. .userCheckbox {
  547. padding: 10px;;
  548. }
  549. </style>
  550. <style lang="less">
  551. .van-nav-bar .van-icon , .van-nav-bar__text {
  552. color: #20a0ff;
  553. }
  554. </style>