<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
   <zy-machine ref="realForm"   @onChangeRowKey="chuancan" @ok="submitCallback" :disabled="disableSubmit" @onChangeCode="changecode" @onChangeCodeName="changecodename"></zy-machine>
  </j-modal>
</template>

<script>

 import ZyMachine from "./list/ZyMachine";
  import {postAction} from "@/api/manage";
  export default {
    name: 'ZyProcessMachineModal',
    components: {
      ZyMachine
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        model:{
          machineId:'',
          processId:'',
          code:'',
          processCode:"",
          codeName:""
        },
        url:{
          add: "/pro/zyProcessMachine/add",
        }
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      add1 (id) {
        this.visible=true
        this.model.processId=id;
        this.model.processCode=id;
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      chuancan(res){
        this.model.machineId=res;
        console.log(res)
      },
      changecode(res){
        this.model.code=res;
        console.log(res)
      },
      changecodename(res){
        this.model.codeName=res;
      },
      handleOk () {
        postAction(this.url.add,this.model).then((res)=>{
          if(res.success){
            this.$message.success(res.message);
          }else{
            this.$message.warning(res.message);
          }
          this.$emit('valueChange',1)
          this.close()

        })},
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>