<template>
  <el-dialog
    title="委外派单"
    :visible.sync="entrustVisible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="50%"
  >
    <div class="main_container">
      <el-form :model="addForm" :rules="addFormRules" label-width="120px"  ref="addFormRef">
        <el-row>
          <el-col :span="12">
            <el-form-item label="报修记录编号：" prop="repairsCode">
              <el-input
                v-model="addForm.repairsCode"
                size="small"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备编码：" prop="equiCode">
              <el-input
                v-model="addForm.equiCode"
                size="small"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备名称：" prop="equiName">
              <el-input
                v-model="addForm.equiName"
                size="small"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="委外单位：" prop="outsourcUnit">
              <el-select
                size="small"
                style="width: 100%"
                clearable
                v-model="addForm.outsourcUnit"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in deptList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.name"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划完成时间：" prop="plannCompletionTime">
              <el-date-picker
                v-model="addForm.plannCompletionTime"
                type="datetime"
                style="width: 100%"
                placeholder="选择日期时间"
                size="small"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="btns">
      <el-button type="primary" size="small" @click="submitAdd">提交</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>

// import { addOutsource, getAllSupplier } from '@/api/maintenance/repair/repair'
export default {
  props: {

  },
 watch: {

  },
  data () {
    return {
      addForm: {},
      addFormRules: {
        outsourcUnit:[{ required: true, message: '请选择委外单位', trigger: 'change' }],
        plannCompletionTime:[{ required: true, message: '请选择计划完成时间', trigger: 'change' }]
      },
      entrustVisible:false,
      deptList:[]
    }
  },
  created () {

  },
  methods: {
    init(row){
       this.addForm = {}
       this.addForm.repairsCode = row.repairsCode
       this.addForm.equiCode = row.equiCode
       this.addForm.equiName = row.equiName
       this.addForm.equiId = row.equiId
       this.addForm.status = 0
       // this.getgys()
       this.entrustVisible = true
    },

    // 获取供应商列表
    async getgys () {
      let res = await getAllSupplier()
      this.deptList = res.data
    },

    handleClose () {
      this.$refs.addFormRef.resetFields()
      this.entrustVisible = false
    },

    submitAdd(){
      this.$refs.addFormRef.validate(valid => {
        if (valid) {
          addOutsource(this.addForm).then(res=>{
               if (res?.success) {
                 this.handleClose()
                 this.$message.success('委派成功！')
                 this.$emit('refresh')
               }
           })

        }
      })

    }





  }
}
</script>

<style lang="scss" scoped>
.dialog_top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.btns {
  text-align: right;
  margin: 10px 0;
}
</style>
