<template>
    <view class="bigRedEnvListBox column">
        <headers :title="page"></headers>
        <view class="bigRedEnvLImg">
            <image class="bigRedEnvLImg0" mode="aspectFit" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638796189067018810.png"/>
            <image class="bigRedEnvLImg1" mode="aspectFit" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638796189108004896.png"/>
        </view>
        <scroll-view :scroll-y="true"
        style="width: 100%;height: 1px;flex: 1;">
            <view class="bigRedEnvLCBox">
                <!-- activeDaiKQ  activeJinXZ activeChaK activeChaKJD-->
                <view class="bigRedEnvLC" v-for="(item,index) in dataList" :key="index"
                :class="[{'activeDaiKQ':item.ContractStatus==3&&(item.Status==2||item.Status==4),
                'activeJinXZ':(item.ContractStatus==2&&(item.Status==2||item.Status==4))||item.ContractStatus==1,
                'activeChaK':(item.ContractStatus==4||item.ContractStatus==5)&&(item.Status==2||item.Status==4),
                'activeChaKJD':item.Status==1||item.Status==3}]"
                @click="goWebUrl(item)">
                    <view class="bigRedEnvLCBj">
                        <view class="row items-center">
                            <view class="bigRedEnvLCLeft col">
                                <view class="bigRedEnvLCLTitle"><text>{{ item.C_ProductName }}</text></view>
                                <view v-if="item.Status!=1" class="bigRedEnvLCLTime">
                                   <!-- <template v-if="item.ContractStatus==3&&(item.Status==2||item.Status==4)&&item.C_PayDate">提交时间：{{ item.C_PayDate }}</template>-->
                                    <template v-if="item.ContractStatus==2&&(item.Status==2||item.Status==4)&&item.JieSuan">结算日期：{{ item.JieSuan }}</template>
                                    <template v-if="(item.ContractStatus==4||item.ContractStatus==5)&&(item.Status==2||item.Status==4)&&item.C_PayDate">结算时间：{{ item.C_PayDate }}</template>
                                </view>
                            </view>
                            <view class="bigRedEnvLCRight">
                                <view class="bigRedEnvLCRBox column" 
                                v-if="item.Status!=1&&item.Status!=3&&item.Status!=0"
                                @click.stop="item.ContractStatus==2&&(item.Status==2||item.Status==4)?goDetails(item,3):
                                item.ContractStatus==3&&(item.Status==2||item.Status==4)?goDetails(item,4):
                                (item.ContractStatus==4||item.ContractStatus==5)&&(item.Status==2||item.Status==4)?goDetails(item,5):''">
                                    <view class="bigRedEnvLCRTitle">- 
                                        <text>
                                            <template v-if="item.ContractStatus==3&&(item.Status==2||item.Status==4)">待开启</template>
                                            <template v-if="item.ContractStatus==2&&(item.Status==2||item.Status==4)">进行中</template>
                                            <template v-if="item.ContractStatus==1">待生效</template>
                                            <template v-if="item.ContractStatus==4&&(item.Status==2||item.Status==4)">结算中</template>
                                            <template v-if="item.ContractStatus==5&&(item.Status==2||item.Status==4)">已完成</template>
                                        </text> -</view>
                                    <view class="bigRedEnvLCRText">
                                        ¥
                                        <text>{{ item.TotalClosePrice.toFixed(2) }}</text>
                                    </view>
                                    <view class="bigRedEnvLCRTYg">预估</view>
                                </view>
                                <view v-if="item.Status==1" class="bigRedEnvLCRBut" @click.stop="goDetails(item,2)">
                                    查看进度
                                </view>
                                <view v-if="item.ContractId&&(item.Status==0||item.Status==3)" class="bigRedEnvLCRBut" @click.stop="goDetails(item,1)">
                                    重新填写
                                </view>
                                <view v-if="!item.ContractId" class="bigRedEnvLCRBut" @click.stop="goUrl(2)">
                                    立即续约
                                </view>
                            </view>   
                        </view>
                        <view class="bigRedEnvLiYou"  v-if="item.Status==3&&item.AuditContractReason">
                            驳回理由:{{ item.AuditContractReason }}
                        </view> 
                    </view>
                </view>
                <!--
                    <u-empty v-if="dataList.length == 0" text="暂无数据" mode="data" padding-top="10"></u-empty>
                -->
            </view>
        </scroll-view>
        <view class="bigRedEnvLRule" @click="goUrl(1)">
            <text>大红包规则</text>
        </view>
        <view style="height: 112rpx;"></view>
        <auth v-if="showAuth&&is_show_auth==1" @changeuserinfo="reloadUserinfo" @gbAuth="gbAuth"></auth>
    </view>
</template>
<script>
import auth from "@/components/auth/index.vue";
import headers from "@/components/header/header";
export default {
    components: {
        auth,
        headers
    },
    data() {
        return {
            page:'',
            Details: null,
            dataList: [],
            U: {},
            showAuth: false,
            is_show_auth: 0,
            b2bUser:{},
            type: 0
        }
    },
    onLoad(options) {
        if(options.type)this.type = options.type;
    },
    onShow() {
        this.U = uni.getStorageSync("mall_UserInfo");
        this.b2bUser = uni.getStorageSync("b2b_user");
        let basedata = uni.getStorageSync("basedata");
        //判断后台是否开启自动授权
        if (basedata && basedata.mall
        && basedata.mall.setting 
        && basedata.mall.setting.is_show_auth ==1) {
            this.is_show_auth = 1;
        }

        if (!this.U) {
            this.U = {
                nickName: "未登录",
                avatarUrl: "",
            };
            this.showAuth = true;
        } else if (!this.b2bUser && this.is_show_auth == 1) {
            this.U = {
                nickName: "未登录",
                avatarUrl: "",
            };
            this.showAuth = true;
        }
        if(this.type==1){
            this.getList()
        }
    },
    mounted() {
        this.getList()
    },
    methods: {
        formatAmount(value) {
            if (typeof value !== 'number') return value; // 确保是数字类型

            if (value >= 10000) {
                return (value / 10000).toFixed(1) + 'w'; // 转换为万，保留1位小数
            } else if (value >= 1000) {
                return (value / 1000).toFixed(1) + 'k'; // 转换为千，保留1位小数
            } else {
                return value.toString(); // 直接返回原值
            }
        },
        goWebUrl(item){
            return
            let url = ""
            url = `https://activity.oytour.com/html/contract/index.html?ContractId=${item.ContractId}`
            if(process.env.NODE_ENV=="development") return console.log(url,"-----url")
            if (url && url.length > 0) {
                uni.navigateTo({
                    url: "/pages/webbox/webbox?u=" + encodeURIComponent(url),
                });
            }
        },
        goDetails(item,type){
            if(item.IsSee!=1) return uni.showToast({title:'暂无查看此合同权限',icon:'none'})
            let path = '';
            if(type==1){
                path = 'signAcontract?'
            }else if(type==2){//合同进度
                path =`PaymentProgress?type=${type}&` 
            }else if(type==3){ //进行中
                path =`ActivityInProgress?` 
            }else if(type==4){ //待开启
                path =`SettableList?` 
            }else if(type==5){ //提现完成
                path =`PaymentProgress?type=3&` 
            }
            uni.navigateTo({
                url: `/pages/bigredrnvelope/${path}ContractId=${item.ContractId}`
            }) 
        },
        getList(){
            uni.showLoading({
                title: '加载中',
                mask: true
            })
            // app_customer_GetAuthenticationContractDetails
            this.apipost('app_customer_GetAuthenticationDetails',{
                CustomerInfoChildrenId: this.b2bUser.customerInfoChildrenId
            },
            res=>{
                if(res.resultCode==1){
                    this.Details = res.data;
                    this.dataList = res.data.ContractList;
                    if(this.Details.IsRenewalContract==1) this.goUrl(3)
                    if(this.Details.IsRenewalContract==2) {
                        let year = Number(res.data.ContractList[0].EndTime.slice(0,4))
                        year = year+1
                        let obj = {
                            ContractId: 0,
                            ContractStatus: 0,
                            Status: 0,
                            C_ProductName: year+'年度大红包',
                        }
                        this.dataList.unshift(obj) 
                    }
                    uni.hideLoading()
                }
                
            },err=>{
                uni.hideLoading()
            })
        },
        goUrl(type){
            // type 1 规则  2 续约  3 签约
            // /pages/bigredrnvelope/rule?IsRenewalContract=${this.Details.IsRenewalContract}
            let page_id  // 2680 签约  2681 查看  2682 续约
            if(type==1){
                if(this.Details.IsRenewalContract==1) page_id = 2680
                else if(this.Details.IsRenewalContract==2) page_id = 2682
                else page_id = 2681
            } else if(type==2||type==3){
                if(this.Details.IsRenewalContract==1) page_id = 2680
                else if(this.Details.IsRenewalContract==2) page_id = 2682
                else page_id = 2681
            }
            if(type<3){
                uni.navigateTo({
                    url: `/pages/index/index?page_id=${page_id}&hidetabs=1&hideheader=1`
                })
            }else{
                uni.redirectTo({
                    url: `/pages/index/index?page_id=${page_id}&hidetabs=1&hideheader=1`
                })
            }
        },
        reloadUserinfo() {
            const pages = getCurrentPages()
            const curPage = pages[pages.length-1]
            curPage.onLoad(curPage.options)
            curPage.onShow()
            curPage.onReady()
        },
        //关闭登录窗口
        gbAuth() {
            this.showAuth = false;
        },
    }
}
</script>
<style lang="scss" scoped>
@import url("@/asset/css/flex.css");
.bigRedEnvListBox{
    height: 100vh;
    background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638796189015251131.jpg')no-repeat;
    background-size: 100% 100%;
}
.bigRedEnvLImg{
    width: 100%;
    text-align: center;
    margin-bottom: 30rpx;
}
.bigRedEnvLImg0{
    width: 639rpx;
    height: 270rpx;
}
.bigRedEnvLImg1{
    // width: 423rpx;
    height: 60rpx;
}
.bigRedEnvLCBox{
    padding: 25rpx 31rpx 31rpx 31rpx;
}
.bigRedEnvLC{
    padding: 19rpx;
    position: relative;
    background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638796316531789257.png')no-repeat;
    background-size: 100% 100%;
    margin-bottom: 58rpx;
}
.bigRedEnvLCBj{
    padding: 35rpx 30rpx 53rpx 46rpx;
    position: relative;
    z-index: 2;
}
.bigRedEnvLC.activeChaKJD .bigRedEnvLCBj{
    padding: 40rpx 50rpx 40rpx 46rpx;
}
.bigRedEnvLCLeft{
    color: #E95E2F;
    // position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bigRedEnvLCLTitle{
    font-weight: 800;
    font-size: 48rpx;
}
.bigRedEnvLCLTime{
    font-weight: 500;
    font-size: 20rpx;
    margin-top: 10rpx;
    position: absolute;
    bottom: 20rpx;
}
.bigRedEnvLCRight{
    width: 171rpx;
    position: relative;
    margin-left: 20rpx;
}
.bigRedEnvLCRBox{
    // width: 165rpx;
    width: 179rpx;
    height: 207rpx;
    position: absolute;
    top: -109rpx;
    padding: 15rpx 19rpx 0 19rpx;
}
.bigRedEnvLiYou{
    font-size: 20rpx;
    color: #E95E2F;
    margin-top: 2rpx;
}
.bigRedEnvLC.activeDaiKQ .bigRedEnvLCRBox{
    background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638805950590594273.png')no-repeat;
    background-size: 100% 100%;
}
.bigRedEnvLC.activeJinXZ .bigRedEnvLCRBox{
    background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638805950590008259.png')no-repeat;
    background-size: 100% 100%;
}
.bigRedEnvLC.activeChaK .bigRedEnvLCRBox{
    background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638805950589978955.png')no-repeat;
    background-size: 100% 100%;
}
.bigRedEnvLCRTitle{
    font-size: 17rpx;
    text-align: center;
    font-weight: 500;
}
.bigRedEnvLCRTitle text{
    margin-left: 5rpx;
    margin-right: 5rpx;
}
.bigRedEnvLC.activeDaiKQ .bigRedEnvLCRTitle,
.bigRedEnvLC.activeChaK .bigRedEnvLCRTitle{
    color: #A4571F;
}
.bigRedEnvLC.activeJinXZ .bigRedEnvLCRTitle,.bigRedEnvLC.activeJinXZ .bigRedEnvLCRText{
    color: #fff;
}
.bigRedEnvLCRText{
    font-size: 19rpx;
    font-weight: 300;
    font-size: 18rpx;
    color: #A4571F;
    text-align: center;
    // margin-top: 5rpx;
}
.bigRedEnvLCRText text{
    font-size: 27rpx;
    font-weight: 600;
}
.bigRedEnvLCRTYg{
    font-size: 19rpx;
    font-weight: 500;
    text-align: center;
    color: #7B0C04;
}
.bigRedEnvLCRBut{
    width: 185rpx;
    line-height: 60rpx;
    background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Upload/Goods/638796304440442295.png')no-repeat;
    background-size: 100% 100%;
    color: #fff;
    font-size: 30rpx;
    font-weight: bold;
    text-align: center;
}
.bigRedEnvLRule{
    text-align: center;
}
.bigRedEnvLRule text{
    font-weight: bold;
    font-size: 28rpx;
    color: #3E67FB;
    line-height: 61rpx;
    text-decoration-line: underline;
}
</style>
