<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :option="option"
      :data="dataList"
      v-model="form"
      :page.sync="page"
      :search.sync="search"
      @search-change="searchChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="small"
          @click.stop="newAdd()"
          >新 建</el-button
        >
      </template>
      <template slot="corpIdSearch">
        <select-component
          v-model="search.corpId"
          :configuration="configuration"
        ></select-component>
      </template>
      <template slot-scope="scope" slot="corpId">
        {{ scope.row.corpsName }}
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-view"
          size="small"
          @click.stop="beforeOpenPage(scope.row, scope.index)"
          >查看
        </el-button>
        <el-button
          type="text"
          icon="el-icon-edit"
          size="small"
          @click.stop="editOpen(scope.row, scope.index)"
          >编辑
        </el-button>
        <el-button
          type="text"
          icon="el-icon-delete"
          size="small"
          @click.stop="rowDel(scope.row, scope.index)"
          >删除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import option from "./config/mainList.json";
import { getList, remove } from "@/api/basicData/customerInquiry";
import { orderStateFormat } from "@/enums/order-stauts";

export default {
  name: "customerInformation",
  data() {
    return {
      configuration: {
        multipleChoices: false,
        multiple: false,
        collapseTags: false,
        placeholder: "请点击右边按钮选择",
        dicData: []
      },
      search: {},
      option: option,
      parentId: 0,
      dataList: [{}],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      }
    };
  },
  methods: {
    //删除列表后面的删除按钮触发触发(row, index, done)
    rowDel(row, index, done) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        remove(row.id);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        this.page.currentPage = 1;
        this.onLoad(this.page);
      });
    },
    //查看跳转页面
    beforeOpenPage(row, index) {
      this.$router.push({
        path: "/exportcustomerInquiry_detailsPage",
        query: { id: JSON.stringify(row.id) }
      });
    },
    //新增跳转页面
    beforeOpen(row) {
      console.log(row);
      this.$router.push({
        path: "/exportInvoice_detailsPage",
        query: { id: JSON.stringify(row.id) }
      });
    },
    editOpen(row) {
      this.$router.push({
        path: "/exportcustomerInquiry_detailsPage",
        query: { id: JSON.stringify(row.id) }
      });
    },
    //点击搜索按钮触发
    searchChange(params, done) {
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(val) {
      this.page.currentPage = val;
    },
    sizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
    },
    onLoad(page, params) {
      getList(page.currentPage, page.pageSize, params).then(res => {
        this.dataList = res.data.data.records ? res.data.data.records : [];
        this.page.total = res.data.data.total;
        if (this.page.total) {
          this.option.height = window.innerHeight - 380;
        } else {
          this.option.height = window.innerHeight - 305;
        }
      });
    },
    refreshChange() {
      this.onLoad(this.page, this.search);
    },
    newAdd() {
      this.$router.push({
        path: "/exportcustomerInquiry_detailsPage"
      });
    }
  }
};
</script>

<style scoped>
::v-deep .select-component {
  display: flex;
}
</style>
