<template>
    <div>
      <basic-container v-show="show" class="page-crad">
        <avue-crud ref="crud" :option="option" :data="dataList" :page.sync="page" :search.sync="search"
          @search-change="searchChange" @current-change="currentChange" @size-change="sizeChange"
          @refresh-change="refreshChange" @on-load="onLoad" :table-loading="loading" @saveColumn="saveColumn"
          @resetColumn="resetColumn" :cell-style="cellStyle" @search-criteria-switch="searchCriteriaSwitch">
          <template slot-scope="{ row,index}" slot="corpId">
            <span>{{ row.corpName }}</span>
          </template>
          <template slot="corpIdSearch">
            <crop-select v-model="search.corpId" corpType="KH" :refresh="false"></crop-select>
          </template>
          <template slot-scope="{ row, index }" slot="menu">
            <el-button type="text" size="small" :disabled="row.status>0" @click.stop="rowView(row, index)">
              查看详情
            </el-button>
          </template>
        </avue-crud>
      </basic-container>
    </div>
  </template>
  
  <script>
  import { option } from "./js/optionList";
  import { getfinancingDetailsList } from "@/api/basicData/financingLedger";
  
  export default {
    name: "index",
    data() {
      return {
        show: true,
        loading: false,
        form: {},
        search: {},
        detailData: {},
        dataList: [],
        selectionList: [],
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0,
          pageSizes: [10, 50, 100, 200, 300, 400, 500]
        },
        option: {},
      };
    },
    async created() {
      this.option = await this.getColumnData(this.getColumnName(194), option);
      // this.getWorkDicts("in_section").then(res => {
      //   this.findObject(this.option.column, "inSection").dicData = res.data.data;
      //   this.$refs.crud.init();
      // });
      this.option.height = window.innerHeight - 210;
    },
    methods: {
      searchCriteriaSwitch(type) {
        if (type) {
          this.option.height = this.option.height - 46;
        } else {
          this.option.height = this.option.height + 46;
        }
        this.$refs.crud.getTableHeight();
      },
      cellStyle() {
        return "padding:0;height:40px;";
      },
      //点击搜索按钮触发
      searchChange(params, done) {
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      refreshChange() {
        this.onLoad(this.page, this.search);
      },
      newAdd() {
        this.show = false;
      },
      rowView(row) {
        this.$router.push({
          path: "/salesManagement/outStock/index",
          query: {
            generateId: row.id
          }
        });
      },
      onLoad(page, params = {}) {
        this.loading = true;
        this.dataList.forEach(item => {
          this.$refs.crud.toggleRowExpansion(item, false);
        });
        getfinancingDetailsList(
          page.currentPage,
          page.pageSize,
          Object.assign(params, this.search)
        )
          .then(res => {
            if (res.data.data.records) {
              res.data.data.records.forEach(e => {
                e.itemLoading = true;
              });
            }
            this.dataList = res.data.data.records ? res.data.data.records : [];
            this.page.total = res.data.data.total;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      editOpen(row, status) {
        this.detailData = {
          id: row.id,
          status: status
        };
        this.show = false;
      },
      currentChange(val) {
        this.page.currentPage = val;
      },
      sizeChange(val) {
        this.page.currentPage = 1;
        this.page.pageSize = val;
      },
      async saveColumn() {
        const inSave = await this.saveColumnData(
          this.getColumnName(194),
          this.option
        );
        if (inSave) {
          this.$nextTick(() => {
            this.$refs.crud.doLayout();
          });
          this.$message.success("保存成功");
          //关闭窗口
          this.$refs.crud.$refs.dialogColumn.columnBox = false;
        }
      },
      async resetColumn() {
        this.option = option;
        const inSave = await this.delColumnData(this.getColumnName(194), option);
        if (inSave) {
          this.$nextTick(() => {
            this.$refs.crud.doLayout();
          });
          this.$message.success("重置成功");
          this.$refs.crud.$refs.dialogColumn.columnBox = false;
        }
      },
      //返回列表
      backToList() {
        this.detailData = this.$options.data().detailData;
        this.show = true;
        this.onLoad(this.page, this.search);
      }
    }
  };
  </script>
  
  <style scoped>
  .page-crad ::v-deep .basic-container__card {
    height: 94.2vh;
  }
  </style>
  