<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="searchData.type" class="filter-item" filterable clearable placeholder="请选择售后类型">
          <el-option label="退货" value="2"></el-option>
          <el-option label="部分退货" value="3"></el-option>
          <el-option label="补差额" value="6"></el-option>
      </el-select>
      <el-select v-model="searchData.returnType" class="filter-item" filterable clearable placeholder="请选择售后原因类型">
        <el-option v-for="item in afterSaleReasonsList" :key="item.F_ValueId" :label="item.F_Value" :value="item.F_Value"></el-option>
      </el-select>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
    </div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleTabClick" >
      <el-tab-pane label="全部" name=""></el-tab-pane>
      <el-tab-pane label="已结算" name="1"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="dataLists" border stripe  @selection-change="handleSelectionChange">
      <el-table-column type="selection"></el-table-column>
      <el-table-column type="index" label="编号" align="center" fixed width="80" />
      <el-table-column prop="F_OrderId" label="订单编号" align="center" min-width="180" >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="hadndleOrderCode(scope.row.F_OrderId)">{{ scope.row.F_OrderId }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="售后类型" align="center">
        <template slot-scope="scope">
          {{ scope.row.F_Type | judgmentStateName }}
        </template>
      </el-table-column>
      <el-table-column label="售后审核类型" align="center">
        <template slot-scope="scope">
          {{ scope.row.F_CheckStateKG | judgmentCheckStateKGName }}
        </template>
      </el-table-column>
      <el-table-column label="仓库审核状态" align="center">
        <template slot-scope="scope">
          {{ scope.row.F_CheckStateKG | judgmentCustodianStateName }}
        </template>
      </el-table-column>
      <el-table-column prop="F_Money" label="变动金额" align="center" />
      <el-table-column prop="F_Remark" label="售后备注" align="center" />
      <el-table-column prop="F_AddTime" label="下单日期" align="center" />
      <el-table-column prop="F_AboutName" label="下单员工" align="center" />
      <el-table-column label="操作" width="240" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button v-permission="'HY_refund'" v-if="isrefund(scope.row.F_State)" type="text" @click="btn_refund(scope.row.F_Id)">退款</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getDictionaryValueList } from '@/api/commonAPI';
import { getAfterSaleRefundList } from "@/api/customerServiceManagement/orderListCustomerService";
import { pickerOptions, formatterContent } from "@/utils";
import refund from './refund';
import detail from "@/views/orderManagement/orderList/detail";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装

export default {
  name: "AfterSaleRefundList",
  components: {
    Pagination
  },
  filters: {
    judgmentStateName(status) {
      const statusMap = {
        '1': '调换货',
        '2': '退货',
        '3': '部门退货',
        '4': '对发货',
        '5': '补发货',
        '6': '补差额',
      }
      return statusMap[status]
    },
    judgmentCheckStateKGName(status) {
      const statusMap = {
        '0': '未审核',
        '1': '收到货',
        '2': '货物不符',
        '3': '未收到货',
      }
      return statusMap[status]
    },
    judgmentCustodianStateName(status) {
      const statusMap = {
        '1': '收到货',
        '2': '货物不符',
        '3': '未收到货',
      }
      return statusMap[status]
    },
  },
  data() {
    return {
      loading: false,
      searchData: {
        type: '', //订单类型
        id: '', //订单号
        returnType: '', //
      },
      afterSaleReasonsList: [], //售后原因类型
      activeName: "0", //标签切换首页
      pickerOptions, // 日期数据
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      multipleSelection: [], // 选中的数据
      selectedId: [], // 选中的数据的id
    };
  },
  created() {
    this.getList()
    this.getAfterSaleReasons()
    document.onkeyup = e => {
      if (e.keyCode === 13) {
        this.getList();
      }
    };
  },
  methods: {
    getList() {
      this.loading = true;
      return new Promise(resolve => {
        const params = {
          F_State: this.activeName, //订单状态
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize, // int 每页几条信息
          F_Type: this.searchData.type,
          F_ReturnType: this.searchData.returnType,
        };
        getAfterSaleRefundList(params).then(response => {
          this.loading = false;
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.data.Totals;
            this.dataLists = response.data.Rows;
          }
        });
        resolve();
      });
    },
    //售后原因类型
    getAfterSaleReasons() {
      return new Promise(resolve=>{
        const params={
          isleaf:true,
          code:'AfterSaleReasons'
        }
        getDictionaryValueList(params).then(response=>{
          if(response.state.toLowerCase() === 'success'){
            this.afterSaleReasonsList = response.data.Rows
          }
        })
      })
    },
    handleTabClick(tab, event) {
      this.getList()
    },
    //设置退款展示
    isrefund(state){
      if(state==1){
        return false
      }else{
        return true
      }
    },
    //合并订单审核
    btn_refund(auditId) {
      this.$layer.iframe({
        content: {
          content: refund, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: auditId } // props
        },
        area: ["40%", "30%"],
        title: "售后退款"
      });
    },
    btn_search() {
      this.pageParams.pageindex = 1;
      this.getList();
    },
    //订单详情
    hadndleOrderCode(ordercode){
      this.$layer.iframe({
        content: {
          content: detail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': ordercode }// props
        },
        area: ['80%', '90%'],
        title: '订单详情'
      })
    },
    //选择多个
    handleSelectionChange(val) {
      const ids = []
      this.multipleSelection = val
      for (let i=0; i<this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].id)
      }
      this.selectedPhone = ids;
    }, 
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.el{
  cursor: pointer;
}
</style>
