<!--
  @description: 系统配置管理
  @Modifier: zhuyanchao
  @routerPath: /systemManagement/systemConfig-list
  @date: 2020-7-11-15:23
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form.sync="searchForm"
      search-label-width="110px"
      @on-load="loadData"
    >
      <template v-slot:header>
        <span>系统配置管理</span>
      </template>
      <template v-slot:search="search">
        <!-- key键值 -->
        <el-form-item ref="configType" label="key键值" prop="configType">
          <el-input v-model.trim="searchForm.configType" placeholder="key键值" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- value值 -->
        <el-form-item ref="configValue" label="value值" prop="configValue">
          <el-input v-model.trim="searchForm.configValue" placeholder="value值" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--使用状态-->
        <el-form-item
          ref="useStatus"
          label="使用状态"
          prop="useStatus"
        >
          <el-select v-model="searchForm.useStatus" placeholder="请选择" style="width: 120px">
            <el-option
              v-for="(item,index) in systemConfigStatusList"
              :key="index"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!-- 配置描述 -->
        <el-form-item ref="configDesc" label="配置描述" prop="configDesc">
          <el-input v-model.trim="searchForm.configDesc" placeholder="配置描述" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 系统类别 -->
        <el-form-item ref="moduleType" label="系统类别" prop="moduleType">
          <el-select v-model="searchForm.moduleType" filterable placeholder="请选择" style="width: 120px">
            <el-option
              v-for="(item,index) in moduleTypeList"
              :key="index"
              :label="item.typename"
              :value="item.typename"
            />
          </el-select>
        </el-form-item>
        <!-- 业务类别 -->
        <el-form-item ref="configurationType" label="业务类别" prop="configurationType">
          <el-select v-model="searchForm.configurationType" filterable placeholder="请选择" style="width: 120px">
            <el-option
              v-for="(item,index) in configurationTypeList"
              :key="index"
              :label="item.typename"
              :value="item.typename"
            />
          </el-select>
        </el-form-item>
        <!-- 模块类别 -->
        <el-form-item ref="microServiceType" label="模块类别" prop="microServiceType">
          <el-select v-model="searchForm.microServiceType" filterable placeholder="请选择" style="width: 120px">
            <el-option
              v-for="(item,index) in microServiceTypeList"
              :key="index"
              :label="item.typename"
              :value="item.typename"
            />
          </el-select>
        </el-form-item>
        <!-- 备注 -->
        <el-form-item ref="remark" label="备注" prop="remark">
          <el-input v-model.trim="searchForm.remark" placeholder="备注" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 影响 -->
        <el-form-item ref="effect" label="影响" prop="effect">
          <el-input v-model.trim="searchForm.effect" placeholder="影响" @keyup.enter.native="search.onSearch" />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button type="primary" @click="addConfig">
            新增配置
          </el-button>
          <el-button type="primary" plain :loading="exportLoading" @click="exportChange">
            导出
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <!-- key键值 -->
          <el-table-column
            prop="configType"
            label="key键值"
            min-width="160"
          />
          <!-- configValue -->
          <el-table-column
            header-align="center"
            label="value值"
            prop="configValue"
            align="left"
            width="100"
          />
          <!-- 使用状态 -->
          <el-table-column
            header-align="center"
            prop="useStatus"
            label="使用状态"
            align="center"
            width="100"
          >
            <template slot-scope="scope">
              <span
                v-for="(item, index) in systemConfigStatusList"
                v-if="scope.row.useStatus === item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!-- 配置描述 -->
          <el-table-column
            header-align="center"
            prop="configDesc"
            label="配置描述"
            min-width="220"
          />
          <el-table-column
            header-align="center"
            prop="moduleType"
            label="系统类别"
            min-width="100"
          />
          <el-table-column
            header-align="center"
            prop="configurationType"
            label="业务类别"
            min-width="180"
          />
          <el-table-column
            header-align="center"
            prop="microServiceType"
            label="模块类别"
            min-width="180"
          />
          <el-table-column
            header-align="center"
            prop="remark"
            label="备注"
            min-width="180"
          />
          <el-table-column
            header-align="center"
            prop="effect"
            label="影响"
            min-width="180"
          />
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            width="160"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="edit(scope.row)"
              >
                [编辑]
              </el-link>
              <el-link
                type="primary"
                @click.stop="view(scope.row)"
              >
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.useStatus==='00'"
                type="primary"
                @click.stop="del(scope.row)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
    <!-- 新增/编辑系统配置弹框 -->
    <systemConfigAdd v-if="dialogDataAdd.dialog" :dialog-data="dialogDataAdd" @watchChild="watchChild" />
    <!-- 查看系统配置详情弹框 -->
    <systemConfigDetail v-if="dialogDataDetail.dialog" :dialog-data="dialogDataDetail" />
  </div>
</template>

<script>
/* 接口*/
import { getSystemConfigList, deleteSystemconfigById, exportSystemConfigList } from '@/api/common/systemConfigCenter'// 系统配置
import { systemConfigMixin } from './mixins/systemConfigMixin'
/* 公用方法*/
import { download } from '@/assets/js/utils'// 常用方法
/* 组件*/
import systemConfigAdd from './systemConfigAdd-dialog' // 新增、编辑系统配置弹框
import systemConfigDetail from './systemConfigDetail-dialog' // 查看系统配置弹框

export default {
  name: 'SystemConfigList',
  components: {
    systemConfigAdd, // 新增系统配置
    systemConfigDetail // 查看系统配置
  },
  mixins: [systemConfigMixin],
  data() {
    return {
      loading: true,
      exportLoading: false, // 导出送货单loading
      // 搜索
      searchForm: {
        configType: '', // key键值
        configValue: '', // value值
        configDesc: '', // 配置描述
        useStatus: '', // 使用状态:00禁用，01启用
        moduleType: '', // 系统类别
        configurationType: '', //  业务类别
        microServiceType: '', //  模块类别
        remark: '', // 备注
        effect: '' // 影响
      },
      tableData: [],
      dialogDataAdd: {
        dialog: false, // 新增系统配置弹框
        useStatus: '01' // 00禁用；01启用
      },
      dialogDataDetail: {
        dialog: false // 系统配置弹框详情
      }
    }
  },
  methods: {
    // 获取数据
    loadData(params, callback) {
      getSystemConfigList(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
      })
    },
    // 新增配置
    addConfig() {
      this.dialogDataAdd = {
        dialog: true,
        id: null
      }
    },
    // 编辑
    edit(row) {
      this.dialogDataAdd = {
        dialog: true,
        id: row.id
      }
    },
    // 查看系统配置
    view(row) {
      this.dialogDataDetail.dialog = true
      this.dialogDataDetail.id = row.id
    },
    // 删除
    del(row) {
      this.$confirm('确认删除该条记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        deleteSystemconfigById(row.id).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.$refs.tableCrud.onSearchChange()
        })
      })
    },
    // 监听子组件
    watchChild(val) {
      if (val) {
        this.$refs.tableCrud.onSearchChange()
      }
    },
    // 导出
    exportChange() {
      this.exportLoading = true
      exportSystemConfigList().then(res => {
        this.exportLoading = false
        download(res, '系统配置信息.xlsx')
      }).catch(() => {
        this.exportLoading = false
      })
    }
  }

}
</script>

<style lang="less" scoped>

</style>
