checkPlan.vue 7.4 KB

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