<!--
 * @Descripttion:
 * @version:
 * @Author: fzq
 * @Date: 2022-03-04 11:12:42
 * @LastEditors: fzq
 * @LastEditTime: 2022-03-06 19:17:36
-->
<template>
  <el-dialog
    :title="!dataForm.locationId ? 'btn.add' : 'btn.edit' | i18nFilter"
    :visible.sync="visible"
  >
    <el-form ref="dataForm" :model="dataForm" label-width="130px" @keyup.enter.native="dataFormSubmit()">
      <el-form-item :label="$t('module.basicData.processLocation.sequence')" prop="sequence">
        <el-input v-model="dataForm.sequence" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.sequence')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.basicData.processLocation.workSequenId')" prop="workSequenId">
        <el-input v-model="dataForm.workSequenId" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.workSequenId')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.basicData.processLocation.locationName')" prop="locationName">
        <el-input v-model="dataForm.locationName" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.locationName')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.basicData.processLocation.locationId')" prop="locationId">
        <el-input v-model="dataForm.locationId" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.locationId')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.basicData.processLocation.isProcess')" prop="isProcess">
        <el-input v-model="dataForm.isProcess" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.isProcess')])" clearable />
      </el-form-item>
      <el-form-item :label="$t('module.basicData.processLocation.equipmentMark')" prop="equipmentMark">
        <el-input v-model="dataForm.equipmentMark" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.equipmentMark')])" 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 { detail, update, add } from '@/api/basicData/Cache/processLocation'

export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        sequence: '',
        locationName: '',
        isProcess: '',
        equipmentMark: ''
      },
      listQuery: {
        current: 1,
        size: 10,
        locationId: '',
        workSequenId: '',
        locationName: ''
      }
    }
  },
  methods: {
    init(LocationId) {
      this.listQuery.LocationId = LocationId || ''
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.listQuery.LocationId) {
          // list(this.listQuery).then(res =>{
          //   this.list = response.data.records
          // })
          detail(this.dataForm.id).then(res => {
            this.dataForm = res.data
          })
        } else {
          // storageBoxCode().then(res => {
          //   this.dataForm.code = res.data
          // })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const data = this.dataForm
          data.id = this.dataForm.id
          if (this.dataForm.id) {
            update(data).then(res => {
              this.$message({
                message: this.$t('module.basicData.visual.success'),
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            })
          } else {
            add(data).then(res => {
              this.$message({
                message: this.$t('module.basicData.visual.success'),
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            })
          }
        }
      })
    }
  }
}
</script>
