editCheckList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view class="check-map-list">
  3. <scroll-view class="scroll-y" scroll-y="true">
  4. <view class="item"
  5. v-for="(item, index) in checkList"
  6. :key="index">
  7. <view class="title-wrap">
  8. <text>{{item.deptName}}</text>
  9. <view>
  10. <image src="../../static/icon-map.png"></image>
  11. <text>{{item.deptClassName}}</text>
  12. </view>
  13. </view>
  14. <view class="content">
  15. <text>{{item.decs}}</text>
  16. <text>
  17. 要点概览:{{item.checkPointNames}}
  18. </text>
  19. </view>
  20. <view class="footer">
  21. <view class="row" @click="checkEdit(item, index, '指派查核人员')">
  22. <text class="label">查核人</text>
  23. <view class="content">
  24. <text :class="['base-text', item.empName ? 'black-color' : '']">
  25. {{ item.empName ? item.empName : '选择查核成员'}}
  26. </text>
  27. </view>
  28. <image class="arrow" src="/static/images/icon-more.png"></image>
  29. </view>
  30. <view class="row" @click="checkEdit(item, index, '设置查核时间')">
  31. <text class="label">计划时间</text>
  32. <view class="content">
  33. <text :class="['base-text', item.startDate ? 'black-color' : '']">
  34. {{ item.startDate ? item.startDate : '选择起始时间' }}
  35. </text>
  36. <text class="center-text">至</text>
  37. <text :class="['base-text', item.endDate ? 'black-color' : '']">
  38. {{ item.endDate ? item.endDate : '选择结束时间' }}
  39. </text>
  40. </view>
  41. <image class="arrow" src="/static/images/icon-more.png"></image>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. <view class="null" v-if="checkList.length === 0">暂无数据</view>
  47. <view class="fixed-buttom-btn" @click="submit">
  48. <text class="btn-text">完成</text>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. // 查核列表(查核人和计划时间可编辑)
  54. import { mapState } from "vuex";
  55. import moment from 'moment';
  56. export default {
  57. computed: {
  58. ...mapState({
  59. checkList: state => state.editCheckList.checkList
  60. })
  61. },
  62. data() {
  63. return {
  64. // 查核组id
  65. checkGroupId: 0,
  66. // 情境id (批量修改有,不然为0)
  67. situationId: 0,
  68. // 查核id
  69. checkId: 0,
  70. // 计划开始时间
  71. startDate: '',
  72. // 计划结束时间
  73. endDate: '',
  74. multiple: 'false',
  75. planList: []
  76. };
  77. },
  78. onLoad({ situationId, checkId, checkGroupId, startDate, endDate, multiple }){
  79. this.getCheckList(checkId);
  80. this.checkGroupId = checkGroupId ? +checkGroupId : 0;
  81. this.situationId = situationId ? +situationId : 0;
  82. this.checkId = checkId ? +checkId : 0;
  83. this.startDate = startDate;
  84. this.endDate = endDate;
  85. this.multiple = multiple;
  86. },
  87. methods: {
  88. // 完成
  89. submit() {
  90. // baseEmpList: 第一次计划修改的数据; changePlanList: 批量分配,记录第一次计划修改数据的信息; multipleEmpList: 批量修改的数据
  91. let baseEmpList = [], changePlanList = [], multipleEmpList = [];
  92. // planStartTimestamp: 开始计划时间戳;
  93. let planStartTimestamp = this.dateToTimestamp(this.startDate);
  94. this.checkList.map((item, i) => {
  95. const {checkId, deptId, empId, empName, startDate, endDate} = item;
  96. if(empId || empName || startDate || endDate){
  97. baseEmpList.push({
  98. checkId,
  99. deptId,
  100. empId,
  101. empName,
  102. startDate: startDate || '',
  103. endDate: endDate || ''
  104. });
  105. if(this.multiple === 'true'){ // 批量分配
  106. changePlanList.push({
  107. index: i, // 第一次计划修改的下标
  108. baseEmpListIndex: baseEmpList.length -1,
  109. startDiffTimestamp: startDate ? this.dateToTimestamp(startDate) - planStartTimestamp : 0, // 开始时间差
  110. endDifTimestamp: endDate ? this.dateToTimestamp(endDate) - planStartTimestamp : 0 // 结束时间差
  111. });
  112. }
  113. }
  114. });
  115. if(this.multiple === 'true') { // 批量分配
  116. this.$store.dispatch({
  117. type: 'planList/commActions',
  118. payload: {
  119. key: 'planList',
  120. data:{situationId: this.situationId}
  121. }
  122. }).then((planList) => {
  123. (planList || []).map(((planItem, planI) => {
  124. if(planI != 0){ // 过滤掉第一条
  125. // 计划开始时间戳
  126. let planStartTimestamp = planItem.startDate ? this.dateToTimestamp(planItem.startDate + ' 00:00') : 0;
  127. // 计划结束时间戳
  128. let planEndTimestamp = planItem.endDate ? this.dateToTimestamp(planItem.endDate + ' 23:59') : 0;
  129. planItem.empList && planItem.empList.map((empItem, empI) => {
  130. // 当前分配明细
  131. let currentEmp = changePlanList.find(item => item.index === empI);
  132. if(currentEmp){
  133. const { baseEmpListIndex, startDiffTimestamp, endDifTimestamp } = currentEmp;
  134. const { empId, empName } = baseEmpList[baseEmpListIndex] || {};
  135. multipleEmpList.push({
  136. empId,
  137. empName,
  138. checkId: empItem.checkId,
  139. deptId: empItem.deptId,
  140. startDate: (planStartTimestamp && startDiffTimestamp)
  141. ? this.getDateStr(planStartTimestamp, planEndTimestamp, startDiffTimestamp, planItem.endDate)
  142. : '',
  143. endDate: (planStartTimestamp && endDifTimestamp)
  144. ? this.getDateStr(planStartTimestamp, planEndTimestamp, endDifTimestamp, planItem.endDate)
  145. : ''
  146. });
  147. }
  148. })
  149. }
  150. }))
  151. multipleEmpList = [...baseEmpList, ...multipleEmpList];
  152. // console.log('批量',multipleEmpList )
  153. this.batchDistribute(multipleEmpList);
  154. })
  155. }else { // 单个分配
  156. this.batchDistribute(baseEmpList);
  157. }
  158. },
  159. /**
  160. * 获取时间字符串
  161. * @param {Number} startTimestamp 计划开始时间戳
  162. * @param {Number} endTimestamp 计划结束时间戳
  163. * @param {Number} diffTimestamp 第一次计划中的时间差
  164. * @param {String} endDateStr 计划结束时间字符串
  165. */
  166. getDateStr(startTimestamp, endTimestamp, diffTimestamp, endDateStr) {
  167. if((startTimestamp + diffTimestamp) > endTimestamp){ // 超出计划结束时间, 则取计划结束时间
  168. return endDateStr;
  169. }else {
  170. return moment(startTimestamp + diffTimestamp).format('YYYY-MM-DD HH:mm');
  171. }
  172. },
  173. // 分配单位查核人员
  174. batchDistribute(empList) {
  175. this.$store.dispatch({
  176. type: 'editCheckList/commActions',
  177. key: "batchDistribute",
  178. data: { empList }
  179. }).then(data => {
  180. if(data){
  181. uni.redirectTo({
  182. url: `/pages/planList/planList?situationId=${this.situationId}&checkGroupId=${this.checkGroupId}`
  183. });
  184. }
  185. });
  186. },
  187. // 日期时间转换为时间戳
  188. dateToTimestamp(dataStr) {
  189. return dataStr ? moment(dataStr).valueOf() : 0
  190. },
  191. checkEdit(data, index, title) {
  192. if(data.completeState){ // 计划已开始, 不能编辑查核人和计划时间
  193. uni.showModal({
  194. content: '因查核计划已开始,故不可修改',
  195. showCancel: false
  196. });
  197. }else {// 跳转编辑页面
  198. const { empId, empName, startDate, endDate } = data;
  199. let details = {
  200. index, // 修改的下标
  201. title, // 标题
  202. empId,
  203. empName,
  204. startDate,
  205. endDate,
  206. situationId: this.situationId, // 情境id (批量修改有,不然为0)
  207. checkId: this.checkId, // 查核id
  208. checkGroupId: this.checkGroupId, //查核组id
  209. planStartDate: this.startDate, // 计划开始时间
  210. planEndDate: this.endDate // 计划结束时间
  211. }
  212. uni.navigateTo({
  213. url: `/pages/allocationPerson/allocationPerson?details=${encodeURIComponent(JSON.stringify(details))}`
  214. });
  215. }
  216. },
  217. // 获取查核列表
  218. getCheckList(checkId) {
  219. this.$store.dispatch({
  220. type: 'editCheckList/commActions',
  221. key: "getCheckList",
  222. data: { checkId }
  223. }).then(data => {
  224. this.$store.dispatch({
  225. type: "commActions",
  226. key: "getDateStr",
  227. }).then((dateStr) => {
  228. if (dateStr) {
  229. this.$store.commit({
  230. type: 'editCheckList/comChangeState',
  231. key: 'checkList',
  232. data: (data || []).map(item => {
  233. if (item.startDate && moment(item.startDate).valueOf() < moment(dateStr).valueOf()) {
  234. return {
  235. ...item,
  236. completeState: true // true:说明计划已开始, 不能编辑查核人和计划时间
  237. }
  238. }else {
  239. return item
  240. }
  241. })
  242. });
  243. }
  244. });
  245. });
  246. },
  247. // 获取计划列表
  248. getPlanList() {
  249. this.$store.dispatch({
  250. type: 'planList/commActions',
  251. payload: {
  252. key: 'planList',
  253. data:{
  254. situationId: this.situationId
  255. }
  256. }
  257. }).then((data) => {
  258. this.planList = data || [];
  259. })
  260. }
  261. }
  262. }
  263. </script>
  264. <style lang="less">
  265. .check-map-list {
  266. height: 100%;
  267. .scroll-y {
  268. height: calc(100% - 87.5rpx);
  269. padding-top: 25rpx;
  270. .footer {
  271. .row {
  272. display: flex;
  273. align-items: center;
  274. justify-content: space-between;
  275. border-top: 1px solid #DADEE6;
  276. height: 62.5rpx;
  277. padding: 0 25rpx;
  278. font-size: 22.5rpx;
  279. .label {
  280. color: #525866;
  281. width: 93.75rpx;
  282. }
  283. .content {
  284. display: flex;
  285. flex-direction: row;
  286. align-items: center;
  287. flex: 1;
  288. height: 100%;
  289. padding: 0 25rpx;
  290. .base-text {
  291. flex: 1;
  292. line-height: 62.5rpx;
  293. color: #B8BECC;
  294. font-weight: normal;
  295. }
  296. .center-text {
  297. padding: 0 25rpx;
  298. color: #292C33;
  299. }
  300. .black-color {
  301. color: #292C33;
  302. }
  303. }
  304. .arrow {
  305. width: 12.5rpx;
  306. height: 21.25rpx;
  307. }
  308. }
  309. }
  310. }
  311. .null {
  312. text-align: center;
  313. color: #999;
  314. }
  315. }
  316. </style>