<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="searchData.checkState" class="filter-item" filterable clearable placeholder="请选择售后审核状态">
        <el-option label="全部" value="-2"></el-option>
        <el-option label="保存" value="0"></el-option>
        <el-option label="审核通过" value="1"></el-option>
        <el-option label="审核未通过" value="2"></el-option>
      </el-select>
      <el-select v-model="searchData.type" class="filter-item" filterable clearable placeholder="请选择售后类型">
          <el-option label="调换货" value="1"></el-option>
          <el-option label="退货" value="2"></el-option>
          <el-option label="部分退货" value="3"></el-option>
          <el-option label="对发货" value="4"></el-option>
          <el-option label="补发货" value="5"></el-option>
          <el-option label="补差额" value="6"></el-option>
      </el-select>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
    </div>
    <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_CheckStateSH | judgmentAfterSaleCheckState }}
        </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 label="操作" width="240" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button v-permission="'HY_after_sale_detail'" type="text" @click="btn_after_sale_detail(scope.row.F_Id)">详情</el-button>
          <el-button v-permission="'HY_edit'" v-if="authority_edit(scope.row.F_CheckStateSH)" type="text" @click="btn_edit(scope.row.F_Id)">编辑</el-button>
          <el-button v-permission="'HY_delete'" v-if="authority_delete(scope.row.F_CheckStateSH)" type="text" @click="btn_delete(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 { getAfterSaleList, deleteAfterSaleList } from "@/api/afterSaleManagement/afterSaleList";
import { pickerOptions, formatterContent } from "@/utils";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装
import addOrEdit from "./addOrEdit"
import afterSaleDetail from "./afterSaleDetail"
import detail from "@/views/orderManagement/orderList/detail"


export default {
  name: "ConsolidateOrderList",
  components: {
    Pagination
  },
  filters: {
    judgmentStateName(status) {
      const statusMap = {
        '1': '调换货',
        '2': '退货',
        '3': '部门退货',
        '4': '对发货',
        '5': '补发货',
        '6': '补差额',
      }
      return statusMap[status]
    },
    judgmentAfterSaleCheckState(status) {
      const statusMap = {
        '0': '保存',
        '1': '审核通过',
        '2': '审核未通过',
      }
      return statusMap[status]
    },
    judgmentCustodianStateName(status) {
      const statusMap = {
        '0': '未审核',
        '1': '收到货',
        '2': '货物不符',
        '3': '未收到货',
      }
      return statusMap[status]
    },
  },
  data() {
    return {
      loading: false,
      searchData: {
        checkState: '-2', //售后审核状态
        type: '', //售后类型
      },
      pickerOptions, // 日期数据
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      multipleSelection: [], // 选中的数据
      selectedId: [], // 选中的数据的id
    };
  },
  created() {
    this.getList()
    document.onkeyup = e => {
      if (e.keyCode === 13) {
        this.getList();
      }
    };
  },
  methods: {
    getList() {
      this.loading = true;
      return new Promise(resolve => {
        const params = {
          F_CheckStateSH: this.searchData.checkState, //售后审核状态
          F_Type: this.searchData.type, //售后类型
          F_State: -2, //订单状态
          F_Id: '',
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize, // int 每页几条信息
           F_PayState:'-2',
        };
        getAfterSaleList(params).then(response => {
          this.loading = false;
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.data.Totals;
            this.dataLists = response.data.Rows;
          }
        });
        resolve();
      });
    },
    //编辑详情
    btn_after_sale_detail(editId) {
      this.$layer.iframe({
        content: {
          content: afterSaleDetail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId } // props
        },
        area: ["80%", "90%"],
        title: "售后列表详情"
      });
    },
    //编辑
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId } // props
        },
        area: ["80%", "90%"],
        title: "编辑售后"
      });
    },
    btn_delete(id) {
      this.$confirm('您确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = {
          ids: id
        }
        deleteAfterSaleList(data).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    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;
    },
    authority_edit(checkStateSH) {
      if (checkStateSH == 0 || checkStateSH == 2) {
        return true
      } else {
        return false
      }
    },
    authority_delete(checkStateSH) {
      if (checkStateSH == 0 || checkStateSH == 2) {
        return true
      } else {
        return false
      }
    },
  }
};
</script>

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