checkPlan.vue 7.7 KB

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