<template>
    <!-- 退货 -->
    <div class="common-box">
        <el-form :model="listQuery" ref="queryForm" :inline="true">
            <el-form-item label="退货单号" prop="id">
                <el-input v-model="listQuery.id" placeholder="请输入退货单号"></el-input>
            </el-form-item>
           
            <!-- <el-form-item label="采购方" prop="orgId">
                <el-select
                    v-model="listQuery.orgId"
                    placeholder="请选择"
                    clearable
                >
                    <el-option
                        v-for="item in dd1"
                        :key="item.value"
                        :label="item.name"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item> -->
            <el-form-item label="当前状态" prop="stas">
                <el-select
                    v-model="listQuery.stas"
                    placeholder="请选择"
                    clearable
                >
                    <el-option
                        v-for="item in stasOptions"
                        :key="item.value"
                        :label="item.lable"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item>
             <el-form-item label="提交时间" prop="bb">
                <el-date-picker
                v-model="listQuery.bb"
                type="daterange"
                range-separator="至"
                :editable="false"
                value-format="yyyy-MM-dd"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="getData('search')">查询 </el-button>
                <el-button @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            v-loading="listLoading"
            element-loading-text="加载中"
            :data="list"
            fit
            stripe
            border
        >
            <template slot="empty">
                <img src="@/assets/nopage.png" alt />
                <p>暂无数据</p>
            </template>
            <el-table-column fixed type="index" label="序号" width="60"/>
            <el-table-column label="退货单号" prop="id" />
            <el-table-column label="品总数" prop="deltCnt" />
            <el-table-column label="退货总数" prop="amt" />
            <el-table-column label="退货金额" prop="orgName" />
            <el-table-column label="客户名称" prop="orgName" />
            <el-table-column label="发起人" prop="orgName" />
            <el-table-column label="发起时间" prop="orgName" />
            <el-table-column label="当前状态" prop="stas" >
                <template #default="{ row }">
                    <span v-if="row.stas == 'A'">待确认</span>
                    <span v-if="row.stas == 'B'">已确认</span>
                    <span v-if="row.stas == 'R'">已拒绝</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="100">
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        @click="handleDetail(scope.row.stas)"
                        >详情</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <!--分页-->
        <yl-pagination
            v-show="total > 0"
            :total="total"
            :page.sync="listQuery.current"
            :limit.sync="listQuery.size"
            @pagination="getData"
        />
    </div>
</template>

<script>
import ylPagination from "@/components/yl-pagination";
import { getRetnOrdSplerPage } from "@/api/returnOrderAccept/index";
    export default {
        components: {
            ylPagination
        },
        data() {
            return {
                listQuery:{
                    current: 1,
                    size: 10,
                    id: "",
                    orgId: "",
                    stas: "",
                    // bb: "",
                },
                stasOptions: [
                    {value: 'A', lable: "未受理"},
                    {value: 'B', lable: "已受理"},
                    {value: 'R', lable: "被驳回"},
                    {value: 'C', lable: "已出库"},
                    {value: 'D', lable: "部分出库"},
                    {value: 'Y', lable: "已入库"},
                    {value: 'P', lable: "部分入库"}
                ],
                dd1: [
                    {value: 0, name: "采购方1"},
                    {value: 1, name: "采购方2"}
                ],
                listLoading: false,
                list: [],
                total: 0,
            }
        },
        mounted () {
            this.getData();
        },
        methods: {
            getData(type) {
                if (type == "search") {
                    this.listQuery.current = 1;
                }
                this.listLoading = true;
                getRetnOrdSplerPage(this.listQuery).then((res) => {
                    this.list = res.data.records;
                    this.total = res.data.total;
                    this.listLoading = false;
                })
                .catch((err) => {
                    this.listLoading = false;
                });
            },
            reset(){
                this.$refs.queryForm.resetFields();
                this.getData();
            },
            // 详情
            handleDetail(row){
                if(row=="a"){
                    this.$router.push('returnDetail');
                this.$router.push({
                    name: 'returnDetail',
                    query: {
                        id: row.id,
                        orgName: row.orgName,
                        amt: row.amt,
                        retnDate: row.retnDate,
                        delvDate: row.delvDate,
                        stas: row.stas,
                    }
                });
                }else{
                    this.$router.push('returncomDetail');
                this.$router.push({
                    name: 'returncomDetail',
                    query: {
                        id: row.id,
                        orgName: row.orgName,
                        amt: row.amt,
                        retnDate: row.retnDate,
                        delvDate: row.delvDate,
                        stas: row.stas,
                    }
                });
                }
                
            },
        },
    }
</script>

<style lang="scss" scoped>

</style>