checkPlan.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view class="check-plan">
  3. <view class="title">请制定查核计划({{showCheckPlan1 ? 1 : 2}}/2)</view>
  4. <view class="content1" v-if="showCheckPlan1">
  5. <view class="list">
  6. <view class="item" v-for="(item, index) in list" :key="index">
  7. <view class="text-wrap">
  8. <input v-if="item.id === 'custom'"
  9. v-model="item.model"
  10. @focus="checkModel(item)"
  11. type="number"
  12. @input="createList"
  13. placeholder="自定义" />
  14. <text>{{item.label}}</text>
  15. </view>
  16. <view class="img-wrap" @click="checkModel(item)">
  17. <image :src="`../../static/check-${checkPlan.checkedItem.id === item.id
  18. ? 'radio': 'no'}.png`"></image>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="date-box">
  23. <text>起止时间</text>
  24. <view>
  25. <date-time-pick-group fields="day"
  26. :startTime="startTime()"
  27. :startSelectValue="start"
  28. :endSelectValue="end"
  29. v-on:changeDate="changeDate"></date-time-pick-group>
  30. <image src="../../../static/incon-more.png"></image>
  31. </view>
  32. </view>
  33. <view class="result-box">
  34. <text>查核频次</text>
  35. <text>{{checkNumber}}</text>
  36. </view>
  37. </view>
  38. <view class="content2" v-else>
  39. <view class="top-box">
  40. <view class="result-box">
  41. <text>开始日期</text>
  42. <text>{{checkPlan.dateObj.start}}</text>
  43. </view>
  44. <view class="date-box">
  45. <text>结束日期</text>
  46. <view>
  47. <date-time-picker fields="day"
  48. placeholder="请选择结束日期"
  49. :start="endStart"
  50. :defaultValue="checkPlan.dateObj.end"
  51. v-on:change="changeDateEnd"></date-time-picker>
  52. <image src="../../../static/incon-more.png"></image>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="content2-list">
  57. <view class="item" v-for="(item, index) in checkPlan.checkList" :key="index">
  58. <text>第{{index + 1}}次查核</text>
  59. <view class="date-box">
  60. <text>开始日期</text>
  61. <view>
  62. <date-time-picker fields="day"
  63. :start="startDate(index)"
  64. :end="endDate(index)"
  65. placeholder="请选择开始日期"
  66. :defaultValue="item"
  67. v-on:change="changeChildDate($event, index)"></date-time-picker>
  68. <image src="../../../static/incon-more.png"></image>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import { mapState } from "vuex";
  78. import {dateHandle} from "../../../utils/dateHandle.js";
  79. const {dateDiff, getNewData, todayDate, compare} = dateHandle;
  80. import {checkPlanList} from "./utils.js";
  81. export default {
  82. data() {
  83. return {
  84. list: checkPlanList,
  85. start: todayDate(),
  86. end: '',
  87. timer: null
  88. }
  89. },
  90. computed: {
  91. ...mapState({
  92. showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
  93. checkPlan: state =>{
  94. console.log('state.creatingSituations.checkPlan',state.creatingSituations.checkPlan);
  95. return state.creatingSituations.checkPlan;
  96. },
  97. }),
  98. checkNumber: function() { // 查核频次
  99. return this.checkPlan.checkList.length;
  100. },
  101. endStart() {
  102. const {checkList, checkedItem} = this.checkPlan;
  103. let date = '';
  104. if(checkList.length>0) {
  105. date = getNewData(checkList[checkList.length-1], checkedItem.model-1)
  106. } else {
  107. date = this.start;
  108. }
  109. return date + ' 00:00';
  110. },
  111. endDate() { // 获取能选择的最大日期,取结束日期的前模天
  112. return function(index) {
  113. let day = -Number(this.checkPlan.checkedItem.model); // 使用负数能取前X天
  114. let date = '';
  115. if(index < this.checkPlan.checkList.length -1) {
  116. date = getNewData(this.checkPlan.checkList[index+1], day);
  117. } else {
  118. date = getNewData(this.end, day+1);
  119. }
  120. return date + ' 23:59';
  121. }
  122. },
  123. startDate() { // 子级能选择的最早开始时间
  124. return function(index) {
  125. let date = '';
  126. if(index > 0) {
  127. let day = Number(this.checkPlan.checkedItem.model);
  128. date = getNewData(this.checkPlan.checkList[index - 1], day);
  129. } else {
  130. date = this.start;
  131. }
  132. return date + ' 00:00';
  133. }
  134. },
  135. },
  136. created: function() {
  137. const {start,end} = this.checkPlan.dateObj;
  138. this.start = start;
  139. this.end = end;
  140. },
  141. methods: {
  142. checkModel: function(item) {
  143. this.myCommit('checkedItem', item);
  144. this.createList();
  145. },
  146. /**
  147. * 开始、结束日期变化函数
  148. * @param {Object} date 日期对象
  149. * @param {Object} type 返回类型(start/end)
  150. */
  151. changeDate: function(date, type) {
  152. let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
  153. dateObj[type] = date.f1;
  154. this[type] = date.f1;
  155. const {start, end} = dateObj;
  156. if(start && end) {
  157. let num = dateDiff(start, end);
  158. if(num >= 0) {
  159. dateObj.dayNum = num + 1; // 开始的那天也要算
  160. this.myCommit('dateObj', dateObj);
  161. this.createList();
  162. } else {
  163. uni.showModal({
  164. title: '错误提示',
  165. content: '开始日期必须小于结束日期!',
  166. showCancel: false,
  167. success: () => {
  168. this[type] = this.checkPlan.dateObj[type];
  169. }
  170. });
  171. }
  172. } else {
  173. this.myCommit('dateObj', dateObj);
  174. }
  175. },
  176. changeDateEnd(date) {
  177. let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
  178. dateObj.end = date.f1;
  179. this.end = date.f1;
  180. this.myCommit('dateObj', dateObj);
  181. this.changeList([...this.checkPlan.checkList]);
  182. },
  183. /**
  184. * 构造计划列表
  185. */
  186. createList: function() {
  187. const { model } = this.checkPlan.checkedItem;
  188. const {start, dayNum} = this.checkPlan.dateObj;
  189. let checkList = [];
  190. if(model && dayNum > 0 && dayNum >= model) { // 确保前两步都做好了
  191. let num = Math.floor(dayNum / model);
  192. checkList = [start];
  193. for(let i = 0; i < num - 1; i++) {
  194. checkList[i+1] = getNewData(checkList[i], model);
  195. }
  196. }
  197. this.myCommit('checkList', checkList);
  198. },
  199. /**
  200. * 已经生成的计划日期变化
  201. * @param {Object} date
  202. */
  203. changeChildDate: function(date, index) {
  204. let newList = [...this.checkPlan.checkList];
  205. newList[index] = date.f1;
  206. // const { model } = this.checkPlan.checkedItem;
  207. // let i = index;
  208. // // 判断下一个计划开始时间日期不能大于结束的前X(模)天
  209. // while(compare(this.endDate(), getNewData(newList[i], model))) {
  210. // newList[i+1] = getNewData(newList[i], model);
  211. // i++;
  212. // }
  213. this.changeList(newList);
  214. },
  215. changeList(checkList){
  216. if(this.timer) clearTimeout(this.timer);
  217. this.myCommit('checkList', []);
  218. this.timer = setTimeout(()=>{
  219. this.myCommit('checkList', checkList);
  220. },0);
  221. },
  222. startTime: function() { // 限制只能从今天开始
  223. return this.formateStartEnd(todayDate());
  224. },
  225. formateStartEnd: function(str) {
  226. return str + ' 00:00';
  227. },
  228. /**
  229. * 更新condition数据
  230. * @param {Object} key 要更新的属性
  231. * @param {Object} value 值
  232. */
  233. myCommit: function(key, value) {
  234. let data = {...this.checkPlan};
  235. data[key] = value;
  236. this.$store.commit({
  237. type: 'creatingSituations/comChangeState',
  238. key: 'checkPlan',
  239. data
  240. });
  241. }
  242. }
  243. }
  244. </script>
  245. <style lang="less">
  246. .check-plan {
  247. font-size: 22.5rpx;
  248. line-height: 33.75rpx;
  249. color: #292C33;
  250. .content1 {
  251. .list {
  252. padding-left: 25rpx;
  253. background-color: #fff;
  254. .item {
  255. display: flex;
  256. flex-direction: row;
  257. justify-content: space-between;
  258. align-items: center;
  259. border-bottom: 1px solid #DADEE6;
  260. width: 100%;
  261. height: 87.5rpx;
  262. .text-wrap {
  263. display: flex;
  264. flex-direction: row;
  265. align-items: center;
  266. input {
  267. margin-right: 25rpx;
  268. width: 75rpx;
  269. font-size: 22.5rpx;
  270. line-height: 33.75rpx;
  271. color: #292C33;
  272. }
  273. }
  274. .img-wrap {
  275. display: flex;
  276. flex-direction: row;
  277. justify-content: center;
  278. align-items: center;
  279. width: 75rpx;
  280. height: 100%;
  281. image {
  282. width: 25rpx;
  283. height: 25rpx;
  284. }
  285. }
  286. }
  287. }
  288. }
  289. .content2 {
  290. .top-box {
  291. padding-left: 25rpx;
  292. background-color: #fff;
  293. .date-box,
  294. .result-box {
  295. padding-left: 0;
  296. }
  297. .result-box {
  298. border-bottom: 1px solid #DADEE6;
  299. }
  300. }
  301. .content2-list {
  302. padding-bottom: 25rpx;
  303. .item {
  304. display: flex;
  305. flex-direction: column;
  306. margin-top: 19.37rpx;
  307. >text {
  308. padding-bottom: 9.37rpx;
  309. padding-left: 25rpx;
  310. color: #666F80;
  311. }
  312. }
  313. }
  314. .date-box,
  315. .result-box {
  316. margin-top: 0;
  317. }
  318. }
  319. .date-box,
  320. .result-box {
  321. display: flex;
  322. flex-direction: row;
  323. align-items: center;
  324. margin-top: 15rpx;
  325. padding: 0 25rpx;
  326. width: 100%;
  327. height: 87.5rpx;
  328. background-color: #fff;
  329. >text:first-child {
  330. margin-right: 85rpx;
  331. white-space: nowrap;
  332. color: #525866;
  333. }
  334. >view {
  335. display: flex;
  336. flex-direction: row;
  337. justify-content: space-between;
  338. align-items: center;
  339. width: 100%;
  340. image {
  341. width: 12.5rpx;
  342. height: 21.25rpx;
  343. }
  344. }
  345. }
  346. }
  347. </style>