<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__menu">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataListSearch()"
      >
        <el-form-item>
          <el-button
            v-if="$hasPermission('workRecord:resource:save')"
            type="primary"
            @click="addOrUpdateHandle()"
            >{{ $t('add') }}</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        style="width: 100%;"
      >
        <table-tree-column
          prop="resourceLabel"
          label="资源名称"
          header-align="center"
        ></table-tree-column>
        <el-table-column
          prop="resourceCode"
          label="资源编码"
          header-align="center"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
                prop="resourceType"
                label="资源类型"
                header-align="center"
                align="center"
                show-overflow-tooltip
        ></el-table-column>
        <el-table-column
                prop="sort"
                label="排序"
                header-align="center"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="showFlag"
                label="是否显示"
                header-align="center"
                align="center"
                :formatter="showFlagFormatter"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
                    v-if="$hasPermission('workRecord:resource:total')"
                    type="text"
                    :disabled="scope.row.isFatherFlag ==='0'? false :true"
                    size="small"
                    @click="relationHandle(scope.row.id)"
            >统计配置</el-button
            >
            <el-button
              v-if="$hasPermission('workRecord:resource:update')"
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
              >{{ $t('update') }}</el-button
            >
            <el-button
              v-if="$hasPermission('workRecord:resource:delete')"
              type="text"
              size="small"
              :disabled="scope.row.isFatherFlag ==='0'? false :true"
              @click="deleteHandle(scope.row.id)"
              >{{ $t('delete') }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
      <relation-list
              v-if="relationListVisible"
              ref="relationList"
              @refreshDataList="getDataList"
      ></relation-list>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import TableTreeColumn from '@/components/table-tree-column'
import AddOrUpdate from './resource-add-or-update'
import RelationList from './resourcestotalrelation-list'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/workRecord/resourcesdictionary/list',
        deleteURL: '/workRecord/resourcesdictionary',
        deleteIsBatch: true
      },
      relationListVisible: false
    }
  },
  components: {
    TableTreeColumn,
    AddOrUpdate,
    RelationList
  },
  methods: {
    showFlagFormatter: function (row, column) {
      if (row.showFlag === '0') {
        return '否'
      } else if (row.showFlag === '1') {
        return '是'
      }
    },
    // 配置统计
    relationHandle (id) {
      this.relationListVisible = true
      this.$nextTick(() => {
        this.$refs.relationList.dataForm.resourceId = id
        this.$refs.relationList.init()
      })
    }
  }
}
</script>
