<template>
    <view>
        <view class="head">
            <view class="title u-line-1">{{ detail.storename || '' }}</view>
            <view class="content">
                <view class="left">
                    <view class="tag-box">
                        <view class="storetype">
                            {{ detail.storetype }}
                        </view>
                        <view class="markettype">
                            {{ detail.markettype }}
                        </view>
                    </view>
                    <view class="row">
                        <text class="iconfont icon-renyuan-hui" />
                        <text>
                            {{ detail.name }}
                        </text>
                        <text style="margin-left: 5px;">
                            {{ detail.phonenumber }}
                        </text>
                    </view>
                    <view class="row">
                        <text class="iconfont icon-dizhi-hui1" />
                        {{ getCity(detail) }}
                    </view>
                    <view class="row">
                        状态：<text style="color: #333333;">{{ detail.status }}</text>
                    </view>
                </view>
                <view class="right">
                    <u--image :src="detail.cover" :width="tovw(100)" :height="tovw(100)" radius="5">
                        <template v-slot:loading>
                            <u-loading-icon color="red"></u-loading-icon>
                        </template>
                    </u--image>
                </view>
            </view>
        </view>
        <u-tabs :scrollable="false" lineColor="#C30D23" :activeStyle="{ color: '#C30D23', fontWeight: 'bold' }" :list="tabs"
            @click="changeCurrent" :current="current" />
        <view v-show="current == 0">
            <displayCell :showList="showList" :detail="detail" />
        </view>
        <block v-if="detail.status != '审核'">
            <view style="height: 75px;" />
            <view class="footer">
                <view class="insert" :class="detail.status == '新建' ? '' : 'forbidden'"
                    @click="detail.status == '新建' ? toEdit() : ''">
                    编辑门店信息
                </view>

                <view class="invite" @click="detail.status == '新建' ? submit() : revocation()">
                    {{ detail.status == '新建' ? '提交门店信息' : '撤回' }}
                </view>
            </view>
        </block>
        <view v-else style="height: 30px;" />
    </view>
</template>

<script>
export default {
    data() {
        return {
            current: 0,
            sa_storeid: 0,
            detail: {},
            tabs: [{ name: "门店详情" }, { name: "门店人员" }],
            showList: []

        }
    },
    onLoad(options) {
        console.log(options)
        this.sa_storeid = options.id;
        this.getDetail();
        uni.setNavigationBarTitle({
            title: '门店信息'
        });
    },
    onUnload() {
        delete this.$Http.uploadStoreDetail;
    },
    methods: {
        getDetail() {
            this.$Http.basic({
                "id": "20240410095402",
                "content": {
                    "sa_storeid": this.sa_storeid
                }
            }).then(res => {
                console.log("店铺详情", res)
                if (this.cutoff(res.msg)) return;
                res.data.cover = res.data.attinfos.length ? this.getSpecifiedImage(res.data.attinfos[0], 'compressed') || uni.getStorageSync("site").logo : uni.getStorageSync("site").logo
                this.detail = res.data;
                this.showList = [{
                    label: "门店名称",
                    key: "storename"
                }, {
                    label: "面积(m²)",
                    key: "area"
                }, {
                    label: "负责人",
                    key: "name"
                }, {
                    label: "负责人电话",
                    key: "phonenumber",
                    funName: "callPhone"
                }, {
                    label: "负责人账号",
                    key: "accountno"
                }, {
                    label: "门店售前电话",
                    key: "sale_phonenmber",
                    funName: "callPhone"
                }, {
                    label: "门店售后电话",
                    key: "service_phonenmber",
                    funName: "callPhone"
                }, {
                    label: "门店类型",
                    key: 'storetype'
                }, {
                    label: "卖场类型",
                    key: "markettype"
                }, {
                    label: "门店地址",
                    value: this.getCity(res.data)
                }, {
                    label: "所属经销商",
                    key: "enterprisename"
                },]
            })
        },
        toEdit() {
            this.$Http.uploadStoreDetail = this.getDetail.bind(this);
            uni.navigateTo({
                url: "/store/insert/store?title=编辑门店信息&data=" + JSON.stringify(this.detail)
            })
        },
        submit() {
            let that = this;
            uni.showModal({
                title: '提交门店信息',
                content: '是否确定提交门店信息?',
                success: function ({ confirm }) {
                    if (confirm) that.$Http.basic({
                        "id": "20240410110302",
                        "content": {
                            "sa_storeid": that.detail.sa_storeid
                        }
                    }).then(res => {
                        console.log('提交门店信息', res)
                        if (that.cutoff(res.msg, '提交成功!')) return;
                        that.$Http.uploadStoreList && that.$Http.uploadStoreList();
                        that.getDetail();
                    })
                }
            });
        },
        revocation() {
            let that = this;
            uni.showModal({
                title: '提交门店信息',
                content: '是否确定撤回提交门店信息?',
                success: function ({ confirm }) {
                    if (confirm) that.$Http.basic({
                        "id": "20240410110802",
                        "content": {
                            "sa_storeid": that.detail.sa_storeid
                        }
                    }).then(res => {
                        console.log('撤回提交门店信息', res)
                        if (that.cutoff(res.msg, '撤回提交成功!')) return;
                        that.$Http.uploadStoreList && that.$Http.uploadStoreList();
                        that.getDetail();
                    })
                }
            });
        },
        changeCurrent({ index }) {
            this.current = index;
        }
    },

}
</script>

<style lang="scss" scoped>
.head {
    width: 100vw;
    background: #FFFFFF;
    border-radius: 8px;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 10px;

    .title {
        line-height: 24px;
        font-family: Source Han Sans SC, Source Han Sans SC;
        font-weight: bold;
        font-size: 16px;
        color: #333333;
    }

    .content {
        position: relative;

        .left {
            width: 220px;

            .tag-box {
                display: flex;

                .storetype,
                .markettype {
                    font-family: Source Han Sans SC, Source Han Sans SC;
                    font-size: 12px;
                    color: #FFFFFF;
                    height: 24px;
                    line-height: 24px;
                    padding: 0 4px;
                    border-radius: 2px;
                    margin-top: 5px;
                }

                .storetype {
                    background: #095DE0;
                }

                .markettype {
                    background: #FC9228;
                    margin-left: 5px;
                }
            }

            .row {
                line-height: 17px;
                font-family: Source Han Sans SC, Source Han Sans SC;
                font-size: 12px;
                color: #888888;
                margin-top: 5px;

                .iconfont {
                    margin-right: 5px;
                    font-size: 12px;
                }
            }
        }

        .right {
            position: absolute;
            right: 0;
            bottom: 0;
        }

    }
}


.footer {
    position: fixed;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    width: 100vw;
    height: 65px;
    background: #FFFFFF;
    box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
    padding: 5px 10px;
    box-sizing: border-box;

    .insert {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 168px;
        height: 45px;
        background: #FFFFFF;
        border-radius: 5px;
        border: 1px solid #999999;
        font-family: PingFang SC, PingFang SC;
        font-size: 16px;
        color: #666666;
        box-sizing: border-box;
    }

    .invite {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 177px;
        height: 45px;
        background: #C30D23;
        border-radius: 5px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 16px;
        color: #FFFFFF;
    }


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