checkPlan.vue 7.8 KB

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