<!--
 * @Descripttion:
 * @version:
 * @Author: fzq
 * @Date: 2022-03-04 11:12:42
 * @LastEditors: fzq
 * @LastEditTime: 2022-03-09 16:12:04
-->
<template>
  <el-dialog
    :title="!dataForm.id ? '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.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.locationId" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.locationName')])" clearable />
      </el-form-item> -->
      <el-form-item :label="$t('module.basicData.processLocation.locationName')" prop="locationName">
        <el-select v-model="dataForm.locationName" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.locationName')])">
          <el-option
            v-for="item in dataForm"
            :key="item.locationName"
            :label="item.locationName"
            :value="item.locationName"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('module.basicData.processLocation.portAttrId')" prop="portAttrId">
        <el-input v-model="dataForm.portAttrId" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.portAttrId')])" 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.isProcess')" prop="isProcess">
        <el-select v-model="dataForm.isProcess" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.isProcess')])">
          <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.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-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.goodsShelves')" prop="goodsShelves">
        <el-input v-model="dataForm.goodsShelves" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.goodsShelves')])" clearable />
      </el-form-item> -->
      <el-form-item :label="$t('module.basicData.processLocation.goodsShelves')" prop="goodsShelves">
        <el-select v-model="dataForm.goodsShelves" :placeholder="$i18nForm(['placeholder.input', $t('module.basicData.processLocation.goodsShelves')])">
          <el-option
            v-for="item in options2"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </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, locationList } from '@/api/basicData/Cache/processLocation'

export default {
  data() {
    return {
      visible: false,
      dataForm: {
        workSequenId: '',
        locationId: '',
        portAttrId: '',
        isProcess: '',
        equipmentMark: '',
        sequence: '',
        goodsShelves: '',
        locationName: ''
      },
      options: [
        {
          value: 0,
          label: this.$t('module.basicData.processLocation.CacheLocation')
        },
        {
          value: 1,
          label: this.$t('module.basicData.processLocation.ProcessLocation')
        }
      ],
      options2: [
        {
          value: 0,
          label: this.$t('module.basicData.processLocation.aShelf')
        },
        {
          value: 1,
          label: this.$t('module.basicData.processLocation.bShelf')
        }
      ],
      // options3: [
      //   {
      //     value: this.dataForm.locationId,
      //     label: this.dataForm.locationName
      //   }
      // ],
      listQuery: {
        id: ''
      }
    }
  },
  methods: {
    init(id) {
      this.listQuery.id = id || ''
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        locationList().then(res => {
          // console.log(res)
          // this.dataForm.locationId = res.data.id'
          for (var i = 0; i < res.data.length; i++) {
            this.dataForm.locationId = res.data[i].id
            this.dataForm.locationName = res.data[i].locationName
          }
          // console.log(this.dataForm)
        })
        // portAttrList().then(res => {
        //   console.log(res)
        // })
        // workSequenList().then(res => {
        //   console.log(res)
        // })
        // console.log(this.listQuery)
        if (this.listQuery.id) {
          // list(this.listQuery).then(res =>{
          //   this.list = response.data.records
          // })
          detail(this.listQuery.id).then(res => {
            this.dataForm.equipmentMark = res.data.equipmentMark
            this.dataForm.goodsShelves = res.data.goodsShelves
            this.dataForm.id = res.data.id
            this.dataForm.isProcess = res.data.isProcess
            this.dataForm.portAttrId = res.data.portAttrId
            this.dataForm.sequence = res.data.sequence
            this.dataForm.workSequenId = res.data.workSequenId
            console.log(this.dataForm)
          })
        } 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>
