<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <div class="cmms-dialog-item-title">巡检内容基本信息</div>
        <a-row>
          <!-- <a-col :span="24">
            <a-form-model-item label="巡检内容编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contentcode">
              <a-input v-model="model.contentcode" placeholder="请输入巡检内容编号"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="巡检内容名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contentname">
              <a-input v-model="model.contentname" placeholder="请输入巡检内容名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="巡检设备" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentid">
              <j-search-select-tag v-model="model.equipmentid" dict="ems_tpm_equipment,equipmentname,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="radio" v-model="model.status" dictCode="inspect_content_status" placeholder="请选择状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <j-popup v-model="model.jPopup" code="demo" field="name" orgFields="name" destFields="name" :multi="true"/> -->
        </a-row>
        <div class="cmms-dialog-item-title">设备巡检设置</div>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CmmsInspectContentForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           contentname: [
              { required: true, message: '请输入巡检内容名称!'},
           ],
           equipmentid: [
              { required: true, message: '请输入设备id!'},
           ],
           status: [
              { required: true, message: '请输入状态：启用：0、禁用:1!'},
           ],
        },
        url: {
          add: "/cmmsInspectContent/cmmsInspectContent/add",
          edit: "/cmmsInspectContent/cmmsInspectContent/edit",
          queryById: "/cmmsInspectContent/cmmsInspectContent/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@/assets/less/uStyle.less';
</style>
<style lang="less" scoped>
</style>