<template>
  <div>
    <div class="sty">
      <el-page-header @back="goBack" content="销售返利单"> </el-page-header>
    </div>
    <el-divider></el-divider>
    <!-- 表头 -->
    <div>
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="100px"
        size="small"
        label-position="left"
      >
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="返利单号" prop="">
              <el-input
                disabled
                v-model="searchForm.rebateOrderId"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="返利日期" prop="">
              <el-input
                disabled
                v-model="searchForm.theTime"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="备注" prop="">
              <el-input
                disabled
                v-model="searchForm.remark"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="制单人" prop="">
              <el-input
                disabled
                v-model="searchForm.createBy"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="制单日期" prop="">
              <el-input
                disabled
                v-model="searchForm.createTime"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="审批人" prop="">
              <el-input
                v-if="this.searchForm.secondExamineBy != null"
                disabled
                v-model="searchForm.secondExamineBy"
                placeholder=""
              ></el-input>
              <el-input
                v-else
                disabled
                v-model="searchForm.examineBy"
                placeholder=""
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="审批日期" prop="">
              <el-input
                v-if="this.searchForm.secondExamineTime != null"
                disabled
                v-model="searchForm.secondExamineTime"
                placeholder=""
              ></el-input>
              <el-input
                v-else
                disabled
                v-model="searchForm.examineTime"
                placeholder=""
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 列表 -->
    <div class="mymain-container">
      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="dataList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
        >
          <el-table-column
            label="序号"
            align="center"
            width="100"
            type="index"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="经销商编码"
            prop="customerNumber"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="经销商名称"
            prop="customerName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="返利类型"
            prop="walletName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="返利总金额"
            prop="amount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="暂扣返利"
            prop="withholdAmount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="政策文件流水号"
            prop="policyFileNo"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="政策文号"
            prop="policyDocNo"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="政策年份"
            prop="policyYear"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="政策月份"
            prop="policyMonth"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="政策归属部门"
            prop="policyOrg"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="客户区域"
            prop="customerArea"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="客户属性"
            prop="customerAttr"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="奖励实际归属客户"
            prop="rewardActualCustomers"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="备注1"
            prop="remark1"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="备注2"
            prop="remark2"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
        </el-table>
      </div>
    </div>
    <span>返利单复核及办理折让</span>
    <el-divider></el-divider>
    <!-- 列表 -->
    <div class="mymain-container">
      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="dataList2"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
          @selection-change="selectionChangeFn"
        >
          <el-table-column
            align="center"
            type="selection"
            prop=""
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="返利单号"
            prop="rebateOrderId"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="经销商编码"
            prop="customerNumber"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="经销商名称"
            prop="customerName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="返利类型"
            prop="walletName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="总返利金额"
            prop="amount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="返利金额"
            prop="rebateAmount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="折让金额"
            prop="allowanceAmount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="暂扣返利"
            prop="withholdAmount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="折让编号"
            prop="allowanceCode"
            min-width="160"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.allowanceCode"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="折让账号"
            prop="allowanceAccount"
            min-width="160"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.allowanceAccount"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="已办理折让金额"
            prop="handledAllowanceAmount"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="折让对应收款单号"
            prop="allowanceOrderNo"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="确认人"
            prop="customerName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="确认日期"
            prop="customerConfirmTime"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="复核人"
            prop="secondExamineBy"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="复核日期"
            prop="secondExamineTime"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="diy-table-1">
      <el-row :gutter="0">
        <el-col :span="12" class="item">
          <div class="label">复核人</div>
          <div class="value">{{ this.name }}</div>
        </el-col>
        <el-col :span="12" class="item">
          <div class="label">操作</div>
          <div class="value">
            <el-radio v-model="examineStatus" label="OK">复核通过</el-radio>
            <el-radio v-model="examineStatus" label="FAIL">取消复核</el-radio>
          </div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">复核说明</div>
          <div class="value">
            <el-input v-model="examineRemark" placeholder="复核说明"></el-input>
          </div>
        </el-col>
      </el-row>
    </div>
    <br />
    <el-button type="primary" size="small" @click="btnFn">确定</el-button>
  </div>
</template>

<script>
import {
  getRebateOrderDetail,
  getRebateOrderExamine2,
} from "@/api/finance/rebate_list";
import { mapGetters } from "vuex";
export default {
  props: {
    detailId: {
      type: String,
      required: true,
    },
  },
  computed: { ...mapGetters(["name"]) },
  data() {
    return {
      examineRemark: "",
      examineStatus: "OK",
      searchForm: {
        rebateOrderId: "",
        theTime: "",
        createBy: "",
        createTime: "",
        remark: "",
      },
      dataList: [],
      dataList2: [],
      selectArr: [],
      listLoading: false, // 列表加载loading
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    //选择项发生改变
    selectionChangeFn(row) {
      console.log(row);
      this.selectArr = row;
    },
    //确定
    async btnFn() {
      if (this.selectArr.length == 0) {
        this.$message.warning("请选择复核单据");
        return;
      }
      await getRebateOrderExamine2({
        id: this.detailId,
        examineRemark: this.examineRemark,
        examineStatus: this.examineStatus,
        items: this.selectArr,
      });
      this.$emit("updateList");
      this.$message.success("复核成功");
      this.$parent.showPage = 1;
    },
    //获取详情数据
    async getDataList() {
      let res = await getRebateOrderDetail({ id: this.detailId });

      this.searchForm.rebateOrderId = res.data.id;
      this.searchForm.theTime = res.data.theTime;
      this.searchForm.createBy = res.data.createBy;
      this.searchForm.createTime = res.data.createTime;
      this.searchForm.remark = res.data.remark;
      this.searchForm.secondExamineBy = res.data.secondExamineBy;
      this.searchForm.secondExamineTime = res.data.secondExamineTime;
      this.searchForm.examineBy = res.data.examineBy;
      this.searchForm.examineTime = res.data.examineTime;
      this.dataList = res.data.items;
      this.dataList2 = res.data.items;
    },
    goBack() {
      this.$parent.showPage = 1;
    },
  },
};
</script>

<style></style>
