<template>
    <scTable ref="table" :apiObj="list.apiObj" :params="searchKey" @selectionChange="selectionChange" row-key="id">
        <el-table-column label="所属商家" prop="id" width="280" fixed="left">
            <template #default="scope">
                <div class="goods-img">
                    <div class="name" v-if="scope.row.poi">
                        <span>{{ scope.row.poi.poi_name }}</span>
                        <span class="dec">{{ scope.row.poi.poi_address }}</span>
                    </div>
                    <div v-else>-</div>
                </div>
            </template>
        </el-table-column>
        <el-table-column prop="company_name" label="企业名称" width="220" />
        <el-table-column label="状态" prop="enable" width="120" align="center">
            <template #default="scope">
                <div class="status-success" v-if="scope.row.status==1"><sc-status-indicator type="success"></sc-status-indicator> 已完成</div>
                <div class="status-danger" v-if="scope.row.status==0"><sc-status-indicator type="danger"></sc-status-indicator> 待审核</div>
                <div v-if="scope.row.status==2">
                    <el-popover :width="300" trigger="hover" placement="top-start" title="驳回原因">
                        <template #reference>
                            <div class="status-danger" v-if="scope.row.status==2"><sc-status-indicator type="danger"></sc-status-indicator> 审核驳回 <el-icon><el-icon-question-filled /></el-icon></div>
                        </template>
                        <div v-html="scope.row.remark"></div>
                    </el-popover>
                </div>
            </template>
        </el-table-column>
        <el-table-column prop="company_number" label="统一社会信用码" width="220" />
        <el-table-column prop="city_name" label="所在省市区" width="220" />
        <el-table-column prop="legal_name" label="法人姓名" width="150" />
        <el-table-column prop="legal_mobile" label="法人手机号" width="150" />
        <el-table-column prop="bank_number" label="对公帐号" width="150" />
        <el-table-column prop="bank_code" label="开户行编码" width="120" />
        <el-table-column prop="create_at" label="进件时间" width="150" />
        <el-table-column label="操作" width="160" align="right" fixed="right">
            <template #default="scope">
                <el-button-group>
                    <el-button type="success" text size="small" @click="submitYes(scope.row)" v-if="scope.row.status == 0">通过</el-button>
                    <el-button type="warning" text size="small" @click="submitNo(scope.row)" v-if="scope.row.status == 0">驳回</el-button>
                </el-button-group>
                <el-button-group>
                    <el-button size="small" text @click="table_view(scope.row)">查看详情</el-button>
                </el-button-group>
            </template>
        </el-table-column>
    </scTable>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
</template>

<script>
import formMain from './form'
export default {
    components: {
        formMain
    },
    data(){
        return {
            list: {
                apiObj: this.$API.finance.openList
            },
            dataSelect:[],
            dataSelectFull:[],
            searchKey:{}
        }
    },
    
    methods: {
        async submitYes(){
            this.$confirm(`通过审核后，该商家无需再次提交，后续开户流程将由管理员进行补充完成，确定吗`, '提示', {
                type: 'warning'
            }).then(async ()=>{
                var resp = await this.$API.shop.del.post({"id":data.id});
                if (resp.code == 0) {
                    return this.$message.error(resp.msg);
                }
                this.$message.success(resp.msg);
                this.$emit("success");
            }).catch(()=>{})
        },
        table_view(data){
            this.$nextTick(() => {
                this.$refs.formMain.open("edit").setData(data)
            })
        },
        table_auth(data){
            this.$nextTick(() => {
                this.$refs.comboMain.open("edit").setData(data)
            })
        },
        refresh(){
            this.$refs.table.refresh()
        },
        upData(data){
            this.$refs.table.upData(data)
        },
        handleSuccess(){
            this.$refs.table.refresh()
        },
        sortChange(event){
            if (event.order) {
                var data = {
                    "field":event.prop,
                    "order":event.order
                }
                this.$refs.table.upData(data)
            } else {
                this.$refs.table.reload(this.searchKey)
            }
            return ;
        },
        selectionChange(event){
            this.dataSelect = [];
            var arr = [];
            var arrCompany = [];
            event.forEach(function(val,index){
                arr[index] = val.id;
                arrCompany[index] = val;
            });
            this.dataSelectFull = arrCompany;
            this.dataSelect = arr;
            this.$emit("success",this.dataSelect);
            this.$emit("successFull",this.dataSelectFull);
        },
        table_passwd(row){
            this.$nextTick(() => {
                this.$refs.userPasswd.open("edit").setData(row)
            })
        }
    }
}
</script>

<style>
.goods-img{display: flex;gap: 5px;}
.goods-img .name span{display: block;}
.goods-img .name span.dec{color: #999;font-size: 12px;}
.goods-price,.price{display: flex;align-items: center;gap: 5px;font-size: 14px;}
.goods-price .del{text-decoration: line-through;}
.goods-price span{background-color: #fff !important;
    border: 1px solid #d3d9e0 !important;
    border-radius: 4px;
    box-sizing: border-box;
    color: #6c737a !important;
    display: inline-flex;
    flex: none;
    font-size: 12px;
    line-height: 18px !important;
    padding: 1px 6px !important;text-decoration: none;}
</style>