<template>
  <div class="capitalPool 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="8" style="width: 470px">
              <el-select
                v-model="code"
                multiple
                filterable
                :size="searchSize"
                remote
                style="width: 100%"
                :multiple-limit="1"
                reserve-keyword
                placeholder="请输入公司名称"
                :remote-method="remoteMethod"
                :loading="selectLoading"
                class="setWidth"
              >
                <el-option
                  v-for="item in activeOptions"
                  :key="item.companyNo"
                  :label="item.companyName"
                  :value="item.companyNo"
                />
              </el-select>
            </el-col>
            <el-col :span="8" style="width: 282px">
              <el-input
                :size="searchSize"
                v-model="parmValue.traNo"
                placeholder="请输入资金编号"
              >
              </el-input>
            </el-col>

            <el-col :span="4" style="width: 66px" class="fr tr">
              <el-button
                :size="searchSize"
                type="primary"
                @click="searchList"
              >
                刷新
              </el-button>
            </el-col>
            <el-col :span="4" style="width: 66px" class="fr tr">
              <el-button
                type="warning"
                :size="searchSize"
                @click="restSearch"
              >
                重置
              </el-button></el-col
            >
          </el-row>
          <el-row :gutter="10">
            <el-col :span="7" style="width: 168px">
              <el-select
                style="width: 100%"
                :size="searchSize"
                v-model="parmValue.inv_status"
                clearable
                @change="
                  pageInfo.curr = 1;
                  parmValue.page = 1;
                  searchList();
                "
                placeholder="关联发票状态"
              >
                <el-option
                  v-for="item in invoiceType"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-col>
            <el-col :span="7" style="width: 168px">
              <el-select
                style="width: 100%"
                :size="searchSize"
                @change="
                  pageInfo.curr = 1;
                  parmValue.page = 1;
                  searchList();
                "
                v-model="parmValue.order_status"
                clearable
                placeholder="关联确认单状态"
              >
                <el-option
                  v-for="item in orderType"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-col>
            <el-col :span="6" style="width: 302px">
              <number-range
                :start="parmValue.total_low"
                :end="parmValue.total_up"
                :type="1"
                :width="'135px'"
                :title="'资金总额'"
                :size="searchSize"
                @numReturned="numReturned($event, 0)"
              />
            </el-col>
            <el-col :span="4" style="width: 54px" class="fr tr">
              <el-button
                type="primary"
                :size="searchSize"
                icon="el-icon-search"
                @click="searchList"
              ></el-button>
            </el-col>
          </el-row>
        </div>
      </template>
      <template #status="{ scope }">
        <el-tag
          :type="
            scope.row.status == '4'
              ? 'danger'
              : scope.row.status == '3'
              ? 'success'
              : scope.row.status == '2'
              ? ''
              : 'warning'
          "
          size="mini"
          v-text="
            (
              capitalFlowType.find((item) => item.code == scope.row.status) ||
              {}
            ).name || '--'
          "
        ></el-tag>
      </template>
      <template #inv_status="{ scope }">
        <el-tag size="mini" v-if="scope.row.inv_status == '1'" type="danger"
          >未核销</el-tag
        >
        <el-tag
          size="mini"
          v-else-if="scope.row.inv_status == '2'"
          type="warning"
          >部分核销</el-tag
        >
        <el-tag size="mini" v-else type="success">全部核销</el-tag>
      </template>
      <template #order_status="{ scope }">
        <el-tag size="mini" v-if="scope.row.order_status == '1'" type="danger"
          >未核销</el-tag
        >
        <el-tag
          size="mini"
          v-else-if="scope.row.order_status == '2'"
          type="warning"
          >部分核销</el-tag
        >
        <el-tag v-else size="mini" type="success">全部核销</el-tag>
      </template>
    </ex-table>
    <no-auth v-else></no-auth>
    <!-- 导入数据 -->
    <add-edit
      :show-model="importshowModel"
      @refresh="searchList"
      @cancel="importshowModel = false"
    />
    <add-edit1
      :id="modelId"
      :show-model="showModel"
      :is-detail="isDetail"
      :traNo="traNo"
      :exam_remark="exam_remark"
      :status="status"
      @refresh="searchList"
      @cancel="showModel = false"
    />
  </div>
</template>
<script>
import ExTable from "@/components/ExTableNew.vue";
import asyncRequest from "@/apis/service/InvoiceSales/capitalPool";
import mixinPage from "@/mixins/elPaginationHandle";
import { mapGetters } from "vuex";
import numberRange from "@/components/numberRange";
import { invoiceType, orderType, capitalFlowType } from "@/assets/js/linkType";
import resToken from "@/mixins/resToken";
export default {
  name: "capitalPool",
  mixins: [mixinPage, resToken],
  components: {
    ExTable,
    numberRange,
  },

  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "capitalPool"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      traNo: "",
      status: "",
      exam_remark: "",
      importshowModel: false,
      invoiceType: invoiceType,
      orderType: orderType,
      capitalFlowType: capitalFlowType,
      code: [],
      selectLoading: false,
      activeOptions: [],
      name: "",
      contector: "",
      loading: false,
      parmValue: {
        companyNo: "",
        total_low: "", //
        total_up: "", //
        inv_status: "", //
        order_status: "", //
        traNo: "", //
        status: "3", //
        start: "",
        end: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "traNo",
          label: "资金编号",
          width: "250px",
          fixed: "left",
        },
        {
          prop: "total_fee",
          label: "总额",
          width: "120px",
        },
        {
          prop: "companyNo",
          label: "认领企业编码",
          width: "130px",
        },
        {
          prop: "customer",
          label: "认领企业",
          "min-width": "200px",
        },
        {
          prop: "inv_fee",
          label: "发票已核销金额",
          width: "120px",
        },
        {
          prop: "inv_used",
          label: "发票处理中的金额",
          width: "120px",
        },
        {
          prop: "winv_fee",
          label: "发票未核销金额",
          width: "120px",
        },
        {
          prop: "inv_status",
          label: "发票核销状态",
          width: "110px",
          _slot_: "inv_status",
        },

        {
          prop: "order_fee",
          label: "确认单已核销金额",
          width: "120px",
        },

        {
          prop: "order_used",
          label: "确认单处理中的金额",
          width: "135px",
        },
        {
          prop: "worder_fee",
          label: "确认单未核销金额",
          width: "120px",
        },
        {
          prop: "order_status",
          label: "确认单核销状态",
          width: "110px",
          _slot_: "order_status",
        },
        {
          prop: "addtime",
          label: "认领时间",
          sortable: true,
          width: "145px",
        },
      ],
    };
  },

  mounted() {
    this.searchList();
  },
  methods: {
    restSearch() {
      this.code = [];
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        companyNo: "",
        total_low: "", //
        total_up: "", //
        inv_status: "", //
        order_status: "", //
        start: "",
        end: "",
        traNo: "", //
        status: "3", //
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      this.searchList();
    },
    numReturned(e, type) {
      if (type === 0) {
        this.parmValue.total_low = e.lower; //最小金额
        this.parmValue.total_up = e.online; //最大金额
      } else if (type === 1) {
        this.parmValue.pay_low = e.lower; //最小金额
        this.parmValue.pay_up = e.online; //最大金额
      } else {
        this.parmValue.inv_low = e.lower; //最小金额
        this.parmValue.inv_up = e.online; //最大金额
      }
    },

    // 刷新表格
    async searchList() {
      if (
        (this.parmValue.total_low !== "" && this.parmValue.total_up === "") ||
        (this.parmValue.total_low === "" && this.parmValue.total_up !== "")
      ) {
        this.$message.warning("资金总额区间有误！");
        return;
      }
      this.parmValue.companyNo = this.code.join(",");
      this.loading = true;
      const res = await asyncRequest.list(this.parmValue);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        // this.tableData.map((v1) => {
        //   v1.addtime = v1.addtime.replace(".000", "");
        //   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;
    },
    async remoteMethod(query) {
      this.selectLoading = true;
      if (query !== "") {
        this.activeOptions = [];
        const res = await asyncRequest.clist({
          page: 1,
          size: 100,
          company: query,
        });
        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>
