<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="所属医院" prop="hospitalId">
        <el-select v-model="queryParams.hospitalId" filterable placeholder="请选择下单医院" size="small" clearable style="width: 100%">
          <el-option v-for="(v,i) in shopList" :key="i" :label="v.name" :value="v.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="退款订单号" prop="orderRefundNo">
        <el-input v-model="queryParams.orderRefundNo" placeholder="请输入退款订单号" maxlength="30" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="下单手机号" prop="userMobile">
        <el-input v-model="queryParams.userMobile" placeholder="请输入下单手机号" maxlength="11" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="服务名称" prop="serviceName">
        <el-input v-model="queryParams.serviceName" 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>
        <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="退款订单号" align="center" prop="orderRefundNo" />
      <el-table-column label="服务名称" align="center" prop="serviceName" />
      <el-table-column label="销售价格" align="center" prop="sellingPrice" />
      <el-table-column label="购买数" align="center" prop="orderNum" />
      <el-table-column label="退款数" align="center" prop="refundQuantity" />
      <el-table-column label="应付金额" align="center" prop="totalPrice" />
      <el-table-column label="应退金额" align="center" prop="refundAmount" />
      <el-table-column label="实退金额" align="center" prop="actualRefundAmount">
        <template slot-scope="scope">
          <span>{{scope.row.actualRefundAmount||'-'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="下单手机号" align="center" prop="orderVo.userMobile" />
      <el-table-column label="所属医院" align="center" prop="orderVo.hospitalName" />
      <el-table-column label="申请时间" align="center" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="refundStatus">
        <template slot-scope="{row}">
          <div v-for="(v,i) in refundStatusList" :key="i" :type="v.tag" v-if="row.refundStatus==v.code">{{v.value}}</div>
        </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 { orderRefundPage, orderRefundEnum } from '@/api/hospitalOrder.js'
import { hospitalSimpleList } from "@/api/hospital.js"
export default {
  data () {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hospitalId: undefined,
        orderRefundNo: undefined,
        userMobile: undefined,
        serviceName: undefined,
      },
      daterangeCreateTime: [],
      statusList: [
        { label: '待处理', value: 0 },
        { label: '审核通过', value: 10 },
        { label: '审核拒绝', value: 20 },
      ],
      shopList: [],
      refundStatusList: []
    }
  },
  created () {

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

    goDetails (row = {}) {
      this.$router.push({
        path: '/order/afterSaleOrderDetails',
        query: { id: row.id }
      })
    },
    getOrderRefundEnum () {
      orderRefundEnum().then(res => {
        this.refundStatusList = res.data.refundStatus;
      })
    },
    //  导出订单
    handleExport () {
      this.download('/system/businessProductRefund/export', {
        ...this.queryParams
      }, `售后订单_${new Date().getTime()}.xlsx`)
    },
    getShopList () {
      hospitalSimpleList().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["startTime"] = undefined;
      this.queryParams["endTime"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["startTime"] = this.daterangeCreateTime[0];
        this.queryParams["endTime"] = this.daterangeCreateTime[1];
      }
      orderRefundPage(this.queryParams).then(response => {
        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>