<template>
    <div class="conent">
        <div class="table" style="margin-top: 10px">
            <el-table v-loading="loading" :data="tableData" style="width: 100%">
                <el-table-column prop="name" label="店铺名称"></el-table-column>
                <el-table-column prop="ship.expires_at" label="授权过期时间点"></el-table-column>
                <el-table-column prop="ship.owner_id" label="商家店铺id"></el-table-column>
                <el-table-column prop="ship.owner_name" label="商家账号名称"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="danger" v-if="scope.row.status === '未授权'" size="small">
                            <a :href="scope.row.authUrl" target="_blank" rel="noopener noreferrer">授权</a>
                        </el-button>

                        <template v-if="scope.row.status === '已授权'">
                            <el-button type="success" :disabled="true" size="small">{{ scope.row.status }}</el-button>
                        </template>
                        <template v-if="scope.row.status === '重新授权'">
                            <el-button type="danger" target="_blank" size="small">
                                <a :href="scope.row.authUrl" rel="noopener noreferrer">重新授权</a>
                            </el-button>
                        </template>

                        <el-button v-if="scope.row.ship" type="info" @click="getSenders(scope.row)"
                            size="small">发货信息</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>


        <!-- 发货信息 -->
        <el-dialog title="发货信息" :visible.sync="dialogVisible" :close-on-click-modal="false">
            <el-form ref="sendersForm" :model="sendersForm" label-width="100px">

                <template v-for="(item, index) in sendersForm.senderList" :prop="`senderList.$(index)`">
                    <div>
                        <p>发货地址 {{ index + 1 }}</p>
                        <el-form-item label="详细地址">
                            {{ item.province }} {{ item.city }} {{ item.district }} {{ item.detail }}
                        </el-form-item>

                        <el-form-item label="发货人" prop="name">
                            <el-input v-model="item.name"></el-input>
                        </el-form-item>

                        <el-form-item label="手机号" prop="mobile">
                            <el-input v-model="item.mobile"></el-input>
                        </el-form-item>

                        <el-form-item label="排序" prop="sort">
                            <el-input v-model="item.sort"></el-input>
                        </el-form-item>

                        <el-form-item label="状态">
                            <el-radio-group v-model="item.status">
                                <el-radio :label="1">启用</el-radio>
                                <el-radio :label="0">停用</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </div>
                </template>

                <el-form-item>
                    <el-button type="primary" @click="saveSenders">保存</el-button>
                    <el-button @click="dialogVisible = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { shipList, ShopSenderList, saveSenders } from "../../api/shop";
export default {
    data() {
        return {
            storeId: [],
            loading: true,
            tableData: [],
            dialogVisible: false,
            sendersForm: {
                senderList: []
            },
        };
    },
    mounted() {
        this.getShipList();
    },
    methods: {
        getShipList() {
            shipList().then((res) => {
                this.tableData = res.data.data;
            });
            this.loading = false
        },
        getSenders(row) {
            ShopSenderList(row.id, row.ship.id).then((res) => {
                this.sendersForm.senderList = res.data.data;
                this.dialogVisible = true;
            })
        },
        saveSenders() {
            saveSenders(this.sendersForm).then((res) => {
                if (200 === res.status) {
                    this.$message.success(res.data.message);
                } else {
                    this.$message.error(res.data.message);
                }
            })
        }
    },
};
</script>

<style lang="scss" scoped>
a {
    text-decoration: none;
    color: white;
}

.block {
    margin-top: 20px;
}
</style>
