<template>
    <view>
        <view class="head">
            请选择门店
        </view>

        <My_listbox ref="List" @getlist="getList" bottomHeight="70">
            <view class="item" v-for="item in list" hover-class="navigator-hover" @click="selectItem(item)"
                :key="item.sa_storeid">
                <checkbox :checked="selectList.some(v => v == item.sa_storeid)" color="#3874F6"
                    style="transform:scale(0.7)" />
                <view style="flex:1">
                    <view class="title u-line-1">{{ item.storename || '' }}</view>
                    <view class="content">
                        <view class="left">
                            <view class="tag-box">
                                <view class="storetype">
                                    {{ item.storetype }}
                                </view>
                                <view class="markettype">
                                    {{ item.markettype }}
                                </view>
                            </view>
                            <view class="row">
                                <text class="iconfont icon-renyuan-hui" />
                                <text>
                                    {{ item.name }}
                                </text>
                                <text style="margin-left: 5px;">
                                    {{ item.phonenumber }}
                                </text>
                            </view>
                            <view class="row">
                                <text class="iconfont icon-dizhi-hui1" />
                                {{ getCity(item) }}
                            </view>
                            <view class="row">
                                状态：<text :style="{ color: item.color }">{{ item.status }}</text>
                            </view>
                        </view>
                        <view class="right">
                            <u--image :src="item.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>
            </view>
        </My_listbox>

        <view class="footer">
            <view class="total">
                已选：{{ selectList.length }}
            </view>
            <view class="confirm" :class="selectList.length ? '' : 'forbidden'" @click="selectList.length ? submit() : ''">
                确定
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            list: [],
            "content": {
                "where": {
                    "condition": "",
                    "storetype": "",
                    "status": "审核"
                }
            },
            selectList: [],
            results: [],
        }
    },
    onLoad(options) {
        uni.setNavigationBarTitle({
            title: options.title || '选择门店'
        });
        if (options.alreadySelecteds) {
            const alreadySelecteds = JSON.parse(options.alreadySelecteds);
            this.selectList = alreadySelecteds.value;
            this.results = alreadySelecteds.value.map((v, i) => {
                return {
                    sa_storeid: v,
                    storename: alreadySelecteds.showValue[i]
                }
            });
        }
        this.getList()
    },
    methods: {
        getList(init = false) {
            if (this.paging(this.content, init)) return;
            this.$Http.basic({
                "id": 20240410095602,
                content: this.content
            }).then(res => {
                this.$refs.List.RefreshToComplete()
                console.log("获取门店列表", res)
                if (this.cutoff(res.msg)) return;
                res.data = res.data.map(v => {
                    v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos[0], 'compressed') || uni.getStorageSync("site").logo : uni.getStorageSync("site").logo
                    switch (v.status) {
                        case '提交':
                            v.color = '#009270'
                            break;
                        case '审核':
                            v.color = '#095DE0'
                            break;
                        default:
                            v.color = '#333333'
                            break;
                    }
                    return v
                })
                this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                this.content = this.$refs.List.paging(this.content, res)
            })
        },
        selectItem(item) {
            let index = this.selectList.findIndex(v => v == item.sa_storeid);
            if (index == -1) {
                this.selectList.push(item.sa_storeid)
                this.results.push(item)
            } else {
                this.selectList.splice(index, 1);
                this.results.splice(index, 1);
            }
        },
        submit() {
            this.$Http.routeSelected({
                value: this.selectList,
                showValue: this.results.map(v => v.storename)
            })
        }
    },

}
</script>

<style lang="scss" scoped>
.head {
    line-height: 17px;
    font-family: Source Han Sans SC, Source Han Sans SC;
    font-size: 12px;
    color: #666666;
    padding: 10px;
}

.item {
    width: 100vw;
    background: #FFFFFF;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 10px;
    display: flex;
    align-items: center;

    .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;
        width: 100%;

        .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;
    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;
    display: flex;
    justify-content: space-between;

    .total {
        line-height: 45px;
        font-family: PingFang SC, PingFang SC;
        font-size: 14px;
        color: #333333;
    }

    .confirm {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 112px;
        height: 45px;
        background: #C30D23;
        border-radius: 5px;
        font-family: PingFang SC, PingFang SC;
        font-size: 14px;
        color: #FFFFFF;
    }

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