<template>
    <div class="page">
        <ul class="list">
            <li class="item" @click="jump('/pages/manage/shop/set-shop')">
                <div class="name">基础设置</div>
                <my-image
                    class="arrow"
                    src="/static/common/arrows_left.png"
                ></my-image>
            </li>
            <li class="item" @click="jump('/pages/manage/shop/delivery')">
                <div class="name">配送设置</div>
                <my-image
                    class="arrow"
                    src="/static/common/arrows_left.png"
                ></my-image>
            </li>
            <li class="item" @click="jump('/pages/manage/shop/points')">
                <div class="name">积分设置</div>
                <my-image
                    class="arrow"
                    src="/static/common/arrows_left.png"
                ></my-image>
            </li>
            <li class="item">
                <div class="name">开启厂商直邮</div>
                <switch
                    :checked="switchChecked"
                    @change="switchChange"
                ></switch>
            </li>
            <li class="item-des" v-if="switchChecked">
                <div class="item">
                    <div class="name">开启日常自动播货</div>
                    <switch
                        :checked="eveningAutoBroadcastGoodsGroup"
                        @change="setEveningAutoBroadcastGoods"
                    ></switch>
                </div>
                <p class="des">
                    助理自动推荐商品链接，每次推荐2个左右商品或活动链接。大约每小时推送一次。
                </p>
            </li>
            <li class="item-des" v-if="switchChecked">
                <div class="item">
                    <div class="name">开启活动自动推荐</div>
                    <switch
                        :checked="dayAutoBroadcastGoodsGroup"
                        @change="setDayAutoBroadcastGoods"
                    ></switch>
                </div>
                <p class="des">
                    助理每天一次自动推送运营专员准备的活动素材内容，包括：文字、图片、食品、产品活动链接。每次推送消息20条左右。每天推送一次
                </p>
            </li>
        </ul>
    </div>
</template>

<script>
import MyImage from "../../../components/image/index";
export default {
    name: "",
    components: { MyImage },

    // 数据
    data() {
        return {
            curShop: {},
            switchChecked: false,
            eveningAutoBroadcastGoodsGroup: false,
            dayAutoBroadcastGoodsGroup: false,
            storeConfig: {},
        };
    },

    onLoad() {},
    async onShow() {
        this.getStoreConfig();
    },
    // 函数
    methods: {
        getStoreConfig() {
            this.api
                .get(
                    "/Store/GetStoreConfig",
                    { id: this.user.storeId },
                    { pass: true }
                )
                .then((infoRes) => {
                    this.storeConfig = infoRes.data;
                    this.switchChecked = this.storeConfig.enableYouXuan;
                    this.eveningAutoBroadcastGoodsGroup = this.storeConfig
                        .eveningAutoBroadcastGoodsGroup
                        ? true
                        : false;
                    this.dayAutoBroadcastGoodsGroup = this.storeConfig
                        .dayAutoBroadcastGoodsGroup
                        ? true
                        : false;
                });
        },

        switchChange(e) {
            let detail = e.detail.value;
            this.switchChecked = detail;
            let data = {
                enabled: detail,
            };

            this.api
                .get("/Shop/SetYouXuan", data, { pass: true })
                .then((res) => {
                    uni.hideLoading();
                    if (res.success) {
                        this.fn.showToast("设置成功");
                    } else {
                        this.switchChecked = !this.switchChecked;
                        this.fn.showModal({
                            title: "设置失败",
                            content: "错误信息:" + res.message,
                            showCancel: false,
                        });
                    }
                });
        },

        setEveningAutoBroadcastGoods(e) {
            let detail = e.detail.value;
            this.eveningAutoBroadcastGoodsGroup = detail;
            let data = {
                enabled: detail,
            };

            this.api
                .get("/Shop/setEveningAutoBroadcastGoods", data, { pass: true })
                .then((res) => {
                    uni.hideLoading();
                    if (res.success) {
                        this.fn.showToast("设置成功");
                    } else {
                        this.eveningAutoBroadcastGoodsGroup = !this
                            .eveningAutoBroadcastGoodsGroup;
                        this.fn.showModal({
                            title: "设置失败",
                            content: "错误信息:" + res.message,
                            showCancel: false,
                        });
                    }
                });
        },

        setDayAutoBroadcastGoods(e) {
            let detail = e.detail.value;
            this.dayAutoBroadcastGoodsGroup = detail;
            let data = {
                enabled: detail,
            };

            this.api
                .get("/Shop/setDayAutoBroadcastGoods", data, { pass: true })
                .then((res) => {
                    uni.hideLoading();
                    if (res.success) {
                        this.fn.showToast("设置成功");
                    } else {
                        this.dayAutoBroadcastGoodsGroup = !this
                            .dayAutoBroadcastGoodsGroup;
                        this.fn.showModal({
                            title: "设置失败",
                            content: "错误信息:" + res.message,
                            showCancel: false,
                        });
                    }
                });
        },
    },

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

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

<style lang="scss" scoped>
.page {
    min-height: 100vh;
    background-color: #fff;
}
.list {
    border-top: 1px solid #f1f1f1;
    .item {
        height: px(120);
        padding: 0 px(35);
        font-size: px(44);
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #f1f1f1;
    }
    .arrow {
        width: px(40);
        height: px(40);
        flex-shrink: 0;
        transform: rotate(180deg);
        /deep/ img {
            width: px(40);
            height: px(40);
        }
    }
}
switch {
    transform: scale(0.7);
}
.item-des{
    border-bottom: 1px solid #f1f1f1;
    .des{
        font-size: px(40);
        color: #999;
        padding: px(15) px(30) px(30);
    }
}
</style>