checkPlan.vue 7.2 KB

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