<template>
    <scTable ref="table" :apiObj="list.apiObj" :params="searchKey" @selectionChange="selectionChange" row-key="id">
        <el-table-column type="selection" width="50" fixed="left"></el-table-column>
        <el-table-column label="订单编号" prop="order_id" width="220" fixed="left">
            <template #default="scope">
                <span v-if="scope.row.order_id">{{ scope.row.order_id }}</span>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="所属代理" prop="status" width="160">
            <template #default="scope">
                <span>{{ scope.row.agent?scope.row.agent.name:'-' }}</span>
            </template>
        </el-table-column>
        <el-table-column label="所属店铺" prop="status" width="160">
            <template #default="scope">
                <span>{{ scope.row.store?scope.row.store.store_name:'-' }}</span>
            </template>
        </el-table-column>
        <el-table-column label="用户ID" prop="open_id" width="320">
            <template #default="scope">
                <span v-if="scope.row.open_id">{{ scope.row.open_id }}</span>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="商品ID" prop="out_id" width="150">
            <template #default="scope">
                <span v-if="scope.row.out_id">{{ scope.row.out_id }}</span>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="商品名称" prop="product_name" width="220">
            <template #default="scope">
                <span v-if="scope.row.product_name">{{ scope.row.product_name }}</span>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="手机号码" prop="mobile" width="120">
            <template #default="scope">
                <span v-if="scope.row.mobile">{{ scope.row.mobile }}</span>
                <span class="status-danger" v-else>未同步</span>
            </template>
        </el-table-column>
        <el-table-column label="数量" prop="count" width="100">
            <template #default="scope">
                <span>{{ scope.row.count }}件</span>
            </template>
        </el-table-column>
        <el-table-column label="订单金额" prop="order_amount" width="150">
            <template #default="scope">
                <span v-if="scope.row.order_amount">￥{{ scope.row.order_amount }}</span>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="支付金额" prop="pay_amount" width="150">
            <template #default="scope">
                <span v-if="scope.row.pay_amount">￥{{ scope.row.pay_amount }}</span>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="状态" prop="status" width="180">
            <template #default="scope">
                <div class="status-danger" v-if="scope.row.status==0"><sc-status-indicator type="danger"></sc-status-indicator> 待支付</div>
                <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==2"><sc-status-indicator type="danger"></sc-status-indicator> 待核销</div>
                <div class="status-info" v-if="scope.row.status==3"><sc-status-indicator type="info"></sc-status-indicator> 已核销</div>
                <div class="status-info" v-if="scope.row.status==4"><sc-status-indicator type="info"></sc-status-indicator> 已取消</div>
                <div class="status-info" v-if="scope.row.status==5"><sc-status-indicator type="info"></sc-status-indicator> 退款审核</div>
                <div class="status-info" v-if="scope.row.status==6"><sc-status-indicator type="info"></sc-status-indicator> 拒绝退款</div>
                <div v-if="scope.row.status==2 && scope.row.remark">{{ scope.row.remark }}</div>
            </template>
        </el-table-column>
        <el-table-column label="支付时间" prop="pay_at" width="180">
            <template #default="scope">
                <span v-if="scope.row.pay_at">{{ scope.row.pay_at }}</span>
                <span class="status-danger" v-else>-</span>
            </template>

        </el-table-column>
        <el-table-column label="退款时间" prop="refund_at" width="180">
            <template #default="scope">
                <span v-if="scope.row.refund_at">{{ scope.row.refund_at }}</span>
                <span class="status-danger" v-else>-</span>
            </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="create_at" width="180"></el-table-column>
    </scTable>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
    <addMain ref="addMain" @success="handleSuccess"></addMain>
</template>

<script>
import formMain from './form';
import addMain from "@/views/manage/components/send";
export default {
    components: {
        formMain,addMain
    },
    data(){
        return {
            list: {
                apiObj: this.$API.orderlife.list
            },
            dataSelect:[],
            dataSelectFull:[],
            searchKey:{}
        }
    },
    methods: {
        table_express(data){
            this.$confirm(`手动录入核销订单后，开启自动呼叫快递订单将转移至【待核销】列表中，未开启则转移至【待发货】中`, '提示', {
                type: 'warning'
            }).then(() => {
                this.$nextTick(() => {
                    this.$refs.addMain.open("edit").setData(data)
                })
            }).catch(() => {

            })
        },
        async table_send(data){
            var resp = await this.$API.orderlife.del.post({"id":data.id});
            if (resp.code == 0) {
                return this.$message.error(resp.msg)
            }
            this.$message.success(resp.msg)
            this.$refs.table.refresh()
        },
        table_view(data){
            this.$nextTick(() => {
                this.$refs.detailMain.open().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.formMain.open("edit").setData(row)
            })
        },
    }
}
</script>