checkPlan.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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="checkPlan.dateObj.start"
  27. :endSelectValue="checkPlan.dateObj.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="startTime()"
  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. const list = [
  81. {id: 'week', value: 1, label: '每周', model: 7},
  82. {id: 'month', value: 2, label: '每月', model: 30},
  83. {id: 'twoMonth', value: 3, label: '每两月', model: 60},
  84. {id: 'quarter', value: 4, label: '每季度', model: 90},
  85. {id: 'halfAYear', value: 5, label: '每半年', model: 180},
  86. {id: 'custom', value: 6, label: '天', model: null},
  87. ];
  88. export default {
  89. data() {
  90. return {
  91. list
  92. }
  93. },
  94. computed: {
  95. ...mapState({
  96. showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
  97. checkPlan: state => state.creatingSituations.checkPlan,
  98. }),
  99. checkNumber: function() { // 查核频次
  100. return this.checkPlan.checkList.length;
  101. }
  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 = {...this.checkPlan.dateObj};
  115. dateObj[type] = date.f1;
  116. this.myCommit('dateObj', dateObj);
  117. const {start, end} = dateObj;
  118. if(start && end) {
  119. dateObj.dayNum = dateDiff(start, end);
  120. this.myCommit('dateObj', dateObj);
  121. this.createList();
  122. }
  123. },
  124. /**
  125. * 构造计划列表
  126. */
  127. createList: function() {
  128. const { model } = this.checkPlan.checkedItem;
  129. const {start, dayNum} = this.checkPlan.dateObj;
  130. let checkList = [];
  131. if(model && dayNum > 0) { // 确保前两步都做好了
  132. let num = Math.floor(dayNum / model);
  133. checkList = [start];
  134. for(let i = 0; i < num - 1; i++) {
  135. checkList[i+1] = getNewData(checkList[i], model);
  136. }
  137. }
  138. this.myCommit('checkList', checkList);
  139. },
  140. /**
  141. * 已经生成的计划日期变化
  142. * @param {Object} date
  143. */
  144. changeChildDate: function(date, index) {
  145. let newList = this.checkPlan.checkList.slice(0, index); // 不包括index
  146. newList[index] = date.f1;
  147. const { model } = this.checkPlan.checkedItem;
  148. let i = index;
  149. // 判断下一个计划开始时间日期不能大于结束的前X(模)天
  150. while(compare(this.endDate(), getNewData(newList[i], model))) {
  151. newList[i+1] = getNewData(newList[i], model);
  152. i++;
  153. }
  154. this.myCommit('checkList', newList);
  155. },
  156. startTime: function() { // 限制只能从今天开始
  157. return this.formateStartEnd(todayDate());
  158. },
  159. endDate: function() { // 获取能选择的最大日期,取结束日期的前模天
  160. let day = -Number(this.checkPlan.checkedItem.model); // 使用负数能取前X天
  161. return getNewData(this.checkPlan.dateObj.end, day);
  162. },
  163. startDate: function(index) { // 子级能选择的最早开始时间
  164. if(index > 0) {
  165. let day = Number(this.checkPlan.checkedItem.model);
  166. return this.formateStartEnd(getNewData(this.checkPlan.checkList[index - 1], day));
  167. } else {
  168. return this.startTime();
  169. }
  170. },
  171. formateStartEnd: function(str) {
  172. return str + ' 00:00';
  173. },
  174. /**
  175. * 更新condition数据
  176. * @param {Object} key 要更新的属性
  177. * @param {Object} value 值
  178. */
  179. myCommit: function(key, value) {
  180. let data = {...this.checkPlan};
  181. data[key] = value;
  182. this.$store.commit({
  183. type: 'creatingSituations/comChangeState',
  184. key: 'checkPlan',
  185. data
  186. });
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="less">
  192. .check-plan {
  193. font-size: 22.5rpx;
  194. line-height: 33.75rpx;
  195. color: #292C33;
  196. .content1 {
  197. .list {
  198. padding-left: 25rpx;
  199. background-color: #fff;
  200. .item {
  201. display: flex;
  202. flex-direction: row;
  203. justify-content: space-between;
  204. align-items: center;
  205. border-bottom: 1px solid #DADEE6;
  206. width: 100%;
  207. height: 87.5rpx;
  208. .text-wrap {
  209. display: flex;
  210. flex-direction: row;
  211. align-items: center;
  212. input {
  213. margin-right: 25rpx;
  214. width: 75rpx;
  215. font-size: 22.5rpx;
  216. line-height: 33.75rpx;
  217. color: #292C33;
  218. }
  219. }
  220. .img-wrap {
  221. display: flex;
  222. flex-direction: row;
  223. justify-content: center;
  224. align-items: center;
  225. width: 75rpx;
  226. height: 100%;
  227. image {
  228. width: 25rpx;
  229. height: 25rpx;
  230. }
  231. }
  232. }
  233. }
  234. }
  235. .content2 {
  236. .top-box {
  237. padding-left: 25rpx;
  238. background-color: #fff;
  239. .date-box,
  240. .result-box {
  241. padding-left: 0;
  242. }
  243. .result-box {
  244. border-bottom: 1px solid #DADEE6;
  245. }
  246. }
  247. .content2-list {
  248. padding-bottom: 25rpx;
  249. .item {
  250. display: flex;
  251. flex-direction: column;
  252. margin-top: 19.37rpx;
  253. >text {
  254. padding-bottom: 9.37rpx;
  255. padding-left: 25rpx;
  256. color: #666F80;
  257. }
  258. }
  259. }
  260. .date-box,
  261. .result-box {
  262. margin-top: 0;
  263. }
  264. }
  265. .date-box,
  266. .result-box {
  267. display: flex;
  268. flex-direction: row;
  269. align-items: center;
  270. margin-top: 15rpx;
  271. padding: 0 25rpx;
  272. width: 100%;
  273. height: 87.5rpx;
  274. background-color: #fff;
  275. >text:first-child {
  276. margin-right: 85rpx;
  277. white-space: nowrap;
  278. color: #525866;
  279. }
  280. >view {
  281. display: flex;
  282. flex-direction: row;
  283. justify-content: space-between;
  284. align-items: center;
  285. width: 100%;
  286. image {
  287. width: 12.5rpx;
  288. height: 21.25rpx;
  289. }
  290. }
  291. }
  292. }
  293. </style>