<!--
 * @Descripttion:
 * @version:
 * @Author: fzq
 * @Date: 2022-03-05 17:45:46
 * @LastEditors: fzq
 * @LastEditTime: 2022-03-20 09:35:03
-->
<template>
  <!-- <el-dialog
    :title="!dataForm.id ? 'btn.add' : 'btn.edit' | i18nFilter"
    :visible.sync="visible"
  > -->
  <el-dialog
    :title="'btn.edit' | i18nFilter"
    :visible.sync="visible"
  >
    <el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="130px" @keyup.enter.native="dataFormSubmit()">
      <el-form-item :label="$t('module.report.substrate.substrateCode')" prop="substrateCode">
        <el-input v-model="dataForm.substrateCode" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.substrateCode')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.report.substrate.location')" prop="subPosition">
        <el-input v-model="dataForm.subPosition" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.location')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.report.substrate.storeTime')" prop="storeTime">
        <el-input v-model="dataForm.storeTime" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.storeTime')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.report.substrate.substrateStatus')" prop="status">
        <el-input v-model="dataForm.status" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.substrateStatus')])" clearable />
      </el-form-item>
      <!-- <el-form-item :label="$t('module.report.substrate.interCode')" prop="interCode">
        <el-input v-model="dataForm.interCode" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.interCode')])" clearable />
      </el-form-item> -->
      <!-- <el-form-item :label="$t('module.report.substrate.subStorageStatus')" prop="subStorageStatus">
        <el-input v-model="dataForm.subStorageStatus" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.subStorageStatus')])" clearable />
      </el-form-item> -->
      <el-form-item :label="$t('module.report.substrate.subStorageStatus')" prop="subStorageStatus">
        <el-select v-model="dataForm.subStorageStatus" :placeholder="this.$t('module.report.substrate.subStorageStatus')" default>
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('module.report.substrate.machineHandID')" prop="machineHandID">
        <el-input v-model="dataForm.machineHandID" :placeholder="$i18nForm(['placeholder.input', $t('module.report.substrate.machineHandID')])" clearable />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ 'btn.cancel' | i18nFilter }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ 'btn.confirm' | i18nFilter }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateSubstrate } from '@/api/report-manage/report'

export default {
  props: {
    id: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data() {
    return {
      visible: false,
      dataForm: {
        // substrateCode: '',
        // locationName: '',
        // storeTime: '',
        // substrateStatus: '',
        // code: '',
        // storageBoxId: '',
        // storageCode: '',
        // interCode: '',
        // id: '',
        // current: 1,
        // size: 10,
        // locationStorageSubID: ''
      },
      options: [
        {
          value: 1,
          label: this.$t('module.report.substrate.load')
        },
        {
          value: 2,
          label: this.$t('module.report.substrate.unload')
        }
      ],
      list: {
        id: '',
        locationName: '',
        storeTime: '',
        substrateCode: '',
        substrateStatus: ''
      },
      dataRule: {
        substrateCode: [
          { required: true, message: this.$i18nForm(['placeholder.input', this.$t('module.report.substrate.substrateCode')]), trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    // init(id) {
    //   // this.dataForm.id = id || ''
    //   this.dataForm.storageBoxId = this.$route.query.id
    //   this.dataForm.storageCode = this.$route.query.code
    //   this.visible = true
    //   this.$nextTick(() => {
    //     this.$refs['dataForm'].resetFields()
    //     // console.log(this.dataForm)
    //     listSubstrate(this.dataForm).then(res => {
    //       this.dataForm.id = res.data.id
    //       this.dataForm.location = res.data.location
    //       this.dataForm.storeTime = res.data.storeTime
    //       this.dataForm.substrateCode = res.data.substrateCode
    //       this.dataForm.substrateStatus = res.data.substrateStatus
    //       // console.log(this.dataForm)
    //     })
    //   })
    // },
    init(data) {
      // this.dataForm.id = id || ''
      // console.log(this.$route.query)
      // this.dataForm.id = this.$route.query.id
      // this.dataForm.substrateCode = this.$route.query.substrateCode
      // this.dataForm.locationStorageSubID = this.$route.query.locationStorageSubID
      this.dataForm = data
      this.visible = true
      // console.log(this.dataForm)
      // listSubstrate(this.dataForm).then(res => {
      //   // console.log(res)
      //   this.dataForm.id = res.data[0].id
      //   this.dataForm.location = res.data[0].location
      //   this.dataForm.storeTime = res.data[0].storeTime
      //   this.dataForm.substrateCode = res.data[0].substrateCode
      //   this.dataForm.substrateStatus = res.data[0].substrateStatus
      //   this.dataForm.interCode = res.data[0].interCode
      //   // console.log(this.dataForm)
      // })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const data = {
            'status': this.dataForm.status,
            'storeTime': this.dataForm.storeTime,
            'id': this.dataForm.id,
            'substrateCode': this.dataForm.substrateCode,
            'subPosition': this.dataForm.subPosition,
            // 'interCode': this.dataForm.interCode,
            'storageBoxFid': this.dataForm.storageBoxFid,
            'machineHandID': this.dataForm.machineHandID,
            'subStorageStatus': this.dataForm.subStorageStatus
          }
          console.log(data)
          updateSubstrate(data).then(res => {
            this.$message({
              message: this.$t('module.basicData.visual.success'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          })
        }
      })
    }
  }
}
</script>
