checkPlan.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="check-plan">
  3. <view class="title" v-if="theme.id != 2">请制定查核计划({{showCheckPlan1 ? 1 : 2}}/2)</view>
  4. <view class="title" v-if="theme.id == 2">请制定查核计划</view>
  5. <view class="content1" v-if="showCheckPlan1">
  6. <view class="list">
  7. <view class="item" v-for="(item, index) in list" :key="index">
  8. <view class="text-wrap">
  9. <input v-if="item.id === 'custom'"
  10. v-model="item.model"
  11. @focus="checkModel(item)"
  12. type="number"
  13. @input="createList"
  14. placeholder="自定义" />
  15. <text>{{item.label}}</text>
  16. </view>
  17. <view class="img-wrap" @click="checkModel(item)">
  18. <image :src="`../../static/check-${checkPlan.checkedItem.id === item.id
  19. ? 'radio': 'no'}.png`"></image>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="date-box">
  24. <text>起止时间</text>
  25. <view>
  26. <date-time-pick-group fields="day"
  27. :startTime="startTime()"
  28. :startSelectValue="start"
  29. :endSelectValue="end"
  30. v-on:changeDate="changeDate"></date-time-pick-group>
  31. <image src="../../../static/incon-more.png"></image>
  32. </view>
  33. </view>
  34. <view class="result-box">
  35. <text>查核频次</text>
  36. <text>{{checkNumber}}</text>
  37. </view>
  38. </view>
  39. <view class="content2" v-else>
  40. <view class="top-box">
  41. <view class="result-box">
  42. <text>开始日期</text>
  43. <text>{{checkPlan.dateObj.start}}</text>
  44. </view>
  45. <view class="date-box">
  46. <text>结束日期</text>
  47. <view>
  48. <date-time-picker fields="day"
  49. placeholder="请选择结束日期"
  50. :start="endStart"
  51. :defaultValue="checkPlan.dateObj.end"
  52. v-on:change="changeDateEnd"></date-time-picker>
  53. <image src="../../../static/incon-more.png"></image>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="content2-list">
  58. <view class="item" v-for="(item, index) in checkPlan.checkList" :key="index">
  59. <text>第{{index + 1}}次查核</text>
  60. <view class="date-box">
  61. <text>开始日期</text>
  62. <view>
  63. <date-time-picker fields="day"
  64. :start="startDate(index)"
  65. :end="endDate(index)"
  66. placeholder="请选择开始日期"
  67. :defaultValue="item"
  68. v-on:change="changeChildDate($event, index)"></date-time-picker>
  69. <image src="../../../static/incon-more.png"></image>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import { mapState } from "vuex";
  79. import {dateHandle} from "../../../utils/dateHandle.js";
  80. const {dateDiff, getNewData, todayDate, compare} = dateHandle;
  81. import {checkPlanList} from "./utils.js";
  82. export default {
  83. data() {
  84. return {
  85. list: checkPlanList,
  86. start: todayDate(),
  87. end: '',
  88. timer: null
  89. }
  90. },
  91. computed: {
  92. ...mapState({
  93. showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
  94. theme: state => state.creatingSituations.theme,
  95. checkPlan: state =>{
  96. return state.creatingSituations.checkPlan;
  97. },
  98. }),
  99. checkNumber: function() { // 查核频次
  100. return this.checkPlan.checkList.length;
  101. },
  102. endStart() {
  103. const {checkList, checkedItem} = this.checkPlan;
  104. let date = '';
  105. if(checkList.length>0) {
  106. date = getNewData(checkList[checkList.length-1], checkedItem.model-1)
  107. } else {
  108. date = this.start;
  109. }
  110. return date + ' 00:00';
  111. },
  112. endDate() { // 获取能选择的最大日期,取结束日期的前模天
  113. return function(index) {
  114. let day = -Number(this.checkPlan.checkedItem.model); // 使用负数能取前X天
  115. let date = '';
  116. if(index < this.checkPlan.checkList.length -1) {
  117. date = getNewData(this.checkPlan.checkList[index+1], day);
  118. } else {
  119. date = getNewData(this.end, day+1);
  120. }
  121. return date + ' 23:59';
  122. }
  123. },
  124. startDate() { // 子级能选择的最早开始时间
  125. return function(index) {
  126. let date = '';
  127. if(index > 0) {
  128. let day = Number(this.checkPlan.checkedItem.model);
  129. date = getNewData(this.checkPlan.checkList[index - 1], day);
  130. } else {
  131. date = this.start;
  132. }
  133. return date + ' 00:00';
  134. }
  135. },
  136. },
  137. created: function() {
  138. const {start,end} = this.checkPlan.dateObj;
  139. this.start = start;
  140. this.end = end;
  141. },
  142. methods: {
  143. checkModel: function(item) {
  144. this.myCommit('checkedItem', item);
  145. this.createList();
  146. },
  147. /**
  148. * 开始、结束日期变化函数
  149. * @param {Object} date 日期对象
  150. * @param {Object} type 返回类型(start/end)
  151. */
  152. changeDate: function(date, type) {
  153. let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
  154. dateObj[type] = date.f1;
  155. this[type] = date.f1;
  156. const {start, end} = dateObj;
  157. if(start && end) {
  158. let num = dateDiff(start, end);
  159. if(num >= 0) {
  160. dateObj.dayNum = num + 1; // 开始的那天也要算
  161. this.myCommit('dateObj', dateObj);
  162. this.createList();
  163. } else {
  164. uni.showModal({
  165. title: '错误提示',
  166. content: '开始日期必须小于结束日期!',
  167. showCancel: false,
  168. success: () => {
  169. this[type] = this.checkPlan.dateObj[type];
  170. }
  171. });
  172. }
  173. } else {
  174. this.myCommit('dateObj', dateObj);
  175. }
  176. },
  177. changeDateEnd(date) {
  178. let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
  179. dateObj.end = date.f1;
  180. this.end = date.f1;
  181. this.myCommit('dateObj', dateObj);
  182. this.changeList([...this.checkPlan.checkList]);
  183. },
  184. /**
  185. * 构造计划列表
  186. */
  187. createList: function() {
  188. const { model } = this.checkPlan.checkedItem;
  189. const {start, dayNum} = this.checkPlan.dateObj;
  190. let checkList = [];
  191. if(model && dayNum > 0 && dayNum >= model) { // 确保前两步都做好了
  192. let num = Math.floor(dayNum / model);
  193. checkList = [start];
  194. for(let i = 0; i < num - 1; i++) {
  195. checkList[i+1] = getNewData(checkList[i], model);
  196. }
  197. }
  198. this.myCommit('checkList', checkList);
  199. },
  200. /**
  201. * 已经生成的计划日期变化
  202. * @param {Object} date
  203. */
  204. changeChildDate: function(date, index) {
  205. let newList = [...this.checkPlan.checkList];
  206. newList[index] = date.f1;
  207. // const { model } = this.checkPlan.checkedItem;
  208. // let i = index;
  209. // // 判断下一个计划开始时间日期不能大于结束的前X(模)天
  210. // while(compare(this.endDate(), getNewData(newList[i], model))) {
  211. // newList[i+1] = getNewData(newList[i], model);
  212. // i++;
  213. // }
  214. this.changeList(newList);
  215. },
  216. changeList(checkList){
  217. if(this.timer) clearTimeout(this.timer);
  218. this.myCommit('checkList', []);
  219. this.timer = setTimeout(()=>{
  220. this.myCommit('checkList', checkList);
  221. },0);
  222. },
  223. startTime: function() { // 限制只能从今天开始
  224. return this.formateStartEnd(todayDate());
  225. },
  226. formateStartEnd: function(str) {
  227. return str + ' 00:00';
  228. },
  229. /**
  230. * 更新condition数据
  231. * @param {Object} key 要更新的属性
  232. * @param {Object} value 值
  233. */
  234. myCommit: function(key, value) {
  235. let data = {...this.checkPlan};
  236. data[key] = value;
  237. this.$store.commit({
  238. type: 'creatingSituations/comChangeState',
  239. key: 'checkPlan',
  240. data
  241. });
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="less">
  247. .check-plan {
  248. font-size: 22.5rpx;
  249. line-height: 33.75rpx;
  250. color: #292C33;
  251. .content1 {
  252. .list {
  253. padding-left: 25rpx;
  254. background-color: #fff;
  255. .item {
  256. display: flex;
  257. flex-direction: row;
  258. justify-content: space-between;
  259. align-items: center;
  260. border-bottom: 1px solid #DADEE6;
  261. width: 100%;
  262. height: 87.5rpx;
  263. .text-wrap {
  264. display: flex;
  265. flex-direction: row;
  266. align-items: center;
  267. input {
  268. margin-right: 25rpx;
  269. width: 75rpx;
  270. font-size: 22.5rpx;
  271. line-height: 33.75rpx;
  272. color: #292C33;
  273. }
  274. }
  275. .img-wrap {
  276. display: flex;
  277. flex-direction: row;
  278. justify-content: center;
  279. align-items: center;
  280. width: 75rpx;
  281. height: 100%;
  282. image {
  283. width: 25rpx;
  284. height: 25rpx;
  285. }
  286. }
  287. }
  288. }
  289. }
  290. .content2 {
  291. .top-box {
  292. padding-left: 25rpx;
  293. background-color: #fff;
  294. .date-box,
  295. .result-box {
  296. padding-left: 0;
  297. }
  298. .result-box {
  299. border-bottom: 1px solid #DADEE6;
  300. }
  301. }
  302. .content2-list {
  303. padding-bottom: 25rpx;
  304. .item {
  305. display: flex;
  306. flex-direction: column;
  307. margin-top: 19.37rpx;
  308. >text {
  309. padding-bottom: 9.37rpx;
  310. padding-left: 25rpx;
  311. color: #666F80;
  312. }
  313. }
  314. }
  315. .date-box,
  316. .result-box {
  317. margin-top: 0;
  318. }
  319. }
  320. .date-box,
  321. .result-box {
  322. display: flex;
  323. flex-direction: row;
  324. align-items: center;
  325. margin-top: 15rpx;
  326. padding: 0 25rpx;
  327. width: 100%;
  328. height: 87.5rpx;
  329. background-color: #fff;
  330. >text:first-child {
  331. margin-right: 85rpx;
  332. white-space: nowrap;
  333. color: #525866;
  334. }
  335. >view {
  336. display: flex;
  337. flex-direction: row;
  338. justify-content: space-between;
  339. align-items: center;
  340. width: 100%;
  341. image {
  342. width: 12.5rpx;
  343. height: 21.25rpx;
  344. }
  345. }
  346. }
  347. }
  348. </style>