<template>
  <div style="display: flex">
    <div class="left" style="width: 15%;">
      <BaseMenuTree
        :menuData="treeData"
        :filterShow="true"
        :Allshow="false"
        :treeButton="false"
        :filterButtonShow="false"
        style="height: 100%"
        :treeProps="treeProps"
        @handleNodeClick="homeHandleNodeClick"
        ref="menuTree"
      ></BaseMenuTree>
    </div>
    <div class="right" style="flex: 1">
      <base-layout
        ref="baseLayout"
        :buttonList="buttonList"
        @onFuncBtn="onFuncBtn"
        :querySwitch="true"
        :searchList="requirementList"
        @search="handleSearchEvent"
        :isPage="true"
        @pageChange="handlePageChange"
      >
        <div slot="main" slot-scope="{ tableHeight }">
          <base-table
            ref="baseTable"
            :showIndex="true"
            :funWidth="180"
            :funData="funData"
            @onFunc="onFunc"
            :tabLoading.sync="tabLoading"
            :tableHeight="tableHeight"
            :tableData="tableData"
            :tableColumn="tableColumnData"
            @onCellClick="onCellClick"
          >
          </base-table>
        </div>
      </base-layout>
    </div>

    <right-dialog ref="rightDialog" @resetTable="resetTable"></right-dialog>
    <contrastRightDialog ref="contrastRightDialog" @resetTable="resetTable"></contrastRightDialog>
  </div>
</template>

<script>
import contrastRightDialog from '@/views/recordContrast/contrastRightDialog.vue'
import baseLayout from '@/components/base/baseLayout'
import baseTable from '@/components/base/baseTable'
import rightDialog from './rightDialog'
import configData from './configData'
import { authApi } from '@/api/apis/auth'
import BaseMenuTree from '@/views/intergrationTask/compoments/baseMenuTree.vue'

export default {
  components: {
    BaseMenuTree,
    baseLayout,
    baseTable,
    rightDialog,
    contrastRightDialog
  },
  data() {
    return {
      type: 1,//当前选中type
      treeProps: {
        children: 'children',
        label: 'name'
      },
      treeData: [
        {
          name: '人员对照',
          type: '1'
        },
        {
          name: '部门档案',
          type: '2'
        },
        {
          name: '存货对照',
          type: '3'
        },
        {
          name: '客商辅助核算',
          type: '4'
        },
        {
          name: '税率',
          type: '5'
        },
        {
          name: '项目辅助核算',
          type: '6'
        },
        {
          name: '银行类别',
          type: '7'
        },
        {
          name: '采购类型',//原来叫银行账户
          type: '8'
        },
        {
          name: '销售类型',//原来叫资产类别
          type: '9'
        }
      ],
      buttonList: [
        {
          menuName: '新增',
          icon: 'el-icon-plus',
          btnFunction: 'add'
        },
        {
          menuName: '刷新',
          icon: 'el-icon-refresh',
          btnFunction: 'resetLoad'
        },
        // {
        //   menuName: '档案对照',
        //   icon: 'el-icon-s-open',
        //   btnFunction: 'contrast'
        // }
      ], //按钮组
      requirementList: [
        {
          placeholder: '编码',
          prop: 'leftCode',
          tag: 'elInput'
        },
        {
          placeholder: '名称',
          prop: 'leftName',
          tag: 'elInput'
        },
        {
          placeholder: '编码',
          prop: 'rightCode',
          tag: 'elInput'
        },
        {
          placeholder: '名称',
          prop: 'rightName',
          tag: 'elInput'
        }
      ], //查询模板list
      tabLoading: false,
      tableColumnData: configData.tableColumnData, //表头数据
      funData: [

        {
          color: '#6a9af1',
          text: '编辑'
        },
        {
          color: '#d67a74',
          text: '删除'
        }
      ],
      tableData: [], //表格数据
      pageModel: {
        pageNum: 1,
        pageSize: 100
      },
      queryModel: {
        code: '',
        name: '',
        classify: '',
        productionCompany: ''
      }
    }
  },
  mounted() {
    // this.queryProductClassfy();
    this.GetProductionTableData()
    this.$refs.menuTree.clickFirst()
  },
  methods: {
    contrast() {
      this.$refs.contrastRightDialog.openDialog('add', {}, this.type)
    },
    //树点击
    homeHandleNodeClick(data) {
      this.pageModel.pageNum = 1
      this.type = data.type
      this.$refs.baseLayout.pageClear()
      this.GetProductionTableData()
    },
    onCellClick(row) {
      this.openLoading('detail')
      this.$refs.rightDialog.openDialog('show', row, this.type)
    },
    // 表格数据
    async GetProductionTableData() {
      this.tabLoading = true
      let param = {
        ...this.pageModel,
        ...this.queryModel,
        type: this.type
      }
      let res = await authApi(
        'sysArchivesContrastService',
        '',
        'queryEntityPage',
        '',
        param
      )
      this.tabLoading = false
      if (res.status == '200') {
        console.log(res.attribute.list, 'res.attribute.list')
        this.tableData = res.attribute.list
        this.$refs.baseLayout.setPageTotal(res.attribute.total)
      }
    },
    // 分页变化
    handlePageChange(val) {
      this.pageModel.pageNum = val.pageIndex
      this.pageModel.pageSize = val.pageSize
      this.GetProductionTableData()
    },
    // 按钮组
    onFuncBtn(btn) {
      this[btn.btnFunction]()
    },
    // 新增
    add() {
      this.$refs.rightDialog.openDialog('add', {}, this.type)
    },
    // 表格操作事件 查看 编辑 删除
    onFunc(index, row, item) {
      // 查看
      if (item.text === '查看') {
        this.openLoading('detail')
        this.$refs.rightDialog.openDialog('show', row, this.type)
      }
      // 编辑
      if (item.text === '编辑') {
        this.openLoading('detail')
        this.$refs.rightDialog.openDialog('edit', row, this.type)
      }
      // 删除
      if (item.text === '删除') {
        this.$delConfirm().then(() => {
          this.openLoading('del')
          this.productionDeleteById(row.id)
        })
      }
    },
    async productionDeleteById(id) {
      let param = {
        id: id,
        type: this.type
      }
      let res = await authApi(
        'sysArchivesContrastService',
        '',
        'deleteEntity',
        '',
        param
      )
      if (res.status == '200') {
        this.$vmNews('删除成功', 'success')
        this.resetTable()
      }
    },
    // 重置表格
    resetTable() {
      this.pageModel.pageNum = 1
      this.$refs.baseLayout.pageClear()
      this.GetProductionTableData()
    },
    // 搜索
    handleSearchEvent() {
      let data = this.$refs.baseLayout.ruleForm
      this.queryModel = data
      this.resetTable()
    },
    // 获取所有产品分类
    async queryProductClassfy() {
      let params = {
        tab_name: 'sys_product',
        column_name: 'classify'
      }
      let res = await authApi(
        'generalServiceImpl',
        'dictionaryshop',
        'selectDictionaryshop',
        '',
        params
      )
      if (res.status == '200') {
        this.requirementList[2].options = res.attribute
      }
    }
  }
}
</script>

<style scoped>
.clickTitle {
  color: #409eff;
  cursor: pointer;
}
</style>
