<template>
  <div class="app-container">
    <div v-if="showPage == 1">
      <el-radio-group @change="changeRadioGroupFn" v-model="category" size="">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button label="WAIT">待审核</el-radio-button>
        <el-radio-button label="OK_ONE">审核通过</el-radio-button>
        <el-radio-button label="FAIL_ONE">审核驳回</el-radio-button>
        <!-- <el-radio-button label="复核通过"></el-radio-button>
        <el-radio-button label="待复核"></el-radio-button>
        <el-radio-button label="复核驳回"></el-radio-button> -->
      </el-radio-group>
      <br /><br />
      <!-- 筛选条件 -->
      <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="id">
                <el-input
                  v-model="searchForm.id"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="返利类型" prop="walletName">
                <el-input
                  v-model="searchForm.walletName"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="申请日期" prop="startTime">
                <el-date-picker
                  class="dateStyle"
                  v-model="searchForm.startTime"
                  placeholder="选择日期"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="" class="fr">
                <el-button size="small" @click="clearFn">清空</el-button>
                <el-button size="small" type="primary" @click="searchFn"
                  >搜索</el-button
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <br />

      <strong>返利互转单列表</strong>
      <el-divider></el-divider>
      <!-- 列表 -->
      <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="id"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="申请日期"
              prop="applyTime"
              min-width="160"
              show-overflow-tooltip
            >
              <!-- <template slot-scope="scope">
                <div>
                  <span>{{ scope.row.applyTime }}</span>
                  <el-button
                    type="text"
                    icon="el-icon-edit"
                    style="padding: 0; margin-left: 6px"
                    @click="editDate(scope.row)"
                  ></el-button>
                </div>
              </template> -->
            </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="initiatorRemark"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="发起方返利类型"
              prop="initiatorCustomerWalletName"
              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="receiverCustomerNumber"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="接收方经销商名称"
              prop="receiverCustomerName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="接收方表体备注"
              prop="receiverRemark"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="接收方返利类型"
              prop="receiverCustomerWalletName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="备注"
              prop="remark"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="制单人"
              prop="createBy"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="审核人"
              prop="examineBy"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="审核日期"
              prop="examineTime"
              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-column
              align="center"
              label="状态"
              prop="examineStatus"
              min-width="160"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag v-show="scope.row.examineStatus == 'SAVE'">保存</el-tag>
                <el-tag v-show="scope.row.examineStatus == 'WAIT'"
                  >待审核</el-tag
                >
                <el-tag v-show="scope.row.examineStatus == 'OK_ONE'"
                  >初审通过</el-tag
                >
                <el-tag v-show="scope.row.examineStatus == 'FAIL_ONE'"
                  >初审不通过</el-tag
                >
                <el-tag v-show="scope.row.examineStatus == 'OK'"
                  >复核通过</el-tag
                >
                <el-tag v-show="scope.row.examineStatus == 'FALL'"
                  >不通过</el-tag
                >
                <el-tag v-show="scope.row.examineStatus == 'CLOSE'"
                  >已关闭</el-tag
                >
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="操作"
              min-width="200"
              show-overflow-tooltip
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  @click="submitFn(scope.row.id)"
                  v-if="
                    $checkBtnRole('apply', $route.meta.roles) &&
                    isCustomer &&
                    scope.row.examineStatus == 'SAVE'
                  "
                  type="text"
                  class="textColor"
                  slot="reference"
                  >提审</el-button
                >
                <el-button
                  v-if="isCustomer && scope.row.examineStatus == 'WAIT'"
                  type="text"
                  class="textColor"
                  slot="reference"
                  @click="withdrawFn"
                  >撤回</el-button
                >
                <el-button
                  v-if="
                    scope.row.examineStatus == 'WAIT' &&
                    !isCustomer &&
                    $checkBtnRole('examine', $route.meta.roles)
                  "
                  @click="examineFn(scope.row.id)"
                  type="text"
                  class="textColor"
                  slot="reference"
                  >审核</el-button
                >
                <el-button
                  v-if="
                    (scope.row.examineStatus == 'FAIL_ONE' ||
                      scope.row.examineStatus == 'SAVE') &&
                    $checkBtnRole('edit', $route.meta.roles)
                  "
                  type="text"
                  class="textColor"
                  slot="reference"
                  @click="editFn(scope.row.id)"
                  >修改</el-button
                >
                <el-button
                  @click="detailFn(scope.row.id)"
                  type="text"
                  class="textColor"
                  slot="reference"
                  >详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fr">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <ChangeListDetail :detailList="detailList" v-else-if="showPage == 2" />
    <ChangeListExamine
      @refresh="refreshFn"
      :detailList="detailList"
      v-else-if="showPage == 3"
    />
    <ChangeListReview
      @refresh="refreshFn"
      :detailList="detailList"
      v-else-if="showPage == 4"
    />
  </div>
</template>

<script>
import {
  getChangeList,
  getChangeListDetail,
  getTransferSubmit,
} from "@/api/finance/change_list";
import ChangeListDetail from "./components/change_list-detail";
import ChangeListExamine from "./components/change_list-examine";
import ChangeListReview from "./components/change_list-review";
export default {
  components: {
    ChangeListDetail,
    ChangeListExamine,
    ChangeListReview,
  },
  data() {
    return {
      isCustomer: null,
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      dataList: [], // 列表数据
      searchForm: {
        startTime: "",
        walletName: "",
        id: "",
      }, //搜索表单
      listLoading: false, // 列表加载loading
      category: "",
      showPage: 1,
      detailList: {},
    };
  },
  created() {
    const res = JSON.parse(localStorage.getItem("supply_user"));
    this.isCustomer = res.isCustomer;
    this.getDataList({ pageSize: this.pageSize, pageNum: this.currentPage });
  },
  methods: {
    //切换radio
    changeRadioGroupFn(v) {
      console.log(v);
      this.getDataList({
        pageSize: this.pageSize,
        pageNum: this.currentPage,
        examineStatus: v,
      });
    },
    //撤回
    withdrawFn() {},
    //刷新
    refreshFn() {
      this.getDataList({ pageSize: this.pageSize, pageNum: this.currentPage });
    },
    //提审
    async submitFn(id) {
      await getTransferSubmit({ id });
      this.$message.success("提审成功");
      this.getDataList({ pageSize: this.pageSize, pageNum: this.currentPage });
    },
    //清空
    clearFn() {
      console.log(this.$refs.searchForm);
      this.$refs.searchForm.resetFields();
    },
    //搜索
    searchFn() {
      this.getDataList({
        ...this.searchForm,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      });
    },

    //获取列表数据
    async getDataList(data) {
      const res = await getChangeList(data);
      console.log(res);
      this.dataList = res.data.records;
      this.listTotal = res.data.total;
    },
    //详情
    async detailFn(id) {
      const res = await getChangeListDetail({ id });
      console.log(res);
      this.detailList = res.data;
      this.showPage = 2;
    },
    //修改
    async editFn(id) {
      const res = await getChangeListDetail({ id });

      this.detailList = res.data;
      this.showPage = 4;
    },
    //审核
    async examineFn(id) {
      const res = await getChangeListDetail({ id });

      this.detailList = res.data;
      this.showPage = 3;
    },
    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.getDataList({
        pageNum: 1,
        pageSize: this.pageSize,
        examineStatus: this.category,
      });
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getDataList({
        pageNum: val,
        pageSize: 10,
        examineStatus: this.category,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.dateStyle {
  width: 100%;
}
</style>
