<!--
 * @Author: zwq
 * @Date: 2020-12-29 16:37:56
 * @LastEditors: zwq
 * @LastEditTime: 2022-03-16 14:17:37
 * @Description:
-->
<template>
  <el-dialog
    :title="'btn.see' | i18nFilter"
    :visible.sync="visible"
    width="70%"
  >
    <el-row :gutter="10">
      <el-form
        ref="dataForm"
        :model="dataForm"
        size="medium"
        label-width="180px"
        label-position="left"
      >
        <el-col :span="8">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.OrderName')" prop="name">
                <el-input v-model="dataForm.name" :placeholder="$t('module.basicData.Warehouse.OrderName')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.OrderStatus')" prop="status">
                <el-input v-model="dataForm.status" :placeholder="$t('module.basicData.Warehouse.OrderStatus')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.PlanProcessQuantity')" prop="planQuantity">
                <el-input v-model="dataForm.planQuantity" :placeholder="$t('module.basicData.Warehouse.PlanProcessQuantity')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.Priority')" prop="priority">
                <el-input v-model="dataForm.priority" :placeholder="$t('module.basicData.Warehouse.Priority')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="8">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.OrderCode')" prop="code">
                <el-input v-model="dataForm.code" :placeholder="$t('module.basicData.Warehouse.OrderCode')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.startProduceTime')" prop="startProduceTime">
                <el-input v-model="dataForm.startProduceTime" :placeholder="$t('module.basicData.Warehouse.startProduceTime')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.actualProcessQuantity')" prop="actualQuantity">
                <el-input v-model="dataForm.actualQuantity" :placeholder="$t('module.basicData.Warehouse.actualProcessQuantity')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.triggerOrigin')" prop="triggerOrigin">
                <el-input v-model="dataForm.triggerOrigin" :placeholder="$t('module.basicData.Warehouse.triggerOrigin')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="8">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.TotalProcessName')" prop="craftName">
                <el-input v-model="dataForm.craftName" :placeholder="$t('module.basicData.Warehouse.TotalProcessName')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.SubProcessName')" prop="subProccessName">
                <el-input
                  v-model="dataForm.subProccessName"
                  :placeholder="$t('module.basicData.Warehouse.SubProcessName')"
                  readonly
                  :style="{width: '100%'}"
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.scrapQuantity')" prop="scrapQuantity">
                <el-input v-model="dataForm.scrapQuantity" :placeholder="$t('module.basicData.Warehouse.scrapQuantity')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="$t('module.basicData.Warehouse.OrderType')" prop="type">
                <el-input v-model="dataForm.type" :placeholder="$t('module.basicData.Warehouse.OrderType')" readonly :style="{width: '100%'}" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ 'btn.cancel' | i18nFilter }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { ProcessInfoDetail } from '@/api/orderManage/00A'
import { timeFormatter } from '@/filters'

export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        name: undefined,
        priority: '',
        actualQuantity: '',
        startProduceTime: '',
        scrapQuantity: '',
        triggerOrigin: '',
        type: '',
        code: undefined,
        status: undefined,
        craftName: undefined,
        planQuantity: undefined,
        subProccessName: undefined
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || ''
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          ProcessInfoDetail(this.dataForm.id).then(res => {
            res.data.status = this.statusfilter('orderStatus', res.data.status)
            res.data.type = this.statusfilter('orderType', res.data.type)
            res.data.priority = this.statusfilter('priority', res.data.priority)
            res.data.triggerOrigin = this.statusfilter('triggerOrigin', res.data.triggerOrigin)
            res.data.startProduceTime = timeFormatter(res.data.startProduceTime)
            this.dataForm = res.data
          })
        }
      })
    },
    statusfilter(type, val) {
      const filterObj = {
        orderStatus: {
          '1': '未激活',
          '2': '等待',
          '3': '激活',
          '4': '暂停',
          '9': '完成'
        },
        priority: {
          '1': '低',
          '2': '正常',
          '3': '高'
        },
        orderType: {
          '1': '生产工单',
          '2': '重工工单',
          '3': '测试工单'
        },
        triggerOrigin: {
          '1': 'MES',
          '2': 'ERP',
          '3': 'PID1',
          '4': '00A',
          '5': '00C'
        }
      }
      return filterObj?.[type]?.[val]
    }
  }
}
</script>
