/*
 *@description:标记管理sign
 *@author: hudw
 *@date: 2022-04-27 15:06:58
*/
<template>
  <div class="pages">
    <formDetails v-show="detailsState === 2" :st="detailsState" ref="formDetails" :record="currentMainData"
      :mainId="mainId" :options="options" @back="onBack">
    </formDetails>
    <p-card v-show="detailsState === 0" class="full-card-panel full-body-flex" :alt="$route.meta.title"
      :bordered="false">
        <searchBar slot="title" ref="searchBar" @submit="submit" :options="options"/>
      <a-space slot="extra">
        <p-button type="primary" @click="handle_add" icon="plus">新增</p-button>
        <p-button @click="handle_remove" type="danger" :disabled="selectedRowKeys.length === 0">删除</p-button>
      </a-space>

      <mainTable ref="mainTable" :options="options" :selectedRowKeys.sync="selectedRowKeys" :activeID="mainId"
        @update="handleUpdate" @view="handleView" @copy="handleCopy" @clickRow="handleRowClick" />

    </p-card>
  </div>
</template>
<script>
import searchBar from './model/searchBar/index.searchBar.vue'
import mainTable from './model/mainTable/index.mainTable.vue' /**主表 */
import formDetails from './model/formDetails/index.formDetails.vue' /**表单 */
import { deleteMainItem } from './api'
import { initDictionary } from '@/blocks/utils'

export default {
  components: { searchBar, mainTable, formDetails },
  data() {
    return {
      open: false,
      options: {},
      selectedRowKeys: [],
      mainId: '',
      currentMainData: null,
      detailsState: 0,/**0=不显示,1=查看,2=新建,3=修改,4=复制 */
    };
  },
  mounted() {
    let _this = this;
    initDictionary([{ objectcode: 'SIGNCONFIG_TYPE' }, { objectcode: 'SIGNCONFIG_MATCHING' },
    ]).then(res => {
      for (let key in res) {
        res[key].forEach(item => {

          if (!isNaN(item.value)) {
            item.value = + item.value
          }
        })
      }
      _this.options = res

    })
  },
  computed: {


  },
  methods: {

    handleCopy(data) {
      this.detailsState = 4
      this.currentMainData = data
      this.formName = 'main'
    },
    handleRowClick(event, key, data) {
      this.mainId = key
      this.childrenId = ''
      if (key) {
        this.currentMainData = data
      } else {
        this.currentMainData = null
      }
    },
    handleUpdate(data) {

      this.detailsState = 3
      this.currentMainData = data
      this.formName = 'main'
    },
    submit() {
      return this.$refs.mainTable.reload()
    },
    handle_remove() {
      deleteMainItem(this, this.selectedRowKeys)

    },
    handle_add(data) {
      this.open = true
      this.detailsState = 2
      this.currentMainData = null
    },
    handleView(data) {
      this.detailsState = 1
      this.currentMainData = data
      this.formName = 'main'

    },
    onBack(id, isReload = false) {
      this.detailsState = 0
      isReload && this.$nextTick(() => {
        this.$refs.mainTable.reload().then(() => {
          if (id) {
            this.mainId = id
          }

        })
      })

    },
  },
};
</script>
<style lang='less' space>



</style>