checkPlan.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 => state.creatingSituations.checkPlan,
  94. }),
  95. checkNumber: function() { // 查核频次
  96. return this.checkPlan.checkList.length;
  97. },
  98. endStart() {
  99. const {checkList, checkedItem} = this.checkPlan;
  100. let date = '';
  101. if(checkList.length>0) {
  102. date = getNewData(checkList[checkList.length-1], checkedItem.model-1)
  103. } else {
  104. date = this.start;
  105. }
  106. return date + ' 00:00';
  107. },
  108. endDate() { // 获取能选择的最大日期,取结束日期的前模天
  109. return function(index) {
  110. let day = -Number(this.checkPlan.checkedItem.model); // 使用负数能取前X天
  111. let date = '';
  112. if(index < this.checkPlan.checkList.length -1) {
  113. date = getNewData(this.checkPlan.checkList[index+1], day);
  114. } else {
  115. date = getNewData(this.end, day+1);
  116. }
  117. return date + ' 23:59';
  118. }
  119. },
  120. startDate() { // 子级能选择的最早开始时间
  121. return function(index) {
  122. let date = '';
  123. if(index > 0) {
  124. let day = Number(this.checkPlan.checkedItem.model);
  125. date = getNewData(this.checkPlan.checkList[index - 1], day);
  126. } else {
  127. date = this.start;
  128. }
  129. return date + ' 00:00';
  130. }
  131. },
  132. },
  133. created: function() {
  134. const {start,end} = this.checkPlan.dateObj;
  135. this.start = start;
  136. this.end = end;
  137. },
  138. methods: {
  139. checkModel: function(item) {
  140. this.myCommit('checkedItem', item);
  141. this.createList();
  142. },
  143. /**
  144. * 开始、结束日期变化函数
  145. * @param {Object} date 日期对象
  146. * @param {Object} type 返回类型(start/end)
  147. */
  148. changeDate: function(date, type) {
  149. let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
  150. dateObj[type] = date.f1;
  151. this[type] = date.f1;
  152. const {start, end} = dateObj;
  153. if(start && end) {
  154. let num = dateDiff(start, end);
  155. if(num >= 0) {
  156. dateObj.dayNum = num + 1; // 开始的那天也要算
  157. this.myCommit('dateObj', dateObj);
  158. this.createList();
  159. } else {
  160. uni.showModal({
  161. title: '错误提示',
  162. content: '开始日期必须小于结束日期!',
  163. showCancel: false,
  164. success: () => {
  165. this[type] = this.checkPlan.dateObj[type];
  166. }
  167. });
  168. }
  169. } else {
  170. this.myCommit('dateObj', dateObj);
  171. }
  172. },
  173. changeDateEnd(date) {
  174. let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
  175. dateObj.end = date.f1;
  176. this.end = date.f1;
  177. this.myCommit('dateObj', dateObj);
  178. this.changeList([...this.checkPlan.checkList]);
  179. },
  180. /**
  181. * 构造计划列表
  182. */
  183. createList: function() {
  184. const { model } = this.checkPlan.checkedItem;
  185. const {start, dayNum} = this.checkPlan.dateObj;
  186. let checkList = [];
  187. if(model && dayNum > 0 && dayNum >= model) { // 确保前两步都做好了
  188. let num = Math.floor(dayNum / model);
  189. checkList = [start];
  190. for(let i = 0; i < num - 1; i++) {
  191. checkList[i+1] = getNewData(checkList[i], model);
  192. }
  193. }
  194. this.myCommit('checkList', checkList);
  195. },
  196. /**
  197. * 已经生成的计划日期变化
  198. * @param {Object} date
  199. */
  200. changeChildDate: function(date, index) {
  201. let newList = [...this.checkPlan.checkList];
  202. newList[index] = date.f1;
  203. // const { model } = this.checkPlan.checkedItem;
  204. // let i = index;
  205. // // 判断下一个计划开始时间日期不能大于结束的前X(模)天
  206. // while(compare(this.endDate(), getNewData(newList[i], model))) {
  207. // newList[i+1] = getNewData(newList[i], model);
  208. // i++;
  209. // }
  210. this.changeList(newList);
  211. },
  212. changeList(checkList){
  213. if(this.timer) clearTimeout(this.timer);
  214. this.myCommit('checkList', []);
  215. this.timer = setTimeout(()=>{
  216. this.myCommit('checkList', checkList);
  217. },0);
  218. },
  219. startTime: function() { // 限制只能从今天开始
  220. return this.formateStartEnd(todayDate());
  221. },
  222. formateStartEnd: function(str) {
  223. return str + ' 00:00';
  224. },
  225. /**
  226. * 更新condition数据
  227. * @param {Object} key 要更新的属性
  228. * @param {Object} value 值
  229. */
  230. myCommit: function(key, value) {
  231. let data = {...this.checkPlan};
  232. data[key] = value;
  233. this.$store.commit({
  234. type: 'creatingSituations/comChangeState',
  235. key: 'checkPlan',
  236. data
  237. });
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="less">
  243. .check-plan {
  244. font-size: 22.5rpx;
  245. line-height: 33.75rpx;
  246. color: #292C33;
  247. .content1 {
  248. .list {
  249. padding-left: 25rpx;
  250. background-color: #fff;
  251. .item {
  252. display: flex;
  253. flex-direction: row;
  254. justify-content: space-between;
  255. align-items: center;
  256. border-bottom: 1px solid #DADEE6;
  257. width: 100%;
  258. height: 87.5rpx;
  259. .text-wrap {
  260. display: flex;
  261. flex-direction: row;
  262. align-items: center;
  263. input {
  264. margin-right: 25rpx;
  265. width: 75rpx;
  266. font-size: 22.5rpx;
  267. line-height: 33.75rpx;
  268. color: #292C33;
  269. }
  270. }
  271. .img-wrap {
  272. display: flex;
  273. flex-direction: row;
  274. justify-content: center;
  275. align-items: center;
  276. width: 75rpx;
  277. height: 100%;
  278. image {
  279. width: 25rpx;
  280. height: 25rpx;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. .content2 {
  287. .top-box {
  288. padding-left: 25rpx;
  289. background-color: #fff;
  290. .date-box,
  291. .result-box {
  292. padding-left: 0;
  293. }
  294. .result-box {
  295. border-bottom: 1px solid #DADEE6;
  296. }
  297. }
  298. .content2-list {
  299. padding-bottom: 25rpx;
  300. .item {
  301. display: flex;
  302. flex-direction: column;
  303. margin-top: 19.37rpx;
  304. >text {
  305. padding-bottom: 9.37rpx;
  306. padding-left: 25rpx;
  307. color: #666F80;
  308. }
  309. }
  310. }
  311. .date-box,
  312. .result-box {
  313. margin-top: 0;
  314. }
  315. }
  316. .date-box,
  317. .result-box {
  318. display: flex;
  319. flex-direction: row;
  320. align-items: center;
  321. margin-top: 15rpx;
  322. padding: 0 25rpx;
  323. width: 100%;
  324. height: 87.5rpx;
  325. background-color: #fff;
  326. >text:first-child {
  327. margin-right: 85rpx;
  328. white-space: nowrap;
  329. color: #525866;
  330. }
  331. >view {
  332. display: flex;
  333. flex-direction: row;
  334. justify-content: space-between;
  335. align-items: center;
  336. width: 100%;
  337. image {
  338. width: 12.5rpx;
  339. height: 21.25rpx;
  340. }
  341. }
  342. }
  343. }
  344. </style>