<template>
  <!-- :exportList="exportList" -->
  <template-page
    ref="pageRef"
    :getList="getList"
    :columnParsing="columnParsing"
    :optionsEvensGroup="optionsEvensGroup"
    :tableAttributes="tableAttributes"
    :tableEvents="tableEvents"
    :operationColumnWidth="200"
    :operation="operation()"
  >
    <AddDataDictionary
      :visible="visible"
      :item="item"
      @setVisible="
        bool => {
          visible = bool
          if (!bool && item) {
            item = null
          }
        }
      "
      @success="
        () => {
          $refs.pageRef.refreshList()
        }
      "
    />
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import AddDataDictionary from './components/addDataDictionary.vue'
import { getDataDictionaryExport, getDataDictionary, delDataDictionary } from '@/api/dataDictionary2.js'
export default {
  components: {
    TemplatePage,
    AddDataDictionary
  },
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [
        [
          [
            {
              name: '新增',
              click: () => {
                this.visible = true
              }
            }
          ]
        ]
      ],
      // 表格属性
      tableAttributes: {},
      // 表格事件
      tableEvents: {},
      visible: false,
      item: null
    }
  },
  methods: {
    // 列表请求函数
    getList: getDataDictionary,
    // 列表导出函数
    exportList: getDataDictionaryExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    operation() {
      if (true) {
        return (h, { row, index, column }) => {
          return (
            <div class="operation-btns">
              {true ? (
                <zj-button
                  useLoading={false}
                  parameter={[row]}
                  buttonAttributes={{
                    size: 'mini',
                    type: 'primary'
                  }}
                  buttonEvents={{
                    click: (...p) => {
                      var [row] = p
                      this.item = row
                      this.visible = true
                    }
                  }}
                >
                  编辑
                </zj-button>
              ) : null}
              {true ? (
                <el-popconfirm
                  icon="el-icon-info"
                  icon-color="red"
                  title="这是一段内容确定删除吗？"
                  onConfirm={() => {
                    delDataDictionary({ id: row.sysDictId })
                      .then(res => {
                        this.$refs.pageRef.refreshList()
                        this.$message({
                          type: 'success',
                          message: `删除成功!`
                        })
                      })
                      .catch(err => {
                        console.log(err)
                      })
                  }}
                >
                  <zj-button
                    slot="reference"
                    buttonAttributes={{
                      size: 'mini',
                      type: 'danger'
                    }}
                  >
                    删除
                  </zj-button>
                </el-popconfirm>
              ) : null}
            </div>
          )
        }
      }
      return undefined
    }
  }
}
</script>

<style lang="scss" scoped></style>
