<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-icon_analysis_patent"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="auto"
        label-position="right"
        :rules="rules"
      >
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">资质类型信息</div>
          </div>
        </div>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="资质类型编码" prop="code">
              <el-input
                v-model="parameter.code"
                disabled
                placeholder="请输入资质类型编码"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资质类型名称" prop="name">
              <el-input
                clearable
                v-model="parameter.name"
                placeholder="请输入资质类型名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="限制文件大小(MB)" prop="fileSize">
              <el-input
                clearable
                type="Number"
                v-model="parameter.fileSize"
                placeholder="请输入限制文件大小(MB)"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="是否需要审批" prop="changeApproval">
              <el-select
                style="width: 100%"
                v-model="parameter.changeApproval"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in changeApprovalList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="12">
            <el-form-item label="是否限制有限期" prop="limitation">
              <el-select
                style="width: 100%"
                v-model="parameter.limitation"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in limitationList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row :gutter="24">
          
          <!-- <el-col :span="12">
            <el-form-item
              label="到期处理方式"
              prop="expirationProcessingMethod"
            >
              <el-select
                style="width: 100%"
                v-model="parameter.expirationProcessingMethod"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in expirationProcessingMethodList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          
        </el-row>
        <el-row :gutter="24">
          
          <el-col :span="12" v-if="parameter.changeApproval == 1">
            <el-form-item label="审批方式" prop="changeApprovalMethod">
              <el-select
                style="width: 100%"
                v-model="parameter.changeApprovalMethod"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in changeApprovalMethodList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row :gutter="23">
          <el-col :span="12">
            <el-form-item label="创建人姓名" prop="createName">
              <el-input
                clearable
                v-model="parameter.createName"
                placeholder="请输入创建人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
      <el-button type="primary" :loading="saveing" @click="handleSave">{{
        $t('domestic.save')
      }}</el-button>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import basicData from '@/api/basicData'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb},
  props: {
    editData: Object,
  },
  data() {
    return {
      breadcrumbOpt: [{breadcrumbName: '资质配置'}, {breadcrumbName: '新增'}],
      expirationProcessingMethodList: [
        {
          label: '冻结',
          value: 0,
        },
        {
          label: '提醒',
          value: 1,
        },
      ],
      limitationList: [
        {
          label: '不限制',
          value: '0',
        },
        {
          label: '限制',
          value: '1',
        },
      ],
      saveing: false,
      changeApprovalList: [
        {
          label: '不需要审批',
          value: 0,
        },
        {
          label: '需要审批',
          value: 1,
        },
      ],
      changeApprovalMethodList: [
        {
          label: '企业审批',
          value: 0,
        },
        {
          label: '平台审批',
          value: 1,
        },
      ],
      rules: {
        qualificationTypeCode: [
          {
            required: true,
            message: '请输入资质类型编码',
            trigger: 'blur',
          },
        ],
        name: [
          {
            required: true,
            message: '请输入资质类型名称',
            trigger: 'blur',
          },
        ],
        fileSize: [
          {
            required: true,
            message: '请输入限制文件大小',
            trigger: 'blur',
          },
        ],
        limitation: [
          {
            required: true,
            message: '请选择是否限制有效期',
            trigger: 'blur',
          },
        ],
        expirationProcessingMethod: [
          {
            required: true,
            message: '请选择到期处理方式',
            trigger: 'blur',
          },
        ],
        changeApproval: [
          {
            required: true,
            message: '请选择是否需要审批',
            trigger: 'blur',
          },
        ],
        changeApprovalMethod: [
          {
            required: true,
            message: '请选择审批方式',
            trigger: 'blur',
          },
        ],
        createName: [
          {
            required: true,
            message: '请输入创建人姓名',
            trigger: 'blur',
          },
        ],
        updateName: [
          {
            required: true,
            message: '请输入更新人姓名',
            trigger: 'blur',
          },
        ],
        fileNum: [
          {
            required: true,
            message: '请选择限制文件数量',
            trigger: 'blur',
          },
        ],
      },
      currentUser: {},
      parameter: {
        name: '',
        qualificationTypeCode: '',
        fileSize: '',
        fileNum: '',
        expirationProcessingMethod: 0,
        changeApproval: 0,
        changeApprovalMethod: 0,
        createName: '',
        createBy: '',
        updateName: '',
        limitation: 0,
      },
    }
  },
  created() {
    this.addModifyBtn()
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    this.parameter.createName = this.currentUser.user.fullname
    this.parameter.createBy = this.currentUser.user.userId
  },
  mounted() {},
  methods: {
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        console.log()
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
        this.modifychoData(this.$route.query.editRows)
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
        this.getCode()
      }
    },
    getCode() {
      this.$http
        .get('${portal}/sys/identity/v1/getNextIdByAlias?alias=zrgz_bm')
        .then((res) => {
          if (res.data.state) {
            this.parameter.code = res.data.value
          }
        })
    },
    //获取修改回显数据
    modifychoData(val) {
      val.changeApproval = Number(val.changeApproval)
      val.changeApprovalMethod = Number(val.changeApprovalMethod)
      val.expirationProcessingMethod = Number(val.expirationProcessingMethod)
      this.parameter = val
    },
    // 关闭//面包屑点击
    handleClose() {
      this.$router.push({
        name: 'qualificationType',
      })
      this.parameter = {
        name: '',
        qualificationTypeCode: '',
        fileSize: '',
        fileNum: '',
        expirationProcessingMethod: '0',
        changeApproval: '0',
        changeApprovalMethod: '0',
        createName: '',
        createBy: '',
        updateName: '',
      }
      // this.$refs.formInfo.clearValidate()
    },
    // 保存
    handleSave() {
      this.$refs.formInfo.validate((valid) => {
        if (valid) {
          this.saveing = true
          basicData.bizQualificationSaveCategory(this.parameter).then((res) => {
            this.saveing = false
            if (res.state) {
              this.$message.success('保存成功')
              this.handleClose()
            }
          })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
// /deep/.el-row {
//   padding: 0 100px;
// }
.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
