<template>
    <div class="page" :class="{ 'page--iphoneX': iphoneX }">
        <div class="step">
            <uni-steps
                :options="[
                    { title: '基础设置' },
                    { title: '配送设置' },
                    { title: '积分设置' },
                ]"
                :active="0"
            ></uni-steps>
        </div>
        <div class="form-card">
            <section class="form-item dis">
                <div class="label">
                    <!-- <span class="required">*</span> -->
                    店铺名称：
                </div>
                <div class="box">
                    <input
                        type="text"
                        :disabled="true"
                        v-model="form.appName"
                        placeholder=" "
                    />
                </div>
            </section>
            <section class="form-item ">
                <div class="label">
                    <!-- <span class="required">*</span> -->
                    店长电话：
                </div>
                <div class="box">
                    <input
                        type="number"
                        v-model="form.managerTelephone"
                        placeholder=" "
                    />
                </div>
            </section>
            <section class="form-item">
                <div class="label">
                    <span class="required">*</span>
                    营业开始时间：
                </div>
                <div class="box">
                    <picker mode="time" @change="timeChange($event,'startTime')">
                    <input
                        type="text"
                        :disabled="true"
                        v-model="form.startTime"
                        placeholder="请选择"
                    />
                    </picker>
                </div>
            </section>
            <section class="form-item">
                <div class="label">
                    <span class="required">*</span>
                    营业结束时间：
                </div>
                <div class="box">
                    <picker mode="time" @change="timeChange($event,'endTime')">
                    <input
                        type="text"
                        :disabled="true"
                        v-model="form.endTime"
                        placeholder="请选择"
                    />
                    </picker>
                </div>
            </section>
            <section class="form-item">
                <div class="label">
                    <span class="required">*</span>
                    Logo：
                </div>
                <div class="box">
                    <easy-upload
                        :types="'image'"
                        v-model="mainImage"
                        :uploadCount="1"
                        :openCilp="true"
                        @change="minImgChange"
                    ></easy-upload>
                </div>
            </section>
            <section class="form-item">
                <div class="label">
                    <span class="required">*</span>
                    店铺背景：
                </div>
                <div class="box">
                    <easy-upload
                        :types="'image'"
                        v-model="mainImage2"
                        :uploadCount="1"
                        @change="minImgChange2"
                    ></easy-upload>
                </div>
            </section>
            <section class="form-item">
                <div class="label">
                    
                    店铺通知：
                </div>
                <div class="box">
                    <!-- <input
                        type="text"
                        
                    /> -->
                    <textarea v-model="form.shopNotice" :maxlength="2048" :auto-height="true"
                        placeholder="请填写店铺通知"></textarea>
                </div>
            </section>
        </div>
        <div class="btns">
            <div class="btn" @click="saveOk">下一步</div>
        </div>
    </div>
</template>

<script>
import MyImage from "../../components/image/index";
import DateTimePicker from "../../components/biaofun-datetime-picker/biaofun-datetime-picker";
import easyUpload from "../../components/easy-upload/easy-upload";
import uSteps from "../../components/uni-steps/uni-steps";

export default {
    name: "",
    components: { MyImage, DateTimePicker, easyUpload,uSteps },
    // 数据
    data() {
        return {
            form: {
                appNmae:'',
                managerTelephone:'',
                startTime:'8:00',
                endTime:'22:00',
                logo:'',
                shopBanner:'',
                shopNotice:'开通本店',
            },
            mainImage: [],
            mainImage2: [],
            mainImage3: [],
            submitLoading: false,
        };
    },

    onLoad(opts) {
        this.getData();
    },

    onShow() {},

    // 函数
    methods: {

        getData(){
            this.api.get('/Shop/GetInfo',{},{pass:true})
                .then(res=>{
                    if(res.success && res.data){
                        this.form.appName = res.data.name;
                        this.form.managerTelephone = res.data.managerTelephone;
                    }else{
                          this.fn.showModal({
                            content:res.message,
                            showCancel: false,
                        }).then(res=>{
                            if(res.confirm){
                                this.router.back();
                            }
                        })
                    }
                })
        },

        minImgChange(e) {
            this.form.logo = e[0] || '';
        },
        minImgChange2(e) {
            this.form.shopBanner = e[0] || "";
        },
        timeChange(e,name){
            let time = e.detail.value;
            this.form[name] = time;
            // console.log(e,name);
        },
        saveOk() {
            if (this.submitLoading) {
                return;
            }
            if (!this.form.managerTelephone) {
                return this.fn.showToast("请输入店长电话");
            }
            let phoneReg = /^[1][1-9][0-9]{9}$/;
            if (!phoneReg.test(this.form.managerTelephone)) {
                return this.fn.showToast("店长电话格式不正确");
            }
            if (!this.form.startTime) {
                return this.fn.showToast("请选择营业开始时间");
            }
            if (!this.form.endTime) {
                return this.fn.showToast("请选择营业结束时间");
            }
            if (!this.form.logo) {
                return this.fn.showToast("请上传logo");
            }
            if (!this.form.shopBanner) {
                return this.fn.showToast("请上传店铺背景");
            }
            // if (!this.form.iDCard) {
            //     return this.fn.showToast("请上传身份证照");
            // }
            // if (this.form.iDCard.length !== 2) {
            //     return this.fn.showToast("请分别上传身份证照正反面");
            // }
            if(this.user.parentInviteCode){
                this.form.invitedCode = this.user.parentInviteCode;
            }
            console.log(this.form);
            this.submitLoading = true;
            uni.showLoading({
                title: "提交中...",
            });
            let data = { ...this.form };
            this.api
                .post("/Shop/Open", data, { pass: true })
                .then((res) => {
                    this.submitLoading = false;
                    uni.hideLoading();
                    if (res.success) {
                        this.router.replace('/pages/guide/delivery');
                    } else {
                        this.fn.showModal({
                            content:
                                "错误码:" +
                                res.code +
                                ",错误信息:" +
                                res.message,
                            showCancel: false,
                        });
                    }
                });
        },
    },

    // 数据计算
    computed: {
        user() {
            return this.$store.state.user.user;
        },
    },

    // 数据监听
    watch: {},
};
</script>


<style lang="scss" scoped>
.page {
    padding-bottom: px(120);
    min-height: 100vh;
    background-color: #fff;
}
.page--iphoneX {
    padding-bottom: px(150);
    .btn {
        padding-bottom: px(30);
        background-color: rgb(0, 188, 38);
    }
}
.form-card {
    background-color: #fff;
    padding: 0 px(30);
    & ~ .form-card {
        margin-top: px(25);
    }
    .head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: px(140);
        background-color: #fbfbfb;
        border-bottom: 1px solid #f1f1f1;
        border-top: 1px solid #f1f1f1;
        font-size: px(44);
    }
}
.form-item {
    display: flex;
    min-height: px(140);
    padding: px(30) 0;
    box-sizing: border-box;
    align-items: center;
    font-size: px(44);
    border-top: 1px solid #f1f1f1;
    &.dis-item {
        color: #999;
        background: #f9f9f9;
    }
    .label {
        width: px(340);
        flex-shrink: 0;
        color: #999;
        margin-right: px(10);
    }
    .box {
        width: 100%;
        position: relative;
        input {
            width: 100%;
        }
    }
    .tool {
        flex-shrink: 0;
        color: #999;
        margin-left: px(10);
    }
    textarea,
    input {
        max-width: 100%;
        width: 100%;
    }
}
.list {
    // min-height: 100vh;
    // background-color: #fff;
    // border-bottom: 1px solid #f1f1f1;
    li {
        padding: px(0) px(35);
        height: px(140);
        line-height: px(140);
        font-size: px(44);
        border-top: 1px solid #f1f1f1;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .tools {
        display: flex;
        align-items: center;
        flex-shrink: 0;
        span {
            display: inline-block;
            border: 1px solid #f1f1f1;
            font-size: px(36);
            height: px(80);
            width: px(120);
            display: flex;
            justify-content: center;
            align-items: center;
            & ~ span {
                margin-left: px(30);
            }
        }
        .remove {
            color: #f00;
        }
    }
}
.btn {
    width: 100%;
    height: px(120);
    background-color: rgb(0, 188, 38);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btns {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}
.layout {
    background-color: #eee;
    color: #666;
}
.add-btn {
    height: px(120);
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: px(50) px(35) 0;
    border: 1px solid #ccc;
    border-radius: px(10);
}
.code-tool {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .scan-img {
        flex-shrink: 0;
        width: px(80);
        height: px(80);
        /deep/ img {
            width: px(80);
            height: px(80);
        }
    }
    .generate {
        color: #0097d1;
        margin-right: px(30);
        flex-shrink: 0;
    }
}
.required {
    color: #f00;
    font-size: px(44);
    &.hide {
        visibility: hidden;
    }
}
.inp-dis {
    color: #999;
}

.img-card {
    padding-top: px(30);
    padding-bottom: px(30);
}
.form-img-item {
    .tit {
        padding: px(30);
        font-size: px(44);
    }
}

.spec-list {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    li {
        width: 33.333333%;
        font-size: px(40);
        height: px(100);
        border: 1px solid #f1f1f1;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #999;
        & ~ li {
            // border-left: none;
        }
        &.on {
            color: rgb(0, 188, 38);
            border-color: rgb(0, 188, 38);
        }
    }
}
.mo-date {
    margin-top: px(20);
    border-bottom: 1px solid #f1f1f1;
    background: #fbfbfb;
    font-size: px(40);
    padding: px(10);
}
.n-date-box {
    margin-top: px(20);
    font-size: px(40);
}
.n-date {
    border-bottom: 1px solid #f1f1f1;
    background: #fbfbfb;
    padding: 0 px(20);
    display: inline-block;
    width: px(200);
    font-size: px(44);
    vertical-align: bottom;
}
.address-icon {
    /deep/ img {
        width: px(60);
        height: px(60);
    }
}
.dis{
    background-color: #f6f6f6;
}
.step {
    padding-top: px(50);
    padding-bottom: px(50);
}
</style>