editCheckList.vue 16 KB

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