index.vue 24 KB

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