<template> 
 | 
    <view class="box"> 
 | 
        <view class="box_hz" :style="{backgroundImage: 'url(' + backgroundImg + ')'}"> 
 | 
            <view class="box_hz_title">加减保申请</view> 
 | 
            <view class="box_hz_info">请按要求填写以下内容</view> 
 | 
            <view class="box_hz_list"> 
 | 
                <u--form 
 | 
                    labelPosition="top" 
 | 
                    :model="model" 
 | 
                    :rules="rules" 
 | 
                    ref="uForm" 
 | 
                > 
 | 
                    <u-form-item 
 | 
                        labelWidth="150" 
 | 
                        label="选择保单号:" 
 | 
                        prop="code" 
 | 
                        @click="show = true" 
 | 
                    > 
 | 
                        <u--input v-model="model.code" disabled disabledColor="#ffffff" placeholder="请选择" border="none"></u--input> 
 | 
                        <u-icon slot="right" name="arrow-right"></u-icon> 
 | 
                    </u-form-item> 
 | 
                <!--     <u-form-item 
 | 
                        labelWidth="200" 
 | 
                        label="选择期望批单生效期:" 
 | 
                        prop="startDate" 
 | 
                        @click="openTime" 
 | 
                    > 
 | 
                        <u--input v-model="model.startDate" disabled disabledColor="#ffffff" placeholder="请选择" border="none"></u--input> 
 | 
                        <u-icon slot="right" name="arrow-right"></u-icon> 
 | 
                    </u-form-item> --> 
 | 
                </u--form> 
 | 
            </view> 
 | 
            <view class="box_hz_footer"> 
 | 
                <u-button type="primary" shape="circle" color="#437CB3" text="下一步" @click="submit"></u-button> 
 | 
            </view> 
 | 
        </view> 
 | 
        <!-- 选择保单号 --> 
 | 
        <u-picker 
 | 
            :immediateChange="true" 
 | 
            :show="show" 
 | 
            :columns="columns" 
 | 
            keyName="label" 
 | 
            confirmColor="#437CB3" 
 | 
            @confirm="confirm" 
 | 
            @cancel="show = false" /> 
 | 
        <!-- 期望保险生效时间 --> 
 | 
        <u-datetime-picker 
 | 
            :show="show1" 
 | 
            mode="date" 
 | 
            :minDate="minDate" 
 | 
            :maxDate="maxDate" 
 | 
            @cancel="show1 = false" 
 | 
            @confirm="confirm1" /> 
 | 
    </view> 
 | 
</template> 
 | 
  
 | 
<script> 
 | 
    export default { 
 | 
        data() { 
 | 
            return { 
 | 
                show: false, 
 | 
                show1: false, 
 | 
                columns: [], 
 | 
                minDate: '', 
 | 
                maxDate: '', 
 | 
                id: '',   // 保单id 
 | 
                backgroundImg: require('@/static/background/toubao_bg@2x.png'), 
 | 
                model: { 
 | 
                    id: '',        // 方案id 
 | 
                    code: '', 
 | 
                    startDate: '', 
 | 
                    cyclePrice: '' 
 | 
                }, 
 | 
                rules: { 
 | 
                    'programmeName': { 
 | 
                        type: 'string', 
 | 
                        required: true, 
 | 
                        message: '请选择保险方案', 
 | 
                        trigger: ['blur', 'change'] 
 | 
                    }, 
 | 
                    'startDate': { 
 | 
                        type: 'string', 
 | 
                        required: true, 
 | 
                        message: '请选择保险生效开始日期', 
 | 
                        trigger: ['blur', 'change'] 
 | 
                    } 
 | 
                } 
 | 
            }; 
 | 
        }, 
 | 
        onLoad() { 
 | 
            this.getCodeList() 
 | 
        }, 
 | 
        methods: { 
 | 
            openTime() { 
 | 
                if (!this.model.code) return uni.showToast({ 
 | 
                    title: '请选择保单号', 
 | 
                    icon: 'none' 
 | 
                }) 
 | 
                this.show1 = true 
 | 
            }, 
 | 
            getCodeList() { 
 | 
                this.$u.api.insuranceApplyFindListByDTO({ 
 | 
                    status: '5,27', 
 | 
                    isEffective: 0 
 | 
                }).then(res => { 
 | 
                    if (res.code === 200) { 
 | 
                        res.data.forEach(item => { 
 | 
                            item.label = item.code 
 | 
                        }) 
 | 
                        this.columns = [res.data] 
 | 
                    } 
 | 
                }) 
 | 
            }, 
 | 
            async confirm(e) { 
 | 
                // 获取最新方案id 
 | 
                let res = await this.$u.api.insuranceApplyById(e.value[0].id) 
 | 
                if (res.code === 200) { 
 | 
                    this.model.id = res.data.newVersionSolutionId 
 | 
                    this.model.code = e.value[0].code 
 | 
                    this.id = e.value[0].id 
 | 
                    if ([1,3].includes(this.compareDates(this.getDate(), e.value[0].startTime)) && !e.value[0].lastChangeDate) { 
 | 
                        // 当前日期大于等于生效日期并且最后一次操作时间等于空 
 | 
                        // this.minDate = new Date(this.getTomorrow()).getTime() 
 | 
                        // this.maxDate = new Date(e.value[0].endTime).getTime() 
 | 
                        this.minDate = this.formatTimeStamp(this.getTomorrow()) 
 | 
                        this.maxDate = this.formatTimeStamp(e.value[0].endTime) 
 | 
                    } else if (this.compareDates(this.getDate(), e.value[0].startTime) === 2 && !e.value[0].lastChangeDate) { 
 | 
                        // 当前日期小于生效日期并且最后一次操作时间等于空 
 | 
                        // this.minDate = new Date(e.value[0].startTime).getTime() 
 | 
                        // this.maxDate = new Date(e.value[0].endTime).getTime() 
 | 
                        this.minDate = this.formatTimeStamp(e.value[0].startTime) 
 | 
                        this.maxDate = this.formatTimeStamp(e.value[0].endTime) 
 | 
                    } else if (e.value[0].lastChangeDate) { 
 | 
                        // 最后一次操作时间有值 
 | 
                        if ([1,3].includes(this.compareDates(this.getDate(), e.value[0].lastChangeDate))) { 
 | 
                            // 当前日期大于最后一次操作时间 
 | 
                            // this.minDate = new Date(this.getTomorrow()).getTime() 
 | 
                            // this.maxDate = new Date(e.value[0].endTime).getTime() 
 | 
                            this.minDate = this.formatTimeStamp(this.getTomorrow()) 
 | 
                            this.maxDate = this.formatTimeStamp(e.value[0].endTime) 
 | 
                        } else if (this.compareDates(this.getDate(), e.value[0].lastChangeDate) === 2) { 
 | 
                            // 当前时间小于最后一次操作时间 
 | 
                            // this.minDate = new Date(e.value[0].lastChangeDate).getTime() 
 | 
                            // this.maxDate = new Date(e.value[0].endTime).getTime() 
 | 
                            this.minDate = this.formatTimeStamp(e.value[0].lastChangeDate) 
 | 
                            this.maxDate = this.formatTimeStamp(e.value[0].endTime) 
 | 
                        } 
 | 
                    } 
 | 
                    this.confirm2(); 
 | 
                    this.show = false 
 | 
                } 
 | 
            }, 
 | 
            //封装函数(data格式为2017-11-11) 
 | 
            formatTimeStamp(date){ 
 | 
                console.log(Date.parse(new Date(`${date}`)) || Date.parse(new Date(`${date.replace(/-/g,'/')}`))) 
 | 
                return Date.parse(new Date(`${date}`)) || Date.parse(new Date(`${date.replace(/-/g,'/')}`)) 
 | 
            }, 
 | 
            // 选择时间 
 | 
            confirm1(e) { 
 | 
                this.model.startDate = uni.$u.timeFormat(e.value, 'yyyy-mm-dd') + ' 00:00:00' 
 | 
                this.$u.api.getChangeCountCyclePriceVO({ 
 | 
                    applyId: this.id, 
 | 
                    validTime: this.model.startDate 
 | 
                }).then(res => { 
 | 
                    if (res.code === 200) { 
 | 
                        this.model.cyclePrice = res.data.cyclePrice 
 | 
                        this.show1 = false 
 | 
                    } else { 
 | 
                        this.model.startDate = '' 
 | 
                    } 
 | 
                }) 
 | 
            }, 
 | 
            confirm2(e) {  
 | 
                this.$u.api.getChangeCountCyclePriceVO({ 
 | 
                    applyId: this.id ,  
 | 
                    validTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd') + ' 00:00:00' 
 | 
                }).then(res => { 
 | 
                    if (res.code === 200) { 
 | 
                        this.model.cyclePrice = res.data.cyclePrice 
 | 
                        this.show1 = false 
 | 
                    } else { 
 | 
                        this.model.startDate = '' 
 | 
                    } 
 | 
                }) 
 | 
            }, 
 | 
            // 获取明天日期 
 | 
            getTomorrow() { 
 | 
                var today = new Date(); 
 | 
                today.setDate(today.getDate() + 1); 
 | 
                var year = today.getFullYear(); 
 | 
                var month = today.getMonth() + 1; 
 | 
                var day = today.getDate(); 
 | 
                return year + "-" + month + "-" + day + ' 00:00:00'; 
 | 
            }, 
 | 
            // 对比时间 
 | 
            compareDates(date1, date2) { 
 | 
                if (new Date(date1).getTime() > new Date(date2).getTime()) { 
 | 
                    return 1 
 | 
                } else if (new Date(date1).getTime() < new Date(date2).getTime()) { 
 | 
                    return 2 
 | 
                } else { 
 | 
                    return 3 
 | 
                } 
 | 
            }, 
 | 
            // 获取当前时间 
 | 
            getDate() { 
 | 
                let currentDate = new Date(); 
 | 
                let year = currentDate.getFullYear(); // 获取当前年份 
 | 
                let month = currentDate.getMonth() + 1; // 获取当前月份,注意月份从0开始,所以要加1 
 | 
                let day = currentDate.getDate(); // 获取当前日期 
 | 
                return `${year}-${month}-${day}` 
 | 
            }, 
 | 
            submit() { 
 | 
                this.$refs.uForm.validate().then(res => { 
 | 
                    uni.navigateTo({ 
 | 
                        url: `/pages/addition_subtraction/addition_subtraction?id=${this.model.id}&codeId=${this.id}&cyclePrice=${this.model.cyclePrice}&startDate=${this.model.startDate}&code=${this.model.code}` 
 | 
                    }) 
 | 
                }).catch(errors => { 
 | 
                     
 | 
                }) 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
</script> 
 | 
<style> 
 | 
    page { 
 | 
        background-color: #f7f7f7; 
 | 
    } 
 | 
</style> 
 | 
<style lang="scss" scoped> 
 | 
    .box { 
 | 
        width: 100%; 
 | 
        .box_hz { 
 | 
            width: 100%; 
 | 
            height: 440rpx; 
 | 
            padding: 0 30rpx; 
 | 
            box-sizing: border-box; 
 | 
            background-repeat: no-repeat; 
 | 
            background-size: 100% 100%; 
 | 
            padding-top: 48rpx; 
 | 
            .box_hz_title { 
 | 
                font-weight: 600; 
 | 
                font-size: 48rpx; 
 | 
                color: #FFFFFF; 
 | 
                font-style: normal; 
 | 
            } 
 | 
            .box_hz_info { 
 | 
                font-weight: 400; 
 | 
                font-size: 28rpx; 
 | 
                color: #FFFFFF; 
 | 
                font-style: normal; 
 | 
                margin-top: 16rpx; 
 | 
            } 
 | 
            .box_hz_list { 
 | 
                width: 100%; 
 | 
                padding: 32rpx 30rpx; 
 | 
                box-sizing: border-box; 
 | 
                background-color: #FFFFFF; 
 | 
                margin-top: 48rpx; 
 | 
                border-radius: 16rpx; 
 | 
            } 
 | 
            .box_hz_footer { 
 | 
                width: 100%; 
 | 
                margin-top: 60rpx; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
</style> 
 |