<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="所属商家" prop="businessId">
        <el-select v-model="queryParams.businessId" filterable placeholder="请选择所属商家" size="small" clearable style="width: 100%">
          <el-option v-for="(v,i) in shopList" :key="i" :label="v.businessName" :value="v.businessId" />
        </el-select>
      </el-form-item>
      <el-form-item label="退款订单号" prop="refundOrderNumber">
        <el-input v-model="queryParams.refundOrderNumber" placeholder="请输入退款订单号" maxlength="30" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="下单手机号" prop="userPhone">
        <el-input v-model="queryParams.userPhone" placeholder="请输入用户手机号" maxlength="11" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商品名称" prop="businessProductName">
        <el-input v-model="queryParams.businessProductName" placeholder="请输入商品名称" maxlength="30" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="退款时间">
        <el-date-picker v-model="daterangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="refundStatus">
        <el-select v-model="queryParams.refundStatus" filterable placeholder="请选择状态" size="small" clearable style="width: 100%">
          <el-option label="待处理" :value="0" />
          <el-option label="已退款" :value="1" />
          <el-option label="退款失败" :value="2" />
          <el-option label="退款拒绝" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleExport">导出订单</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="55" label="序号" align="center">
        <template slot-scope="scope">
          <div>
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="商家ID" align="center" prop="businessId" />
      <el-table-column label="退款订单号" align="center" prop="refundOrderNumber" />
      <el-table-column label="商品名称" align="center" prop="businessProductName" />
      <el-table-column label="销售价格" align="center" prop="sellingPrice" />
      <el-table-column label="购买数" align="center" prop="buyQuantity" />
      <el-table-column label="退款数" align="center" prop="refundQuantity" />
      <el-table-column label="实付金额" align="center" prop="payAmount" />
      <el-table-column label="应退金额" align="center" prop="refundAmount" />
      <el-table-column label="下单手机号" align="center" prop="userPhone" />
      <el-table-column label="所属商家" align="center" prop="businessName" />
      <el-table-column label="申请时间" align="center" prop="refundApplyTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refundApplyTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="refundStatus">
        <template slot-scope="{row}">
          <el-tag v-if="row.refundStatus===0">待处理</el-tag>
          <el-tag type="info" v-if="row.refundStatus===1">已退款</el-tag>
          <el-tag type="danger" v-if="row.refundStatus===2">退款失败</el-tag>
          <el-tag type="warning" v-if="row.refundStatus===3">退款拒绝</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="goDetails(scope.row)">{{scope.row.refundStatus==0?'处置':'查看'}}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

  </div>
</template>

<script>
import { businessProductRefundPage } from '@/api/order.js'
import { businessList } from "@/api/shop"
export default {
  data () {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: undefined,
        relatedOrderNo: undefined,
        userPhone: undefined,
        businessProductName: undefined,
        refundStatus: undefined
      },
      daterangeCreateTime: [],
      statusList: [
        { label: '待处理', value: 0 },
        { label: '审核通过', value: 10 },
        { label: '审核拒绝', value: 20 },
      ],
      shopList: []
    }
  },
  created () {

  },
  mounted () {
    if (this.$route.query.refundStatus) {
      this.queryParams.refundStatus = Number(this.$route.query.refundStatus)
    }
    this.getShopList()
    this.getList()
  },
  methods: {

    goDetails (row = {}) {
      this.$router.push({
        path: '/order/afterSaleOrderDetails',
        query: { refundOrderId: row.refundOrderId }
      })
    },
    //  导出订单
    handleExport () {
      this.download('/system/businessProductRefund/export', {
        ...this.queryParams
      }, `售后订单_${new Date().getTime()}.xlsx`)
    },
    getShopList () {
      businessList().then(res => {
        this.shopList = res.data
      })
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 查询测试单表列表 */
    getList () {
      this.loading = true;
      this.queryParams["refundTimeStart"] = undefined;
      this.queryParams["refundTimeEnd"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["refundTimeStart"] = this.daterangeCreateTime[0];
        this.queryParams["refundTimeEnd"] = this.daterangeCreateTime[1];
      }
      businessProductRefundPage(this.queryParams).then(response => {
        // response.rows.map(v => {
        //   let arr = []
        //   v.businessProductCategoryList.map(k => {
        //     arr.push(k.categoryName)
        //   })
        //   v.businessProductCategoryText = arr.join(",")
        // })
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset () {
      this.form = {
        name: undefined,
        shelvedStatus: undefined,
        orderIndex: 1
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>

<style lang='scss' scoped>
</style>