checkPlan.vue 7.9 KB

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