editCheckList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <view class="check-map-list">
  3. <scroll-view :class="[ifAllPlanListHasDistribution==true?'scroll-y noBottom':'scroll-y']" scroll-y="true" v-if="checkList.length > 0">
  4. <view class="item" v-for="(item, index) in checkList" :key="index">
  5. <view v-if="multiple != 'true'&&ifStartCheck(item.startDate)"
  6. :class="{'checkPoint':true,checked:checkedList.includes(item.deptId)}"
  7. @click="checkedHandle(item.deptId)">
  8. <image class="innerImg" v-if="checkedList.includes(item.deptId)"
  9. src="../../static/check-checkbox.png" mode=""></image>
  10. </view>
  11. <view class="status" :style="{'background':item.color}" >{{item.completeDes}}</view>
  12. <view class="title-wrap">
  13. <text>{{item.deptName}}</text>
  14. <view>
  15. <image src="../../static/icon-map.png"></image>
  16. <text>{{item.deptClassName}}</text>
  17. </view>
  18. </view>
  19. <view class="content">
  20. <text>{{item.decs}}</text>
  21. <text>
  22. 要点概览:{{item.checkPointNames}}
  23. </text>
  24. </view>
  25. <view class="footer">
  26. <view class="row" @click="checkEdit(item, index, '指派查核人员')">
  27. <text class="label">查核人</text>
  28. <view class="content">
  29. <text :class="['base-text', item.empName ? 'black-color' : '']">
  30. {{ item.empName ? item.empName : '选择查核成员'}}
  31. </text>
  32. </view>
  33. <image class="arrow" src="/static/images/icon-more.png"></image>
  34. </view>
  35. <view class="row" @click="checkEdit(item, index, '设置查核时间')">
  36. <text class="label">计划时间</text>
  37. <view class="content">
  38. <text :class="['base-text', item.startDate ? 'black-color' : '']">
  39. {{ item.startDate ? item.startDate : '选择起始时间' }}
  40. </text>
  41. <text class="center-text">至</text>
  42. <text :class="['base-text', item.endDate ? 'black-color' : '']">
  43. {{ item.endDate ? item.endDate : '选择结束时间' }}
  44. </text>
  45. </view>
  46. <image class="arrow" src="/static/images/icon-more.png"></image>
  47. </view>
  48. </view>
  49. </view>
  50. </scroll-view>
  51. <view class="null" v-else>暂无数据</view>
  52. <view class="fixed-buttom-btn" @click="submit" v-if="multiple == 'true'">
  53. <text class="btn-text">完成</text>
  54. </view>
  55. <view class="bottomBtnGroup" v-if="multiple != 'true'&&ifAllPlanListHasDistribution==false">
  56. <view class="leftBtn" @click="bottomBtnClickHandle('left')">{{ifCheckAll?'取消':'全选'}}</view>
  57. <view class="rightBtn" @click="bottomBtnClickHandle('right')">{{`(已选${checkedList.length}项)批量分配`}}</view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. // 查核列表(查核人和计划时间可编辑)
  63. import {
  64. mapState
  65. } from "vuex";
  66. import moment from 'moment';
  67. export default {
  68. computed: {
  69. ...mapState({
  70. checkList: state => state.editCheckList.checkList
  71. }),
  72. //计算当所有查核计划都已分配完时掩藏底部批量按钮
  73. ifAllPlanListHasDistribution: function() {
  74. const tempData = this.checkList.filter(item => (!item.empId && !item.empName));
  75. return tempData.length == 0
  76. }
  77. },
  78. data() {
  79. return {
  80. // 查核组id
  81. checkGroupId: 0,
  82. // 情境id (批量修改有,不然为0)
  83. situationId: 0,
  84. // 查核id
  85. checkId: 0,
  86. // 计划开始时间
  87. startDate: '',
  88. // 计划结束时间
  89. endDate: '',
  90. multiple: false,
  91. planList: [],
  92. hasStartedCheck: [], //查核已经开始的集合
  93. ifInit: null,
  94. ifshowBottom: false,
  95. checkedList: [], //批量选中的集合
  96. ifCheckAll:false,//是否全选
  97. };
  98. },
  99. onLoad({
  100. situationId,
  101. checkId,
  102. checkGroupId,
  103. startDate,
  104. endDate,
  105. multiple,
  106. situationType,
  107. checkNo
  108. }) {
  109. this.init(situationId,
  110. checkId,
  111. checkGroupId,
  112. startDate,
  113. endDate,
  114. multiple,
  115. situationType,
  116. checkNo
  117. );
  118. },
  119. onShow() {
  120. let pages = getCurrentPages(); // 获取当前页面栈
  121. let curPage = pages[pages.length - 1]; // 当前页面
  122. if (curPage.ifInit) {
  123. curPage.ifInit = false;
  124. this.init(
  125. this.situationId,
  126. this.checkId,
  127. this.checkGroupId,
  128. this.startDate,
  129. this.endDate,
  130. this.multiple,
  131. this.situationType,
  132. this.checkNo
  133. ) // A页面 method中的方法,用来刷新页面A
  134. }
  135. },
  136. mounted() {},
  137. onUnload() {
  138. //页面卸载或返回
  139. this.$store.commit('planList/comChangeState',{key:'ifReloadData',data:true})
  140. },
  141. methods: {
  142. init(situationId,
  143. checkId,
  144. checkGroupId,
  145. startDate,
  146. endDate,
  147. multiple,
  148. situationType,
  149. checkNo) {
  150. this.getCheckList(checkId, situationType);
  151. this.checkGroupId = checkGroupId ? +checkGroupId : 0;
  152. this.situationId = situationId ? +situationId : 0;
  153. this.checkId = checkId ? +checkId : 0;
  154. this.startDate = startDate;
  155. this.endDate = endDate;
  156. this.multiple = multiple;
  157. this.checkedList = [];
  158. this.situationType = situationType;
  159. this.checkNo = checkNo;
  160. },
  161. ifStartCheck(timeStr) {
  162. if (timeStr) {
  163. const currentTime = new Date().getTime();
  164. const startTime = Date.parse(timeStr.replace(/-/g, '/'));
  165. if (currentTime < startTime) {
  166. this.ifshowBottom = true;
  167. }
  168. return currentTime < startTime;
  169. }
  170. this.ifshowBottom = true;
  171. return true;
  172. },
  173. bottomBtnClickHandle(key) {
  174. let details = {
  175. index: '', // 修改的下标
  176. title: '', // 标题
  177. empId: '',
  178. empName: '',
  179. startDate: '',
  180. endDate: '',
  181. situationType: this.situationType,
  182. checkNo:this.checkNo,
  183. checkedList: this.checkedList,
  184. situationId: this.situationId, // 情境id (批量修改有,不然为0)
  185. checkId: this.checkId, // 查核id
  186. checkGroupId: this.checkGroupId, //查核组id
  187. planStartDate: this.startDate, // 计划开始时间
  188. planEndDate: this.endDate // 计划结束时间
  189. }
  190. if (key == 'left') {
  191. this.ifCheckAll = !this.ifCheckAll;
  192. if(this.ifCheckAll){
  193. const tempArr = this.checkList.filter(item => this.ifStartCheck(item.startDate));
  194. this.checkedList = tempArr.map(v => v.deptId);
  195. }else {
  196. this.checkedList = [];
  197. }
  198. }
  199. if (key == 'right') {
  200. if (this.checkedList.length > 0) {
  201. uni.navigateTo({
  202. url: `/pages/batchDistribution/batchDistribution?details=${encodeURIComponent(JSON.stringify(details))}`
  203. });
  204. } else {
  205. uni.showModal({
  206. title: '提示',
  207. content: '请先选择分配项!',
  208. showCancel: false
  209. });
  210. }
  211. }
  212. },
  213. checkedHandle(deptId) {
  214. // console.log({checkId});
  215. let temp = JSON.parse(JSON.stringify(this.checkedList)); //去除_observer_
  216. if (temp.includes(deptId)) {
  217. temp.splice(temp.findIndex(v => v === deptId), 1);
  218. this.checkedList = temp;
  219. } else {
  220. this.checkedList = this.checkedList.concat([deptId]);
  221. }
  222. },
  223. // 完成
  224. submit() {
  225. // baseEmpList: 第一次计划修改的数据; changePlanList: 批量分配,记录第一次计划修改数据的信息; multipleEmpList: 批量修改的数据
  226. let baseEmpList = [],
  227. changePlanList = [],
  228. multipleEmpList = [];
  229. // planStartTimestamp: 开始计划时间戳;
  230. let planStartTimestamp = this.dateToTimestamp(this.startDate);
  231. this.checkList.map((item, i) => {
  232. const {
  233. checkId,
  234. deptId,
  235. empId,
  236. empName,
  237. startDate,
  238. endDate
  239. } = item;
  240. if (empId && startDate && endDate) {
  241. baseEmpList.push({
  242. checkId,
  243. deptId,
  244. empId,
  245. empName,
  246. startDate: startDate || '',
  247. endDate: endDate || ''
  248. });
  249. if (this.multiple === 'true') { // 批量分配
  250. changePlanList.push({
  251. index: i, // 第一次计划修改的下标
  252. baseEmpListIndex: baseEmpList.length - 1,
  253. startDiffTimestamp: (startDate && planStartTimestamp != -1) ? this
  254. .dateToTimestamp(startDate) - planStartTimestamp : -1, // 开始时间差
  255. endDifTimestamp: (endDate && planStartTimestamp != -1) ? this
  256. .dateToTimestamp(endDate) - planStartTimestamp : -1 // 结束时间差
  257. });
  258. }
  259. }
  260. });
  261. if (this.multiple === 'true') { // 批量分配
  262. this.$store.dispatch({
  263. type: 'planList/commActions',
  264. payload: {
  265. key: 'planList',
  266. data: {
  267. situationId: this.situationId
  268. }
  269. }
  270. }).then((planList) => {
  271. (planList || []).map(((planItem, planI) => {
  272. if (planI != 0) { // 过滤掉第一条
  273. // 计划开始时间戳
  274. let planStartTimestamp = planItem.startDate ? this.dateToTimestamp(
  275. planItem.startDate + ' 00:00') : -1;
  276. // 计划结束时间戳
  277. let planEndTimestamp = planItem.endDate ? this.dateToTimestamp(planItem
  278. .endDate + ' 23:59') : -1;
  279. planItem.empList && planItem.empList.map((empItem, empI) => {
  280. // 当前分配明细
  281. let currentEmp = changePlanList.find(item => item.index ===
  282. empI);
  283. if (currentEmp) {
  284. const {
  285. baseEmpListIndex,
  286. startDiffTimestamp,
  287. endDifTimestamp
  288. } = currentEmp;
  289. const {
  290. empId,
  291. empName
  292. } = baseEmpList[baseEmpListIndex] || {};
  293. multipleEmpList.push({
  294. empId,
  295. empName,
  296. checkId: empItem.checkId,
  297. deptId: empItem.deptId,
  298. startDate: (planStartTimestamp > -1 &&
  299. startDiffTimestamp > -1) ?
  300. this.getDateStr(planStartTimestamp,
  301. planEndTimestamp,
  302. startDiffTimestamp, planItem
  303. .endDate) : '',
  304. endDate: (planStartTimestamp > -1 &&
  305. endDifTimestamp > -1) ?
  306. this.getDateStr(planStartTimestamp,
  307. planEndTimestamp, endDifTimestamp,
  308. planItem.endDate) : ''
  309. });
  310. }
  311. })
  312. }
  313. }))
  314. multipleEmpList = [...baseEmpList, ...multipleEmpList];
  315. // console.log('批量',multipleEmpList )
  316. this.batchDistribute(multipleEmpList);
  317. })
  318. } else { // 单个分配
  319. this.batchDistribute(baseEmpList);
  320. }
  321. },
  322. /**
  323. * 获取时间字符串
  324. * @param {Number} startTimestamp 计划开始时间戳
  325. * @param {Number} endTimestamp 计划结束时间戳
  326. * @param {Number} diffTimestamp 第一次计划中的时间差
  327. * @param {String} endDateStr 计划结束时间字符串
  328. */
  329. getDateStr(startTimestamp, endTimestamp, diffTimestamp, endDateStr) {
  330. if ((startTimestamp + diffTimestamp) > endTimestamp) { // 超出计划结束时间, 则取计划结束时间
  331. return endDateStr;
  332. } else {
  333. return moment(startTimestamp + diffTimestamp).format('YYYY-MM-DD HH:mm');
  334. }
  335. },
  336. // 分配单位查核人员
  337. batchDistribute(empList) {
  338. if (empList.length === 0) { // 未作修改直接跳转页面
  339. return this.redirectToPlanList();
  340. }
  341. this.$store.dispatch({
  342. type: 'editCheckList/commActions',
  343. key: "batchDistribute",
  344. data: {
  345. empList
  346. }
  347. }).then(data => {
  348. if (data) {
  349. this.redirectToPlanList();
  350. }
  351. });
  352. },
  353. // 跳转页面
  354. redirectToPlanList() {
  355. uni.redirectTo({
  356. url: `/pages/planList/planList?situationId=${this.situationId}&checkGroupId=${this.checkGroupId}`
  357. });
  358. },
  359. // 日期时间转换为时间戳
  360. dateToTimestamp(dataStr) {
  361. return dataStr ? moment(dataStr).valueOf() : -1
  362. },
  363. checkEdit(data, index, title) {
  364. // console.log({data});
  365. if (data.completeState) { // 计划已开始, 不能编辑查核人和计划时间
  366. uni.showModal({
  367. content: '因查核计划已结束,故不可修改',
  368. showCancel: false
  369. });
  370. } else { // 跳转编辑页面
  371. const {
  372. empId,
  373. empName,
  374. startDate,
  375. endDate,
  376. deptId,
  377. categoryId,
  378. isDistribution,
  379. } = data;
  380. let details = {
  381. index, // 修改的下标
  382. title, // 标题
  383. empId,
  384. empName,
  385. startDate,
  386. endDate,
  387. deptId,
  388. categoryId,
  389. isDistribution,
  390. situationType: this.situationType,
  391. checkNo:this.checkNo,
  392. situationId: this.situationId, // 情境id (批量修改有,不然为0)
  393. checkId: this.checkId, // 查核id
  394. checkGroupId: this.checkGroupId, //查核组id
  395. planStartDate: this.startDate, // 计划开始时间
  396. planEndDate: this.endDate // 计划结束时间
  397. }
  398. if (this.multiple == 'true') {
  399. uni.navigateTo({
  400. url: `/pages/allocationPerson/allocationPerson?details=${encodeURIComponent(JSON.stringify(details))}`
  401. });
  402. }
  403. if (this.multiple == 'false') {
  404. const _detailsTwo = {
  405. ...details,
  406. checkedList: [deptId]
  407. }
  408. uni.navigateTo({
  409. url: `/pages/batchDistribution/batchDistribution?details=${encodeURIComponent(JSON.stringify(_detailsTwo))}`
  410. });
  411. }
  412. }
  413. },
  414. // 获取查核列表
  415. getCheckList(checkId, situationType) {
  416. this.$store.dispatch({
  417. type: 'editCheckList/commActions',
  418. key: "getCheckList",
  419. data: {
  420. checkId,
  421. situationType
  422. }
  423. }).then(data => {
  424. this.$store.dispatch({
  425. type: "commActions",
  426. key: "getDateStr",
  427. }).then((dateStr) => {
  428. if (dateStr) {
  429. this.$store.commit({
  430. type: 'editCheckList/comChangeState',
  431. key: 'checkList',
  432. data: (data || []).map(item => {
  433. if (item.endDate && moment(item.endDate)
  434. .valueOf() < moment(dateStr).valueOf()) {
  435. return {
  436. ...item,
  437. completeState: true // true:说明计划已结束, 不能编辑查核人和计划时间
  438. }
  439. } else {
  440. return item
  441. }
  442. })
  443. });
  444. }
  445. });
  446. });
  447. },
  448. // 获取计划列表
  449. getPlanList() {
  450. this.$store.dispatch({
  451. type: 'planList/commActions',
  452. payload: {
  453. key: 'planList',
  454. data: {
  455. situationId: this.situationId,
  456. }
  457. }
  458. }).then((data) => {
  459. this.planList = data || [];
  460. })
  461. }
  462. }
  463. }
  464. </script>
  465. <style lang="less">
  466. .check-map-list {
  467. display: flex;
  468. flex-direction: column;
  469. height: 100%;
  470. .scroll-y {
  471. flex: 1;
  472. height: 100%;
  473. // height: calc(100% - 87.5rpx);
  474. padding-top: 25rpx;
  475. padding-bottom:95rpx;
  476. &.noBottom {
  477. padding-bottom:0;
  478. }
  479. .item {
  480. position: relative;
  481. }
  482. .checkPoint {
  483. position: absolute;
  484. top: 30rpx;
  485. right: 25rpx;
  486. width: 25rpx;
  487. height: 25rpx;
  488. z-index: 2;
  489. border-radius: 50%;
  490. border: 2.5rpx solid #C3CAD9;
  491. .innerImg {
  492. width: 100%;
  493. height: 100%;
  494. }
  495. &.checked {
  496. border: none;
  497. }
  498. }
  499. .status {
  500. position: absolute;
  501. top: 0;
  502. right:0;
  503. width: 100rpx;
  504. height: 35rpx;
  505. color: #FFFFFF;
  506. text-align: center;
  507. line-height: 35rpx;
  508. border-radius: 0px 5rpx 0px 28.12rpx;
  509. }
  510. .footer {
  511. .row {
  512. display: flex;
  513. align-items: center;
  514. justify-content: space-between;
  515. border-top: 1px solid #DADEE6;
  516. height: 62.5rpx;
  517. padding: 0 25rpx;
  518. font-size: 22.5rpx;
  519. .label {
  520. color: #525866;
  521. width: 93.75rpx;
  522. }
  523. .content {
  524. display: flex;
  525. flex-direction: row;
  526. align-items: center;
  527. flex: 1;
  528. height: 100%;
  529. padding: 0 25rpx;
  530. .base-text {
  531. flex: 1;
  532. line-height: 62.5rpx;
  533. color: #B8BECC;
  534. font-weight: normal;
  535. margin-bottom: 0;
  536. }
  537. .center-text {
  538. padding: 0 25rpx;
  539. color: #292C33;
  540. }
  541. .black-color {
  542. color: #292C33;
  543. }
  544. }
  545. .arrow {
  546. width: 12.5rpx;
  547. height: 21.25rpx;
  548. }
  549. }
  550. }
  551. }
  552. .bottomBtnGroup {
  553. position: fixed;
  554. width: 100%;
  555. height: 87.5rpx;
  556. bottom: 0;
  557. left: 0;
  558. display: flex;
  559. flex-direction: row;
  560. background-color: #FFFFFF;
  561. .leftBtn,
  562. .rightBtn {
  563. display: flex;
  564. width: 50%;
  565. height: 100%;
  566. justify-content: center;
  567. align-items: center;
  568. font-size: 22.5rpx;
  569. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  570. font-weight: 400;
  571. color: #3377FF;
  572. }
  573. .rightBtn {
  574. color: #FFFFFF;
  575. background-color: #3377FF;
  576. }
  577. }
  578. .null {
  579. margin-top: 375rpx;
  580. text-align: center;
  581. color: #999;
  582. }
  583. }
  584. </style>