<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               :search.sync="search"
               :header-cell-class-name="headerClass"
               v-model="form"
               ref="crud"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
      <template #menu="{row,index,size}">
        <el-button @click="handleDetailSearch(row,index)" type="text">查看详情</el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {getList, getDetail, add, update, remove, reject, auditing} from "@/api/leger/dynamicledger";
import {mapGetters} from "vuex";
import website from "@/config/website";
import {getToken} from "@/util/auth";

export default {
  data() {
    return {
      form: {},
      search: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height: 'auto',
        calcHeight: 210,
        searchShow: true,
        searchMenuSpan: 22,
        searchBtnText: '查询',
        emptyBtnText: '重置',
        tip: false,
        border: true,
        indexLabel: "序号",
        index: true,
        viewBtn: false,
        selection: false,
        column: [
          {
            label: "场站",
            prop: "status",
            type: "select",
            search: true,
            hide: true,
            dicUrl: "/api/daf-system/dict/dictionary?code=station",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
          },
          {
            label: "KKS编码",
            prop: "kksEncoding",
            search: true,

          },
          {
            label: "KKS描述",
            prop: "kksDescription",
          },
          {
            label: "工单",
            prop: "workOrder",
          },
          {
            label: "工作票",
            prop: "workTicket",
          },
          {
            label: "操作票",
            prop: "operation",
          },
          {
            label: "开始日期",
            prop: "startDate",
            search: true,
            hide: true,
            type: "date",
            format: 'yyyy/MM/dd',
            valueFormat: "yyyyMMdd",
          },
          {
            label: "结束日期",
            prop: "endDate",
            search: true,
            hide: true,
            type: "date",
            format: 'yyyy/MM/dd',
            valueFormat: "yyyyMMdd",
          },
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      // this.option.column = this.option.column.filter(v => {
      //     return this.permission['equipmentledger_col_' + v.prop]
      // })
      return {
        addBtn: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    handleDetailSearch(row) {
      debugger
      this.$router.push({
        path: "/leger/dynamicledgerDetail",
        query: {
          frameMode:"search",
          id: row.id,
          station: row.status,
          kksEncoding: row.kksEncoding,
          kksDescription: row.kksDescription
        },
      });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then(res => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    headerClass() {
      return 'header-class'
    }
  }
};
</script>

<style>
.header-class {
  background-color: #3366cc !important;
  color: #FFFFFF !important;
}
</style>
