<template>
    <view>
        <view class="price-content">
            <AForm ref="form" :form="form" @isUncomplete="isUncomplete"></AForm>
            <view style="height: 70px;" />
            
        </view>
        <view class="footer">
            <view class="add" :class="uncomplete ? 'forbidden' : ''" hover-class="navigator-hover"
                @click="uncomplete || loading ? '' : submit()">
                <u-loading-icon v-if="loading" />
                <block v-else>
                    {{  '保存' }}
                </block>
            </view>
        </view>
    </view>
    
</template>

<script>
import AForm from './my_form.vue'
export default {
    components:{AForm},
    data () {
        return{
            uncomplete:true,
            loading:false,
            form: [],
            sa_storeid:uni.getStorageSync('shop').sa_storeid
        }
    },
    methods: {
        async init () {
            let from = [{
                key: "cufang_min",
                type: "text",
                inputmode:'digit',
                label: "厨房最小单价",
                isMust: true,//是否必填
                value: "",
                title:'1个厨房（6平方）',
                descript:'官方指导价199元',
            },{
                key: "cufang_max",
                type: "text",
                inputmode:'digit',
                label: "厨房最大单价",
                isMust: true,//是否必填
                value: "",
                marginBottom:10,
                paddingBottom:15,
                borderRadius:true
            },{
                key: "weiyu_min",
                type: "text",
                inputmode:'digit',
                label: "卫浴最小单价",
                isMust: true,//是否必填
                value: "",
                title:'1个卫浴（4平方）',
                descript:'官方指导价799元'
            },{
                key: "weiyu_max",
                type: "text",
                inputmode:'digit',
                label: "卫浴最大单价",
                isMust: true,//是否必填
                value: "",
                marginBottom:10,
                paddingBottom:15,
                borderRadius:true
            },{
                key: "bg_min",
                type: "text",
                inputmode:'digit',
                label: "背景墙最小单价",
                isMust: true,//是否必填
                value: "",
                paddingBottom:false,
                title:'1个背景墙（4平方）',
                descript:'官方指导价199元'
            },{
                key: "bg_max",
                type: "text",
                inputmode:'digit',
                label: "背景墙最大单价",
                isMust: true,//是否必填
                value: "",
                paddingBottom:15,
                borderRadius:true
            }]
            await this.$Http.basic({
                "id": 20240515131702,
                "content": {
                    "sa_storeid": this.sa_storeid
                }
            }).then(res => {
                for (let i = 0; i < res.data.length; i++) {
                    for (let j = 0; j < from.length; j++) {
                        if (from[j].label.indexOf(res.data[i].type) != -1) {
                            if (from[j].key.indexOf('min') != -1) {
                                from[j].value = res.data[i].min_price
                            } else {
                                from[j].value = res.data[i].max_price
                            }
                        }
                    }
                }
                console.log(res.data,'门店价');
            })


            await this.$Http.basic({
                "id": 20240515133602,
                "content": {
                }
            }).then(res => {
                for (let i = 0; i < res.data.length; i++) {
                    for (let j = 0; j < from.length; j++) {
                        if (from[j].label.indexOf(res.data[i].type) != -1) {
                            if (from[j].key.indexOf('min') != -1) {
                                from[j].descript = '官方指导价' + res.data[i].min_price + '元'
                            } else {
                                from[j].descript = '官方指导价元' + res.data[i].max_price + '元'
                            }
                        }
                    }
                }
                this.form = from
                console.log(res.data,'官方价');
                console.log(this.form,'value');
            })


        },
        isUncomplete(uncomplete,actions) {
            console.log(uncomplete,'验证');
            this.uncomplete = uncomplete;
        },
        submit() {
            this.loading = true;
            let that = this;
            this.$refs.form.submit().then(data => {
                this.$Http.basic({
                    "id": 20240515134102,
                    "content": {
                        sa_storeid:that.sa_storeid,
                        "items": [
                            {
                                "type": "厨房",
                                "min_price": data.cufang_min,
                                "max_price": data.cufang_max
                            },
                            {
                                "type": "卫浴",
                                "min_price": data.weiyu_min,
                                "max_price": data.weiyu_max
                            },
                            {
                                "type": "背景墙",
                                "min_price": data.bg_min,
                                "max_price": data.bg_max
                            }
                        ]
                    }
                }).then(async res => {
                    this.loading = false;
                    console.log("修改信息", res)
                    if (this.cutoff(res.msg)) return;
                    uni.showToast({
                        title:'修改成功'
                    })
                })
            })
        },
    },
    onLoad () {
        this.init()
        uni.setNavigationBarTitle({
            title:'装修预算改价',
        })
    }
}
</script>

<style lang="scss">
.price-content {
    padding: 10px 10px 0 10px;
    box-sizing: border-box;
}
.footer {
    position: fixed;
    bottom: 0;
    width: 100vw;
    height: 65px;
    background: #FFFFFF;
    box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
    box-sizing: border-box;
    padding: 5px 10px;
    z-index: 2;
    .add {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 45px;
        background: #C30D23;
        border-radius: 5px;
        font-family: PingFang SC, PingFang SC;
        font-size: 14px;
        color: #FFFFFF;
    }

    .forbidden {
        opacity: .6;
    }
}
</style>