<!--资质证照-新增-->
<template>
  <div class="accessRequirementAddPage">
    <el-form :model="form" ref="form" label-width="120px" :rules="rules">
      <el-form-item label="资质名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入资质名称" style="width:320px;" maxlength="15" ></el-input>
      </el-form-item>
      <el-form-item label="供应商类型">
        <el-select v-model="form.supplierType" placeholder="请选择" style="width:320px;">
          <el-option :label="item.dictLabel" :value="item.dictValue" v-for="(item,index) in materialTypeList" :key="index"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="资质类型" >
        <el-radio-group v-model="form.type">
          <el-radio :label="1">供应商资质</el-radio>
          <el-radio :label="2">人员证照</el-radio>
          <el-radio :label="3">车辆证照</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="form.sort" :min="0" :max="999" style="width:320px;" ></el-input-number>
      </el-form-item>
      <el-form-item label="是否必填">
        <el-radio-group v-model="form.required" @change="radioChange">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="需选择有效期">
        <el-radio-group v-model="form.validity" @change="radioChange">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入" style="width:320px;" maxlength="50" ></el-input>
      </el-form-item>

      <div class="bottom-button-box">
        <p class="reset-button-one" @click="backPage">取消</p>
        <p class="inquire-button-one" @click="submitForm">提交</p>
      </div>
    </el-form>
  </div>
</template>

<script>
  import { materialdata,materialdataPut } from "@/api/laboratory/accessRequirement"
  import {
    certificationAdd, certificationAnew,
    certificationDetail, certificationInfo,
    gasCategoryList,
    specificationAdd,
    specificationAnew,
    specificationInfo,
    supplierTypeList
  } from '@/api/gasManage3_0/gasManage'
  export default {
    name: 'accessRequirementAddPage',
    props:{
      pageData:{},
    },
    data() {
      return {
        materialTypeList:[],
        form:{
          name:'',
          supplierType:'1',
          type:1,
          sort:'',
          required:'',
          validity:'',
          remark:'',
        },
        status:0,
        // 表单校验
        rules: {
          name: [
            { required: true, message: "请输入资质名称", trigger: "change" }
          ],
          sort: [
            { required: true, message: "请输入排序序号", trigger: "change" }
          ],
        },

      }
    },
    methods: {
      handleClose(tag) {
        this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
      },

      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },
      handleInputConfirm() {
        let specificationVal = this.form.specificationVal;
        if (specificationVal) {
          this.dynamicTags.push(specificationVal);
        }
        this.form.specificationVal = '';
      },
      //单选事件
      radioChange(e){

      },
      //返回
      backPage(){
        this.$parent.handleClick('','','back');
        this.$parent.getList();
      },
      //气瓶类目
      supplierTypeList(){
        let _this=this;
        supplierTypeList().then( response => {
          let res=response.rows;
          _this.materialTypeList=res;
        });
      },
      /* 详情 */
      getInfo(id){
        let _this=this;
        certificationInfo(id).then( response => {
          let res=response.data;
          if(response.code==200){
            _this.form=res;
            _this.form.supplierType=res.supplierType==null?'':res.supplierType+'';
            res.detailVos.forEach(function(item){
              _this.dynamicTags.push(item.specValue)
            })
          }
        });

      },
      //提交
      submitForm(){
        let _this = this;
        this.$refs["form"].validate(valid => {
          if (valid) {
            _this.form.type=_this.form.type+'';
            if(_this.status==0){//添加
              certificationAdd(_this.form).then(response => {
                _this.msgSuccess(_this.form.name+"添加成功");
                _this.backPage();
              });
            }else if(_this.status==1){//编辑
              certificationAnew(_this.form).then(response => {
                _this.msgSuccess(_this.form.name+"修改成功");
                _this.backPage();
              });
            }

          }
        })
      }
    },
    mounted(){
      this.status=this.pageData.status;

      if(this.status==1){
        this.form.id=this.pageData.id
        this.getInfo(this.pageData.id);
      }
      this.supplierTypeList();
    },

  }
</script>

<style scoped lang="scss">
  .accessRequirementAddPage{
    flex:1;
    overflow-y: scroll;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:50px 0 50px 60px!important;
    border-radius: 10px;
    .bottom-button-box{
      margin-top:50px;
      display: flex;
      p:nth-child(1){
        margin:0 20px 0 100px;
      }
      .inquire-button-one{
        width: 140px;
      }
    }
  }
</style>
