<!--
  @description: 系统配置管理新增/编辑
  @Modifier: zhuyanchao
  @routerPath:
  @date: 2020-7-11-15:23
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    :title="title"
    width="700px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <section class="main">
      <!-- 表单 -->
      <el-form ref="formData" :model="formData" label-width="96px" class="demo-ruleForm">
        <el-row>
          <el-col :span="24">
            <!-- key键值 -->
            <el-form-item label="key键值" prop="configType">
              <el-input
                v-model="formData.configType"
                maxlength="50"
                placeholder="最多允许输入50个汉字(100字符)"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- value值 -->
            <el-form-item label="value值" prop="configValue">
              <el-input
                v-model="formData.configValue"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                maxlength="8000"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 启用状态值 -->
            <el-form-item label="启用状态" prop="useStatus">
              <el-select v-model="formData.useStatus" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="(item,index) in systemConfigStatusList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 配置描述 -->
            <el-form-item label="配置描述" prop="configDesc">
              <el-input
                v-model="formData.configDesc"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                maxlength="500"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 系统类别 -->
            <el-form-item label="系统类别" prop="moduleType">
              <el-select v-model="formData.moduleType" style="width: 100%;" placeholder="请选择" filterable>
                <el-option
                  v-for="(item,index) in moduleTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typename"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 业务类别 -->
            <el-form-item label="业务类别" prop="configurationType">
              <el-select v-model="formData.configurationType" style="width: 100%;" placeholder="请选择" filterable>
                <el-option
                  v-for="(item,index) in configurationTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typename"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 模块类别 -->
            <el-form-item label="模块类别" prop="microServiceType">
              <el-select v-model="formData.microServiceType" style="width: 100%;" placeholder="请选择" filterable>
                <el-option
                  v-for="(item,index) in microServiceTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注" prop="remark">
              <el-input v-model="formData.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <!-- 影响 -->
            <el-form-item label="影响" prop="effect">
              <el-input v-model="formData.effect" placeholder="请输入影响" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure('formData')">提 交</el-button>
      <el-button @click="dialogData.dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { saveSystemConfig, getSystemconfigById } from '@/api/common/systemConfigCenter'// 系统配置
import { systemConfigMixin } from './mixins/systemConfigMixin'
export default {
  name: 'SystemConfigAddDialog',
  mixins: [systemConfigMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {
      }
    }
  },
  data() {
    return {
      title: '新增系统配置', // 弹框标题
      formData: {
        id: '',
        configType: '', // key键值
        configValue: '', // value值
        configDesc: '', // 配置描述
        useStatus: '01',
        moduleType: '', // 系统类别
        configurationType: '', //  业务类别
        microServiceType: '', //  模块类别
        remark: '', // 备注
        effect: '' // 影响
      }
    }
  },
  mounted() {
    this.watchDialog()
  },
  methods: {
    // 监听dialog
    watchDialog() {
      if (this.dialogData.dialog) {
        // 弹框已打开
        if (this.dialogData.id !== null) {
          this.getSystemconfigById(this.dialogData.id)
          this.title = '编辑系统配置'
        } else {
          this.title = '新增系统配置'
        }
      }
    },
    // 获取详情
    getSystemconfigById(id) {
      getSystemconfigById(id).then(res => {
        if (res.header.ret === '0') {
          this.formData = { ...res.data }
        }
      })
    },
    // 提交
    ensure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          saveSystemConfig(this.formData).then(res => {
            if (res.header.ret === '0') {
              this.dialogData.dialog = false
              this.$emit('watchChild', true)
            }
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
