<template>
  <div id="functional">
    <search-box-new
      ref="searchBox"
      :formData="formData"
      :formList="formList"
      @search="search"
      @init="init"
    />
    <table-list
      rowKey="instId"
      ref="tableList"
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      :loading="loading"
      @addClick="addClick"
    >
      <template slot="customize">
        <el-button type="warning" @click="remove"> 批量删除 </el-button>
        <el-button @click="excelPort"> Excel导出 </el-button>
      </template>
      <template slot="status" slot-scope="props">
        <div>开户名：{{ props.scope.row.bankName }}</div>
        <div>开户银行：{{ props.scope.row.bank }}</div>
        <div>收款账号：{{ props.scope.row.bankAccount }}</div>
      </template>
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="addClick(props.scope.row)"
          >修改</el-button
        ><el-button type="text" @click="del(props.scope.row)">删除</el-button>
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize.sync="formData.pageSize"
      :currentPage.sync="formData.pageNum"
      @search="search"
    />
    <dislog
      :dialogVisible.sync="dialogVisible"
      @search="search"
      :activeData="activeData"
    ></dislog>
  </div>
</template>

<script>
import { exportFn } from "@/utils/index.js";
import dislog from "./dislog.vue";
import searchBoxNew from "@/components/searchBoxNew";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  name: "Functional",
  components: { searchBoxNew, tableList, pagination, dislog },
  data() {
    return {
      loading: false,
      navText: {
        title: "供应商管理",
        index: 0,
        ch: "条",
        num: true,
        choice: true,
        addHide: false,
        custom: false,
        openCheckMore: true,
      },
      formList: [
        {
          prop: "instId",
          placeholder: "请选择供应商名称",
          scope: "topinstitutionList",
        },
      ],
      formData: {},
      tableSet: [
        {
          label: "供应商",
          prop: "instName",
          hidden: true,
        },
        {
          label: "收款账号",
          hidden: true,
          scope: "solt",
          soltName: "status",
        },
      ],
      tableData: [],
      total: 0,
      dialogVisible: false,
      activeData: {},
    };
  },
  created() {
    this.search(2);
  },
  methods: {
    addClick(data) {
      this.activeData = data || {};
      this.dialogVisible = true;
    },
    search(v) {
      this.loading = true;
      if (v === 2) {
        this.formData = {
          pageSize: 10,
          pageNum: 1,
          status: 1,
        };
        this.$nextTick(() => {
          this.$refs.tableList.clearMoreActive();
        });
      }
      if (v === 3) {
        this.$nextTick(() => {
          this.$refs.tableList.clearMoreActive();
        });
      }
      this.$api
        .topinstitutionList(this.formData)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    init() {
      this.search(2);
    },
    del(v) {
      this.$confirm("确定删除此内容？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api
            .edittopinstitutiondeleteBatch({ instIds: [v.instId] })
            .then((res) => {
              this.$message.success("删除成功");
              this.$store.commit("INSTITUTION");
              this.search(3);
            });
        })
        .catch(() => {});
    },
    excelPort() {
      let data = Object.assign({}, this.formData);
      delete data.pageNum;
      delete data.pageSize;
      this.$api.topinstitutionlistExport(data).then((res) => {
        if (res.msg) {
          exportFn(res.msg, `导出数据`);
        } else {
          this.$message.error("导出失败");
        }
      });
    },
    remove() {
      if (this.$refs.tableList.allCheckData.length === 0) {
        this.$message.warning("请勾选数据");
        return;
      }
      this.$confirm("确定批量删除选中的数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api
            .edittopinstitutiondeleteBatch({
              instIds: this.$refs.tableList.allCheckData.map((i) => i.instId),
            })
            .then(() => {
              this.$message.success("批量删除成功");
              this.$store.commit("INSTITUTION");
              this.search(3);
            });
        })
        .catch(() => {});
    },
  },
};
</script>

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