<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="工序代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processCode">
              <a-input v-model="model.processCode" placeholder="请输入工序代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processName">
              <a-input v-model="model.processName" placeholder="请输入工序名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工艺描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processDescribe">
              <a-textarea v-model="model.processDescribe" rows="4" placeholder="请输入工艺描述"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="做工说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mkExplain">
              <a-textarea v-model="model.mkExplain" rows="4" placeholder="请输入做工说明"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品质要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qualityRequire">
              <a-input v-model="model.qualityRequire" placeholder="请输入品质要求"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processTime">
              <a-input v-model="model.processTime" placeholder="请输入工序时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入工序单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="grade">
              <a-input v-model="model.grade" placeholder="请输入工序等级"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="面料代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fabricNum">-->
<!--              <a-input v-model="model.fabricNum" placeholder="请输入面料代码"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="面料等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fabricGrade">-->
<!--              <a-input v-model="model.fabricGrade" placeholder="请输入面料等级"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="针距（针/厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="needlePitch">
              <a-input-number v-model="model.needlePitch" placeholder="请输入针距（针/厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="机器名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineId">-->
<!--              <j-dict-select-tag type="list" v-model="model.machineId" dictCode="zy_devicetype,name,id" placeholder="请选择机器名" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="手工宽放" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manualWide">
              <a-input v-model="model.manualWide" placeholder="请输入手工宽放"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手工时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manualTime">
              <a-input-number v-model="model.manualTime" placeholder="请输入手工时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机器转速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineSpeed">
              <a-input-number v-model="model.machineSpeed" placeholder="请输入机器转速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机器宽放" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineWide">
              <a-input v-model="model.machineWide" placeholder="请输入机器宽放"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机器时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineTime">
              <a-input-number v-model="model.machineTime" placeholder="请输入机器时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机器浮于" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineFloat">
              <a-input v-model="model.machineFloat" placeholder="请输入机器浮于"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="绑包宽放" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bundleWide">
              <a-input v-model="model.bundleWide" placeholder="请输入绑包宽放"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="绑包时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bundleTime">
              <a-input v-model="model.bundleTime" placeholder="请输入绑包时间"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="部件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="componentId">-->
<!--              <j-dict-select-tag type="list" v-model="model.componentId" dictCode="zy_cloths_component,parts_name,id" placeholder="请选择部件表" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="是否为瓶颈工序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isBottleneck">-->
<!--              <a-input-number v-model="model.isBottleneck" placeholder="请输入是否为瓶颈工序" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseId">-->
<!--              <a-input v-model="model.enterpriseId" placeholder="请输入企业名称"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="企业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseId">
              <j-select-depart  v-model="model.enterpriseId" placeholder="请输入企业名称" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="工具名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolId">-->
<!--              <j-dict-select-tag type="list" v-model="model.toolId" dictCode="zy_tool,name,id" placeholder="请选择工具名称" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="款式名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="styleId">-->
<!--              <a-input v-model="model.styleId" placeholder="请输入款式名称"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="款式名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="styleId">-->
<!--              <j-dict-select-tag  v-model="model.styleId"  placeholder="请输入款式名称" dictCode="zy_cloths_style,style_names,id" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="工段代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="worksectionCode">
              <a-input v-model="model.worksectionCode" placeholder="请输入工段代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processType">
              <j-dict-select-tag type="radio" v-model="model.processType" dictCode="processType" placeholder="" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="合同号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractNum">-->
<!--              <a-input v-model="model.contractNum" placeholder="请输入合同号"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="合计（手工TMU）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalManualTmu">
              <a-input-number v-model="model.totalManualTmu" placeholder="请输入合计（手工TMU）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合计（机器TMU）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalMachineTmu">
              <a-input-number v-model="model.totalMachineTmu" placeholder="请输入合计（机器TMU）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合计（手工秒）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalMaunal">
              <a-input-number v-model="model.totalMaunal" placeholder="请输入合计（手工秒）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合计（机器秒）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalMachine">
              <a-input-number v-model="model.totalMachine" placeholder="请输入合计（机器秒）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" class='coin'>
            <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image" >
              <j-image-upload isMultiple  v-model="model.image" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="视频" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vedio">
              <j-upload v-model="model.vedio"   ></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

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

  export default {
    name: 'ZyProcessForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          processType:0,
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           fabricNum: [
              { required: true, message: '请输入面料代码!'},
           ],

          processCode: [
            { required: true, message: '请输入工序代码!'},
          ],
          processName: [
            { required: true, message: '请输入工序名称!'},
          ],

        },
        url: {
          add: "/base/zyProcess/add",
          edit: "/base/zyProcess/edit",
          queryById: "/base/zyProcess/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;
        console.log(this.model)
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              this.model.createBy=store.getters.userInfo.realname
              httpurl+=this.url.add;
              method = 'post';
            }else{
              this.model.updateBy=store.getters.userInfo.realname
              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;
            })
          }

        })
        console.log(this.model)
      },
    }
  }
</script>