<template>
    <div class="page">
        <ul class="list">
            <li class="item" v-for="item of list" :key="item.platform">
                <div class="name">{{item.platformName}}</div>
                <!-- <my-image
                    class="arrow"
                    src="/static/common/arrows_left.png"
                ></my-image> -->
                <switch
                    :checked="item.enabled"
                    @change="switchChange($event,item)"
                ></switch>
            </li>
        </ul>
    </div>
</template>

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

    // 数据
    data() {
        return {
            groupData: {},
            list:[]
        };
    },

    onLoad(opts) {
        this.groupData = this.$store.state.common.groupData;
        this.getGroupPlatform();
    },
    async onShow() {},
    // 函数
    methods: {

        // 获取群平台
        getGroupPlatform(){
            this.api.get('/Group/GetGroupPlatform',{gid:this.groupData._id},{pass:true})
                .then(res=>{
                    this.list = res.data;
                })
        },

        switchChange(e,item) {
            let detail = e.detail.value;
            let data = {
                gid: this.groupData._id,
                isDisable: detail ? false : true,
            };

            this.api
                .get("/Group/EnableGroupJdPlatform", data, { pass: true })
                .then((res) => {
                    uni.hideLoading();
                    if (res.success) {
                        this.fn.showToast("设置成功");
                    } else {
                        item.switchChecked = !item.switchChecked;
                        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);
}
</style>