<template>
  <el-dialog
    :model-value="isShow"
    title="产品工艺流程"
    destroy-on-close
    :before-close="()=>{emits('destroy')}"
    style="width: 80vw; height: 80vh"
  >
    <el-form
      inline
      label-position="left"
      @submit.native.prevent
    >
      <el-form-item
        label="工单编号"
      >
        <el-input
          v-model="input"
          style="width: 120px;"
          @keyup.enter="handleShowDetail"
          placeholder="Enter回车"
        />
      </el-form-item>

      <el-table
        :data="detailData"
        border
        height="50vh"
        :row-style="{ height: '20px' }"
        :cell-style="{ padding: '0px' }"
        :header-row-style="{ height: '20px' }"
        :header-cell-style="{ padding: '0px' }"
      >
        <el-table-column
          label="印件及工序"
          width="100"
          prop="Gy0_yjno"
        />

        <el-table-column
          label="工序名称"
          width="300"
          prop="Gy0_gxmc"
        />

        <el-table-column
          label="基础损耗"
          width="100"
          prop="Gy0_rate0"
        />

        <el-table-column
          label="损耗率"
          width="100"
          prop="Gy0_rate1"
        />

        <el-table-column
          label="损耗系数"
          width="100"
          prop="损耗系数"
        />
        <el-table-column
          label="无形损减免比例"
          width="150"
        >
          <template #default="{ row }">
            <el-input v-model="row['loss_one']" />
          </template>
        </el-table-column>
        <el-table-column
          label="超节损承担比例"
          width="150"
        >
          <template #default="{ row }">
            <el-input v-model="row['loss_two']" />
          </template>
        </el-table-column>
        <el-table-column
          label="超节损核算单价"
          width="150"
        >
          <template #default="{ row }">
            <el-input v-model="row['loss_thr']" />
          </template>
        </el-table-column>

      </el-table>

    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="()=>{emits('destroy')}">取 消</el-button>
        <el-button
          type="primary"
          @click="handleUpdateDatail"
        >更 新
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: 'Detail',
}
import service from '@/utils/request'
// 3.1查改-获取工单工艺流程
const getOrderGy = (params) => {
  return service({
    url: '/mes_server/order_super_loss/getOrderGy',
    method: 'get',
    params
  })
}

// 3.2查改-更新产品工艺资料
const updateOrderGy = (data) => {
  return service({
    url: '/mes_server/order_super_loss/updateOrderGy',
    method: 'post',
    data
  })
}

</script>
<script setup>

import { defineEmits, defineProps, ref } from 'vue'
import { ElMessage } from 'element-plus'

const props = defineProps({
  isShow: {
    type: Boolean,
    default: false,
  },
  gdbh: {
    type: String,
    default: '',
  },
})
const emits = defineEmits(['destroy'])
const detailData = ref([])
const input = ref(props['gdbh'])

const handleShowDetail = async() => {
  if (!input.value) {
    ElMessage({
      type: 'info',
      message: '请输入工单编号',
    })
    return
  }
  const res = await getOrderGy({ order: input.value })
  if (res['code'] === 0) {
    const { data } = res
    detailData.value = data.map(item => ({
      ...item,
      Gy0_yjno: item['Gy0_yjno'] + '-' + item['Gy0_gxh'],
    }))
  }
}
const handleUpdateDatail = async() => {
  const val = detailData.value.map(item => ({
    UniqId: item['UniqId'],
    loss_one: item['loss_one'],
    loss_two: item['loss_two'],
    loss_thr: item['loss_thr'],
  }))
  const res = await updateOrderGy(val)
  if (res['code'] === 0) {
    ElMessage({
      type: 'success',
      message: '更新成功',
    })
  }
}

</script>

<style scoped>
</style>
