<template>
  <div class="orderRecord pagePadding">
    <ex-table
      v-loading="loading"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
      :table="table"
      :data="tableData"
      :columns="columns"
      :page="pageInfo"
      :size="size"
      @page-curr-change="handlePageChange"
      @page-size-change="handleSizeChange"
      @screen-reset="
        pageInfo.curr = 1;
        parmValue.page = 1;
        searchList();
      "
      @screen-submit="
        pageInfo.curr = 1;
        parmValue.page = 1;
        searchList();
      "
    >
      <template #table-header="{}">
        <div style="width: 100%">
          <el-row :gutter="10" style="padding: 0 0 10px 80px">
            <el-col :span="6" style="width: 460px">
              <el-select
                v-model="code"
                multiple
                filterable
                remote
                :multiple-limit="1"
                reserve-keyword
                :size="searchSize"
                style="width: 100%"
                placeholder="供应商名称搜索"
                :remote-method="remoteMethod"
                :loading="selectLoading"
                @change="selectChange"
              >
                <el-option
                  v-for="item in activeOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                />
              </el-select>
            </el-col>
            <el-col :span="6" style="width: 296px">
              <period-date-picker
                :start="parmValue.startTime"
                :end="parmValue.endTime"
                :type="1"
                :width="'132px'"
                :size="searchSize"
                @timeReturned="timeReturned($event)"
              ></period-date-picker>
            </el-col>

            <el-col
              :span="3"
              style="width: 66px; float: right; padding: 0"
              v-if="powers.some((item) => item == '002')"
            >
              <el-button
                class="fr"
                :size="searchSize"
                type="primary"
                @click="searchList"
              >
                刷新
              </el-button>
            </el-col>
            <el-col
              :span="3"
              style="width: 61px; float: right; padding: 0"
              v-if="powers.some((item) => item == '024')"
            >
              <el-button
                type="warning"
                class="fr"
                :size="searchSize"
                @click="restSearch"
              >
                重置
              </el-button>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="8" style="width: 155px">
              <el-select
                v-model="parmValue.pay_status"
                clearable
                :size="searchSize"
                placeholder="付款状态"
                @change="
                  pageInfo.curr = 1;
                  parmValue.page = 1;
                  searchList();
                "
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
            <el-col :span="8" style="width: 155px">
              <el-select
                v-model="parmValue.inv_status"
                clearable
                :size="searchSize"
                placeholder="回票状态"
                @change="
                  pageInfo.curr = 1;
                  parmValue.page = 1;
                  searchList();
                "
              >
                <el-option
                  v-for="item in dstatusOptions"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
            <el-col :span="5" style="width: 350px">
              <el-input
                clearable
                style="width: 100%"
                :size="searchSize"
                placeholder="关键字"
                v-model="input"
              >
                <el-select
                  v-model="selectK"
                  slot="prepend"
                  style="width: 100px"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in selectKlist"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click.native="searchList"
                ></el-button>
              </el-input>
            </el-col>
            <!-- <el-col :span="4" style="width: 270px">
              <el-input
                clearable
                :size="searchSize"
                placeholder="付款编码"
                v-model="parmValue.payNo"

              >
              </el-input>
            </el-col> -->
            <el-col
              :span="2"
              style="width: 66px; float: right; padding: 0"
              v-if="powers.some((item) => item == '003')"
            >
              <el-button
                class="fr"
                :size="searchSize"
                type="success"
                @click="openModal('add', '003', 0, 0, 0)"
              >
                添加
              </el-button>
            </el-col>
          </el-row>
        </div>
      </template>
      <template #dstatus="{ scope }">
        <el-tag
          :size="'mini'"
          :type="
            scope.row.dstatus == '7'
              ? 'success'
              : scope.row.dstatus == '0'
              ? 'info'
              : scope.row.dstatus == '9' || scope.row.dstatus == '2'
              ? 'danger'
              : 'warning'
          "
          v-text="
            (dstatusOptions.find((item) => item.id == scope.row.dstatus) || {})
              .label || '--'
          "
        ></el-tag>
      </template>
      <template #pay_status="{ scope }">
        <el-tag
          :size="'mini'"
          :type="
            scope.row.pay_status == '4'
              ? 'success'
              : scope.row.pay_status == '0'
              ? 'info'
              : scope.row.pay_status == '5' || scope.row.pay_status == '6'
              ? 'danger'
              : 'warning'
          "
          v-text="
            (options.find((item) => item.id == scope.row.pay_status) || {})
              .label || '--'
          "
        ></el-tag>
      </template>
      <template #operation="{ scope }">
        <!-- :hide-on-click="false" -->
        <el-dropdown trigger="click">
          <span class="el-dropdown-link">
            更多操作<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown" style="min-width: 130px">
            <el-dropdown-item
              v-if="powers.some((item) => item == '007')"
              @click.native="
                openModal(
                  scope.row.sid,
                  '007',
                  scope.row.dstatus,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >查看详情</span
              ></el-dropdown-item
            >

            <el-dropdown-item
              v-if="
                (powers.some((item) => item == '005') &&
                  scope.row.pay_stages === '1' &&
                  scope.row.dstatus === '0') ||
                (powers.some((item) => item == '005') &&
                  scope.row.pay_stages === '1' &&
                  scope.row.dstatus === '2')
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '005',
                  scope.row.dstatus,
                  scope.row.payNo,
                  scope.row.companyNo,
                  scope.row.pay_status,
                  scope.row.aremark
                )
              "
              ><span style="text-align: center; display: block"
                >修改申请</span
              ></el-dropdown-item
            >

            <el-dropdown-item
              v-if="powers.some((item) => item == '027') && scope.row.delType"
              @click.native="changeStatus(scope.row.payNo)"
              ><span style="text-align: center; display: block"
                >取消申请</span
              ></el-dropdown-item
            >
            <el-divider class="my-el-divider" v-if="scope.row.ptype"
              >付款</el-divider
            >
            <el-dropdown-item
              v-if="
                (powers.some((item) => item == '030') &&
                  scope.row.pay_status === '0') ||
                (powers.some((item) => item == '030') &&
                  scope.row.pay_status === '5') ||
                (powers.some((item) => item == '030') &&
                  scope.row.pay_status === '6')
              "
              @click.native="ApplyExamPay(scope.row.sid)"
              ><span style="text-align: center; display: block"
                >发起审核流程</span
              ></el-dropdown-item
            >
            <el-dropdown-item
              v-if="
                powers.some((item) => item == '043') &&
                scope.row.pay_status === '1'
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '043',
                  scope.row.pay_status,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >业务审核</span
              ></el-dropdown-item
            >
            <el-dropdown-item
              v-if="
                powers.some((item) => item == '044') &&
                scope.row.pay_status === '2'
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '044',
                  scope.row.pay_status,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >财务审核</span
              ></el-dropdown-item
            >
            <el-dropdown-item
              v-if="
                powers.some((item) => item == '033') &&
                scope.row.pay_status === '3'
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '033',
                  scope.row.pay_status,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >付款回执</span
              ></el-dropdown-item
            >
            <el-divider class="my-el-divider" v-if="scope.row.dtype"
              >回票</el-divider
            >
            <el-dropdown-item
              v-if="
                (powers.some((item) => item == '030') &&
                  scope.row.dstatus === '0') ||
                (powers.some((item) => item == '030') &&
                  scope.row.dstatus === '2')
              "
              @click.native="ApplyPay(scope.row.payNo, scope.row.sid)"
              ><span style="text-align: center; display: block"
                >发起审核流程</span
              ></el-dropdown-item
            >
            <el-dropdown-item
              v-if="
                powers.some((item) => item == '045') &&
                scope.row.dstatus === '1'
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '045',
                  scope.row.dstatus,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >业务审核</span
              ></el-dropdown-item
            >
            <el-dropdown-item
              v-if="
                (powers.some((item) => item == '031') &&
                  scope.row.dstatus === '3') ||
                (powers.some((item) => item == '031') &&
                  scope.row.dstatus === '9')
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '031',
                  scope.row.dstatus,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
            >
              <span style="text-align: center; display: block">上传发票</span>
            </el-dropdown-item>
            <el-dropdown-item
              v-if="
                powers.some((item) => item == '032') &&
                scope.row.dstatus === '5'
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '032',
                  scope.row.dstatus,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >校验结果</span
              ></el-dropdown-item
            >
            <el-dropdown-item
              v-if="
                powers.some((item) => item == '035') &&
                scope.row.dstatus === '6'
              "
              @click.native="
                openModal(
                  scope.row.sid,
                  '035',
                  scope.row.dstatus,
                  scope.row.payNo,
                  scope.row.companyNo
                )
              "
              ><span style="text-align: center; display: block"
                >审核发票</span
              ></el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </template>
    </ex-table>
    <no-auth v-else></no-auth>
    <!-- 新建/编辑/查看 -->
    <add-edit1
      v-if="isDetail === '003' || isDetail === '005' || isDetail === '007'"
      :id="modelId"
      :payNo="payNo"
      :show-model="showModel1"
      :is-detail="isDetail"
      :pay_status="pay_status"
      :remark="remark"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 业务审核 -->
    <add-edit-2
      :id="modelId"
      :payNo="payNo"
      :show-model="showModel2"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 财务反馈信息 -->
    <add-edit-3
      :id="modelId"
      :payNo="payNo"
      :show-model="showModel3"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 上传发票/发票识别驳回 -->
    <add-edit-4
      :id="modelId"
      :payNo="payNo"
      :show-model="showModel4"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 发票结果校验 -->
    <add-edit-5
      :id="modelId"
      :payNo="payNo"
      :companyNo="companyNo"
      :show-model="showModel5"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 人工审核发票 -->
    <add-edit-6
      :id="modelId"
      :payNo="payNo"
      :companyNo="companyNo"
      :show-model="showModel6"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 付款业务审核-->
    <add-edit-21
      :id="modelId"
      :payNo="payNo"
      :companyNo="companyNo"
      :show-model="showModel21"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
    <!-- 付款财务审核-->
    <add-edit-22
      :id="modelId"
      :payNo="payNo"
      :companyNo="companyNo"
      :show-model="showModel22"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />

    <!-- 付款回执-->
    <add-edit-23
      :id="modelId"
      :payNo="payNo"
      :companyNo="companyNo"
      :show-model="showModel23"
      :is-detail="isDetail"
      @refresh="searchList"
      :dstatus="dstatus"
      @cancel="cancel"
    />
  </div>
</template>
<script>
import ExTable from "@/components/ExTableNew.vue";

import asyncRequest from "@/apis/service/purchase/orderRecord";
import statusList from "@/assets/js/statusList";
import roleLevel from "@/assets/js/roleLevel";
import mixinPage from "@/mixins/elPaginationHandle";
import PeriodDatePicker from "@/components/PeriodDatePicker";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import addEdit1 from "./components/addEdit1"; //新建/编辑/查看
import addEdit2 from "./components/addEdit2"; //业务审核
import addEdit3 from "./components/addEdit3"; //财务反馈信息
import addEdit4 from "./components/addEdit4"; //上传发票/发票识别驳回
import addEdit5 from "./components/addEdit5"; //发票结果校验
import addEdit6 from "./components/addEdit6"; //人工审核发票
import addEdit21 from "./components/addEdit21"; //付款业务审核
import addEdit22 from "./components/addEdit22"; //付款财务审核
import addEdit23 from "./components/addEdit23"; //付款回执
import AddEdit4 from "@/views/InvoiceSales/invoiceApply/addEdit4.vue";
export default {
  name: "orderRecord",
  mixins: [mixinPage, resToken],
  components: {
    ExTable,
    PeriodDatePicker,
    addEdit1, //新建/编辑/查看
    addEdit2, //业务审核
    addEdit3, //财务反馈信息
    addEdit4, //上传发票/发票识别驳回
    addEdit5, //发票结果校验
    addEdit6, //人工审核发票
    addEdit21, //付款业务审核
    addEdit22, //付款财务审核
    addEdit23,
    AddEdit4, //付款回执
  },
  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "orderRecord"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      selectK: "1",
      input: "",
      selectKlist: [
        {
          code: "1",
          name: "付款编码",
        },
        {
          code: "2",
          name: "申请人",
        },
      ],
      code: [],
      // 状态
      dstatusOptions: [
        { id: "0", label: "待提交申请" },
        { id: "1", label: "待业务审核" },
        { id: "2", label: "业务审核驳回" },
        { id: "3", label: "待上传发票" },
        { id: "4", label: "待识别发票" },
        { id: "5", label: "待校验结果" },
        { id: "6", label: "待审核发票" },
        { id: "7", label: "回票已完成" },
        // { id: "8", label: "回票已完成" },
        { id: "9", label: "识别未成功" },
      ],
      options: [
        { id: "0", label: "待提交申请" },
        { id: "1", label: "待业务审核" },
        { id: "2", label: "待财务审核" },
        { id: "3", label: "待付款回执" },
        { id: "4", label: "付款已成功" },
        // { id: "5", label: "业务审核驳回" },
        // { id: "6", label: "财务审核驳回" },
      ],
      payNo: 0,
      formValue: {
        name: "", // 账户
        page: 1, // 页码
        size: 20, // 每页显示条数
      },
      activeOptions: [],
      selectLoading: false,
      statusList: statusList,
      roleLevel: roleLevel,
      loading: true,
      companyNo: "0",
      showModel1: false, //新建/编辑/查看
      showModel2: false, //业务审核
      showModel3: false, //财务反馈信息
      showModel4: false, //上传发票/发票识别驳回
      showModel5: false, //发票结果校验
      showModel6: false, //人工审核发票
      showModel21: false, //付款业务审核
      showModel22: false, //付款财务审核
      showModel23: false, //付款回执
      isDetail: false,
      modelId: 0,
      dstatus: 0,
      remark: "",
      pay_status: "",
      parmValue: {
        startTime: "",
        endTime: "",
        supplierNo: "", //
        apply: "",
        pay_status: "",
        inv_status: "",
        payNo: "", //
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "payNo",
          label: "付款编码",
          width: "180",
          //  fixed: "left",
        },
        {
          prop: "dzNo",
          label: "对账编码",
          width: "180px",
        },
        {
          prop: "supplierNo",
          label: "供货商编码",
          width: "140px",
        },
        {
          prop: "name",
          label: "供货商名称",
          width: "170px",
        },
        {
          prop: "contector",
          label: "联系人",
        },
        {
          prop: "createrName",
          label: "申请人",
        },
        {
          prop: "total_fee",
          label: "总货款",
          // sortable: true,
          width: "110px",
        },
        {
          prop: "pay_fee",
          label: "已付款金额",
          // sortable: true,
          width: "110px",
        },
        {
          prop: "wait_fee",
          label: "待付款金额",
          // sortable: true,
          width: "110px",
        },
        {
          prop: "inv_fee",
          label: "已回票金额",
          // sortable: true,
          width: "110px",
        },
        // {
        //   prop: "winv_fee",
        //   label: "待回票金额",
        //   sortable: true,
        //   width: "110px",
        // },
        {
          prop: "dpay_fee",
          label: "申请金额",
          // sortable: true,
          width: "100px",
        },
        {
          prop: "pay_stages",
          label: "当期期数",
           width: "70px",
        },
        // {
        //   prop: "pay_rate",
        //   label: "支付比率",
        // },

        {
          prop: "pay_status",
          label: "付款状态",
          width: "110px",
          _slot_: "pay_status",
        },
        {
          prop: "dstatus",
          label: "回票状态",
          width: "110px",
          _slot_: "dstatus",
        },
        {
          prop: "addtime",
          label: "申请时间",
          // sortable: true,
          width: "140px",
        },

        {
          prop: "",
          label: "操作",
          fixed: "right",
          // _noset_: true,
          width: "96px",
          _slot_: "operation",
        },
      ],
    };
  },
  mounted() {
    this.selectK = "1";
    this.input = "";
    this.searchList();
  },
  methods: {
    restSearch() {
      this.selectK = "1";
      this.input = "";
      this.code = [];
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        startTime: "",
        endTime: "",
        supplierNo: "", //
        payNo: "", //
        apply: "",
        pay_status: "",
        inv_status: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      this.searchList();
    },
    async timeReturned(e) {
      if (e.startTime !== "") {
        this.parmValue.startTime = e.startTime;
      } else {
        this.parmValue.startTime = "";
      }

      if (e.endTime !== "") {
        this.parmValue.endTime = e.endTime;
      } else {
        this.parmValue.endTime = "";
      }
      if (this.parmValue.startTime !== "" && this.parmValue.endTime !== "") {
        this.parmValue.page = 1;
        await this.searchList();
      }
    },
    // 新建/编辑/详情
    openModal(id, isDetail, dstatus, payNo, companyNo, pay_status, remark) {
      console.log(id, isDetail, dstatus, payNo, companyNo);
      this.modelId = id;
      this.isDetail = isDetail;
      this.dstatus = dstatus;
      this.payNo = payNo;
      this.companyNo = companyNo;
      this.pay_status = pay_status ? pay_status : "";
      this.remark = remark ? remark : "";
      console.log(companyNo);
      if (isDetail === "003") {
        this.showModel1 = true;
      } else if (isDetail === "005") {
        this.showModel1 = true;
      } else if (isDetail === "007") {
        this.showModel1 = true;
      } else if (this.isDetail === "045") {
        this.showModel2 = true;
      } else if (this.isDetail === "034") {
        this.showModel3 = true;
      } else if (this.isDetail === "031") {
        this.showModel4 = true;
      } else if (this.isDetail === "032") {
        this.showModel5 = true;
      } else if (this.isDetail === "035") {
        this.showModel6 = true;
      } else if (this.isDetail === "043") {
        this.showModel21 = true;
      } else if (this.isDetail === "044") {
        this.showModel22 = true;
      } else if (this.isDetail === "033") {
        this.showModel23 = true;
      }
    },
    cancel() {
      this.showModel1 = false; //新建/编辑/查看
      this.showModel2 = false; //业务审核
      this.showModel3 = false; //财务反馈信息
      this.showModel4 = false; //上传发票/发票识别驳回
      this.showModel5 = false; //发票结果校验
      this.showModel6 = false; //人工审核发票

      this.showModel21 = false; //付款回执
      this.showModel22 = false; //付款回执
      this.showModel23 = false; //付款回执
    },

    async selectChange() {
      // console.log(this.code);
      this.parmValue.supplierNo = this.code.join(",");
      this.formValue.page = 1;
      this.pageInfo.curr = 1;
      await this.searchList();
    },
    /**
     * 发起审核流程
     * @param {String} payNo 付款编码
     */
    async ApplyPay(payNo, sid) {
      await this.$confirm(`确定发起回票审核流程？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const model = {
            payNo: payNo,
            sid: sid,
            status: "1",
          };
          const res = await asyncRequest.again(model);
          if (res && res.code === 0) {
            this.$notify.success({
              title: "发起回票审核流程成功!",
              message: "",
            });
            this.searchList();
          } else if (res && res.code >= 100 && res.code <= 104) {
            await this.logout();
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    /**
     * 发起审核流程
     */
    async ApplyExamPay(sid) {
      await this.$confirm(`确定发起付款审核流程？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const model = {
            sid: sid,
            status: "1",
          };
          const res = await asyncRequest.paymentexam(model);
          if (res && res.code === 0) {
            this.$notify.success({
              title: "发起付款审核流程成功!",
              message: "",
            });
            this.searchList();
          } else if (res && res.code >= 100 && res.code <= 104) {
            await this.logout();
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    /**
     * 申请取消
     * @param {String} payNo 付款编码
     */
    async changeStatus(payNo) {
      await this.$confirm(`确定申请取消？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const model = {
            payNo: payNo,
            status: "0",
          };
          const res = await asyncRequest.status(model);
          if (res && res.code === 0) {
            this.$notify.success({
              title: "申请取消成功!",
              message: "",
            });
            this.searchList();
          } else if (res && res.code >= 100 && res.code <= 104) {
            await this.logout();
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },

    // 刷新表格
    async searchList() {
      if (this.parmValue.startTime !== "" && this.parmValue.endTime === "") {
        this.$message.error("结束时间不能为空！");
        return;
      }
      if (this.parmValue.startTime === "" && this.parmValue.endTime !== "") {
        this.$message.error("开始时间不能为空！");
        return;
      }
      this.loading = true;
      if (this.selectK === "1") {
        this.parmValue.payNo = this.input;
        this.parmValue.apply = "";
      } else {
        this.parmValue.payNo = "";
        this.parmValue.apply = this.input;
      }

      const res = await asyncRequest.list(this.parmValue);

      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        this.tableData.map((v1) => {
          v1.total_fee = parseFloat(v1.total_fee + "").toFixed(2);
          v1.pay_fee = parseFloat(v1.pay_fee + "").toFixed(2);
          v1.wait_fee = parseFloat(v1.wait_fee + "").toFixed(2);
          v1.dpay_fee = parseFloat(v1.dpay_fee + "").toFixed(2);
          v1.inv_fee = parseFloat(v1.inv_fee + "").toFixed(2);
          // v1.winv_fee = parseFloat(v1.winv_fee + "").toFixed(2);
          v1.dtype = this.setDtype(v1.dstatus);
          v1.ptype = this.setPtype(v1.pay_status);
          v1.delType = this.setDeltype(v1.dstatus, v1.pay_status);
          let rate = parseInt(v1.pay_stages);
          let stages = v1.pay_rate.replace("[", "").replace("]", "").split(",");
          v1.pay_rate = stages[rate - 1] + "%";
          return v1;
        });
        this.pageInfo.total = Number(res.data.count);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
    setDeltype(dtatus, ptatus) {
      let td = true;
      if (dtatus === "7" || dtatus === "8") {
        td = false;
      }
      if (ptatus === "4") {
        td = false;
      }
      return td;
    },
    setDtype(tatus) {
      let td = false;
      const dList = [
        { type: "030", tatus: ["0", "2"] },
        { type: "045", tatus: ["1"] },
        { type: "031", tatus: ["3", "9"] },
        { type: "032", tatus: ["5"] },
        { type: "035", tatus: ["6"] },
      ];
      dList.forEach((v1) => {
        let i1 = this.powers.some((item) => item == v1.type);
        if (i1) {
          v1.tatus.forEach((v2) => {
            if (v2 === tatus) {
              td = true;
            }
          });
        }
      });
      return td;
    },
    setPtype(tatus) {
      let td = false;
      const dList = [
        { type: "030", tatus: ["0", "5", "6"] },
        { type: "043", tatus: ["1"] },
        { type: "044", tatus: ["2"] },
        { type: "033", tatus: ["3"] },
      ];
      dList.forEach((v1) => {
        let i1 = this.powers.some((item) => item == v1.type);
        if (i1) {
          v1.tatus.forEach((v2) => {
            if (v2 === tatus) {
              td = true;
            }
          });
        }
      });
      return td;
    },
    async remoteMethod(query) {
      this.selectLoading = true;
      if (query !== "") {
        this.activeOptions = [];
        this.formValue.name = query;
        const res = await asyncRequest.supplierlist(this.formValue);
        if (res && res.code === 0 && res.data && res.data.list) {
          this.activeOptions = res.data.list;
        } else if (res && res.code >= 100 && res.code <= 104) {
          await this.logout();
        } else {
          this.$message.warning(res.message);
        }
      } else {
        this.activeOptions = [];
      }
      this.selectLoading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
