<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-custom__module}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model.trim="dataForm.moduleCode" placeholder="模块编码" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model.trim="dataForm.name" placeholder="模块名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('custom:module:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('custom:module:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="40"></el-table-column>
        <el-table-column prop="name" label="模块名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="moduleCode" label="模块编码" header-align="center" align="center" width="170"></el-table-column>
        <el-table-column prop="moduleCategory" label="模块分类" header-align="center" align="center" :formatter="moduleTypeFormat"></el-table-column>
        <el-table-column align="center" label="模块图片" :show-overflow-tooltip="true" prop="imgUrl">
          <template slot-scope="scope">
            <el-popover placement="right"
                        title=""
                        trigger="click"
                        class="big_image">
              <el-image slot="reference"
                        min-width="70"
                        height="70"
                        :src="scope.row.imgUrl"
                        :alt="scope.row.imgUrl"></el-image>
              <img class="big_image"
                   :src="scope.row.imgUrl" />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="enableFlag" label="启用标识" :formatter="showFlagFormatter" header-align="center" align="center" width="80"></el-table-column>
        <el-table-column prop="sort" label="排序" header-align="center" align="center" width="60"></el-table-column>
        <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="130">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('custom:module:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('custom:module:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './module-add-or-update'
import 'element-ui/lib/theme-chalk/image.css'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/custom/module/page',
        getDataListIsPage: true,
        deleteURL: '/custom/module',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      },
      optionModuleName: []
    }
  },
  created () {
    this.getListSimpleByDictType()
    this.getNoticeCategory()
  },
  methods: {
    showFlagFormatter: function (row, column) {
      if (row.enableFlag === '0') {
        return '否'
      }
      return '是'
    },
    // 获取模块名称[参数：moduleType]
    getListSimpleByDictType () {
      this.$http.get(`/custom/module/listSimple/moduleType`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.optionModuleName = res.data
      }).catch(() => {})
    },
    moduleTypeFormat (row, column) {
      for (var property in this.optionModuleName) {
        if (row.moduleCategory === this.optionModuleName[property].dictValue) {
          return this.optionModuleName[property].dictName
        }
      }
    }
  },
  components: {
    AddOrUpdate
  }
}
</script>
<style scoped>
  .big_image {
    width: 300px;
    height: 240px;
  }
</style>
