123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <template>
- <view class="check-plan">
- <view class="title">请制定查核计划({{showCheckPlan1 ? 1 : 2}}/2)</view>
- <view class="content1" v-if="showCheckPlan1">
- <view class="list">
- <view class="item" v-for="(item, index) in list" :key="index">
- <view class="text-wrap">
- <input v-if="item.id === 'custom'"
- v-model="item.model"
- type="number"
- @input="createList"
- placeholder="自定义" />
- <text>{{item.label}}</text>
- </view>
- <view class="img-wrap" @click="checkModel(item)">
- <image :src="`../../static/check-${checkPlan.checkedItem.id === item.id
- ? 'radio': 'no'}.png`"></image>
- </view>
- </view>
- </view>
- <view class="date-box">
- <text>起止时间</text>
- <view>
- <date-time-pick-group fields="day"
- :startTime="startTime()"
- :startSelectValue="start"
- :endSelectValue="end"
- v-on:changeDate="changeDate"></date-time-pick-group>
- <image src="../../../static/incon-more.png"></image>
- </view>
- </view>
- <view class="result-box">
- <text>查核频次</text>
- <text>{{checkNumber}}</text>
- </view>
- </view>
- <view class="content2" v-else>
- <view class="top-box">
- <view class="result-box">
- <text>开始日期</text>
- <text>{{checkPlan.dateObj.start}}</text>
- </view>
- <view class="date-box">
- <text>结束日期</text>
- <view>
- <date-time-picker fields="day"
- placeholder="请选择结束日期"
- :start="endStart"
- :defaultValue="checkPlan.dateObj.end"
- v-on:change="changeDateEnd"></date-time-picker>
- <image src="../../../static/incon-more.png"></image>
- </view>
- </view>
- </view>
- <view class="content2-list">
- <view class="item" v-for="(item, index) in checkPlan.checkList" :key="index">
- <text>第{{index + 1}}次查核</text>
- <view class="date-box">
- <text>开始日期</text>
- <view>
- <date-time-picker fields="day"
- :start="startDate(index)"
- :end="endDate(index)"
- placeholder="请选择开始日期"
- :defaultValue="item"
- v-on:change="changeChildDate($event, index)"></date-time-picker>
- <image src="../../../static/incon-more.png"></image>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { mapState } from "vuex";
- import {dateHandle} from "../../../utils/dateHandle.js";
- const {dateDiff, getNewData, todayDate, compare} = dateHandle;
- import {checkPlanList} from "./utils.js";
-
- export default {
- data() {
- return {
- list: checkPlanList,
- start: todayDate(),
- end: '',
- timer: null
- }
- },
- computed: {
- ...mapState({
- showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
- checkPlan: state => state.creatingSituations.checkPlan,
- }),
- checkNumber: function() { // 查核频次
- return this.checkPlan.checkList.length;
- },
- endStart() {
- const {checkList, checkedItem} = this.checkPlan;
- let date = '';
- if(checkList.length>0) {
- date = getNewData(checkList[checkList.length-1], checkedItem.model)
- } else {
- date = this.start;
- }
- return date + ' 00:00';
- },
- endDate() { // 获取能选择的最大日期,取结束日期的前模天
- return function(index) {
- let day = -Number(this.checkPlan.checkedItem.model); // 使用负数能取前X天
- let date = '';
- if(index < this.checkPlan.checkList.length -1) {
- date = getNewData(this.checkPlan.checkList[index+1], day);
- } else {
- date = getNewData(this.end, day+1);
- }
- return date + ' 23:59';
- }
- },
- startDate() { // 子级能选择的最早开始时间
- return function(index) {
- let date = '';
- if(index > 0) {
- let day = Number(this.checkPlan.checkedItem.model);
- date = getNewData(this.checkPlan.checkList[index - 1], day);
- } else {
- date = this.start;
- }
- return date + ' 00:00';
- }
- },
- },
- created: function() {
- const {start,end} = this.checkPlan.dateObj;
- this.start = start;
- this.end = end;
- },
- methods: {
- checkModel: function(item) {
- this.myCommit('checkedItem', item);
- this.createList();
- },
- /**
- * 开始、结束日期变化函数
- * @param {Object} date 日期对象
- * @param {Object} type 返回类型(start/end)
- */
- changeDate: function(date, type) {
- let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
- dateObj[type] = date.f1;
- this[type] = date.f1;
- const {start, end} = dateObj;
- if(start && end) {
- let num = dateDiff(start, end);
- if(num >= 0) {
- dateObj.dayNum = num + 1; // 开始的那天也要算
- this.myCommit('dateObj', dateObj);
- this.createList();
- } else {
- uni.showModal({
- title: '错误提示',
- content: '开始日期必须小于结束日期!',
- showCancel: false,
- success: () => {
- this[type] = this.checkPlan.dateObj[type];
- }
- });
- }
- } else {
- this.myCommit('dateObj', dateObj);
- }
- },
- changeDateEnd(date) {
- let dateObj = JSON.parse(JSON.stringify(this.checkPlan.dateObj));
- dateObj.end = date.f1;
- this.end = date.f1;
- this.myCommit('dateObj', dateObj);
- this.changeList(this.checkPlan.checkList);
- },
- /**
- * 构造计划列表
- */
- createList: function() {
- const { model } = this.checkPlan.checkedItem;
- const {start, dayNum} = this.checkPlan.dateObj;
- let checkList = [];
- if(model && dayNum > 0 && dayNum >= model) { // 确保前两步都做好了
- let num = Math.floor(dayNum / model);
- checkList = [start];
- for(let i = 0; i < num - 1; i++) {
- checkList[i+1] = getNewData(checkList[i], model);
- }
- }
- this.myCommit('checkList', checkList);
- },
- /**
- * 已经生成的计划日期变化
- * @param {Object} date
- */
- changeChildDate: function(date, index) {
- let newList = [...this.checkPlan.checkList];
- newList[index] = date.f1;
- // const { model } = this.checkPlan.checkedItem;
- // let i = index;
- // // 判断下一个计划开始时间日期不能大于结束的前X(模)天
- // while(compare(this.endDate(), getNewData(newList[i], model))) {
- // newList[i+1] = getNewData(newList[i], model);
- // i++;
- // }
- this.changeList(newList);
- },
- changeList(checkList){
- if(this.timer) clearTimeout(this.timer);
- this.myCommit('checkList', []);
- this.timer = setTimeout(()=>{
- this.myCommit('checkList', checkList);
- },0);
- },
- startTime: function() { // 限制只能从今天开始
- return this.formateStartEnd(todayDate());
- },
- formateStartEnd: function(str) {
- return str + ' 00:00';
- },
- /**
- * 更新condition数据
- * @param {Object} key 要更新的属性
- * @param {Object} value 值
- */
- myCommit: function(key, value) {
- let data = {...this.checkPlan};
- data[key] = value;
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'checkPlan',
- data
- });
- }
- }
- }
- </script>
- <style lang="less">
- .check-plan {
- font-size: 22.5rpx;
- line-height: 33.75rpx;
- color: #292C33;
- .content1 {
- .list {
- padding-left: 25rpx;
- background-color: #fff;
- .item {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- border-bottom: 1px solid #DADEE6;
- width: 100%;
- height: 87.5rpx;
- .text-wrap {
- display: flex;
- flex-direction: row;
- align-items: center;
- input {
- margin-right: 25rpx;
- width: 75rpx;
- font-size: 22.5rpx;
- line-height: 33.75rpx;
- color: #292C33;
- }
- }
- .img-wrap {
- display: flex;
- flex-direction: row;
- justify-content: center;
- align-items: center;
- width: 75rpx;
- height: 100%;
- image {
- width: 25rpx;
- height: 25rpx;
- }
- }
- }
- }
- }
- .content2 {
- .top-box {
- padding-left: 25rpx;
- background-color: #fff;
- .date-box,
- .result-box {
- padding-left: 0;
- }
- .result-box {
- border-bottom: 1px solid #DADEE6;
- }
- }
- .content2-list {
- padding-bottom: 25rpx;
- .item {
- display: flex;
- flex-direction: column;
- margin-top: 19.37rpx;
- >text {
- padding-bottom: 9.37rpx;
- padding-left: 25rpx;
- color: #666F80;
- }
- }
- }
- .date-box,
- .result-box {
- margin-top: 0;
- }
- }
- .date-box,
- .result-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- margin-top: 15rpx;
- padding: 0 25rpx;
- width: 100%;
- height: 87.5rpx;
- background-color: #fff;
- >text:first-child {
- margin-right: 85rpx;
- white-space: nowrap;
- color: #525866;
- }
- >view {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- width: 100%;
- image {
- width: 12.5rpx;
- height: 21.25rpx;
- }
- }
- }
- }
- </style>
|