From 3aedad63dd01f1fc5154cb520af32edab967d6e0 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周一, 12 5月 2025 09:15:26 +0800
Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/HIA24016N_PipeLineDemo

---
 PipeLineLems/pipelinelems_web/src/widgets/OrderManagement-main/dialog/productForm.vue |  383 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 383 insertions(+), 0 deletions(-)

diff --git a/PipeLineLems/pipelinelems_web/src/widgets/OrderManagement-main/dialog/productForm.vue b/PipeLineLems/pipelinelems_web/src/widgets/OrderManagement-main/dialog/productForm.vue
new file mode 100644
index 0000000..48f6a67
--- /dev/null
+++ b/PipeLineLems/pipelinelems_web/src/widgets/OrderManagement-main/dialog/productForm.vue
@@ -0,0 +1,383 @@
+<template>
+  <div class="dialog-container">
+    <BaseDrawer
+      v-model="dialogVisible"
+      :title="_t(title)"
+      width="689px"
+      @close="onClose"
+      @confirm="onConfirm"
+      :before-close="beforeClose"
+    >
+      <div class="dialog-content">
+        <HeadTitle :title="_t('鍩虹淇℃伅')" />
+        <div
+          class="customFormItem-container"
+          v-for="item in form"
+          :key="item.prop"
+        >
+          <CustomFormItem
+            v-model="item.value"
+            :label="item.label"
+            :component-name="item.componentName"
+            label-width="120px"
+            source="productForm"
+            inputWidth="480px"
+            v-bind="{ ...item.attrProps }"
+            :placeholder="_t(item.attrProps.placeholder)"
+            @change="onChange($event, item)"
+          >
+            <template v-if="item.componentName === 'el-select'">
+              <el-option
+                v-for="o in item.nodeOptions"
+                :key="o.id"
+                :label="o.model"
+                :value="o.id"
+              />
+            </template>
+          </CustomFormItem>
+        </div>
+      </div>
+      <!-- 
+      <template #footer>
+        <span class="dialog-footer">
+          <el-button
+            @click="dialogVisible = false"
+            class="baseCss"
+            style="background: #efeded"
+          >
+            鍙栨秷
+          </el-button>
+          <el-button
+            type="primary"
+            @click="onConfirm"
+            class="baseCss"
+            style="background: #5a84ff"
+          >
+            纭畾
+          </el-button>
+        </span>
+      </template> -->
+    </BaseDrawer>
+  </div>
+</template>
+
+<script lang="ts">
+import {
+  PropType,
+  defineComponent,
+  computed,
+  ref,
+  provide,
+  reactive,
+} from 'vue'
+import { useVModel } from '@vueuse/core'
+import api from '../api/product-setting'
+import type { IProductParamsRequest } from '../api/product'
+import { get, head, set } from 'lodash'
+import { ElMessage } from 'element-plus'
+import { getEnum } from '../enum'
+const { DIALOG_STATUS, DIALOG_STATUS_OPTIONS } = getEnum()
+import CustomFormItem from '../components/customFormItem/index.vue'
+import HeadTitle from '../components/head-title/index.vue'
+import Dialog from '../../../components/Dialog/index.vue'
+import BaseDrawer from '@/components/BaseDrawer/BaseDrawer'
+import isEqual from 'lodash/isEqual'
+import cloneDeep from 'lodash/cloneDeep'
+import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
+import { _t } from '../app'
+
+export default defineComponent({
+  name: 'ProductFormDialog',
+  components: { Dialog, CustomFormItem, HeadTitle, BaseDrawer },
+  props: {
+    modelValue: {
+      type: Boolean,
+      default: false,
+    },
+    status: {
+      type: String,
+      default: DIALOG_STATUS.ADD,
+    },
+    dialogConfig: {
+      type: Object as PropType<IProductParamsRequest>,
+    },
+  },
+
+  setup(props, ctx) {
+    const dialogVisible = useVModel(props)
+    const dialogTableVisible = ref(false)
+    const isEdit = computed(
+      () =>
+        props.status === DIALOG_STATUS.EDIT ||
+        props.status === DIALOG_STATUS.PAUSED
+    )
+    const title = computed(
+      () =>
+        DIALOG_STATUS_OPTIONS.find((item) => item.value === props.status)?.label
+    )
+    const form = reactive<Record<string, any>[]>([
+      {
+        label: _t('宸ュ崟鍙凤細'),
+        prop: 'code',
+        value: '',
+        attrProps: { placeholder: _t('璇疯緭鍏�'), disabled: isEdit.value },
+        componentName: 'el-input',
+      },
+      {
+        label: _t('浜у搧鍨嬪彿锛�'),
+        prop: 'productId',
+        value: '',
+        attrProps: { placeholder: _t('璇疯緭鍏�'), disabled: isEdit.value },
+        nodeOptions: [] as { id: string; model: string }[],
+        componentName: 'el-select',
+      },
+      {
+        label: _t('宸ヨ壓閰嶆柟锛�'),
+        prop: 'formulaId',
+        value: '',
+        attrProps: { placeholder: _t('璇疯緭鍏�'), disabled: true },
+        nodeOptions: [] as { id: string; model: string }[],
+        componentName: 'el-select',
+      },
+      {
+        label: _t('璁″垝鏁伴噺锛�'),
+        prop: 'planQty',
+        value: '',
+        attrProps: {
+          placeholder: _t('璇疯緭鍏�'),
+          maxlength: '15',
+          'show-word-limit': true,
+        },
+        componentName: 'el-input',
+
+        formatter: (value: string) => {
+          return Number(value)
+        },
+      },
+      {
+        label: _t('璁″垝寮�濮嬫椂闂达細'),
+        prop: 'planStartTime',
+        value: '',
+        attrProps: {
+          placeholder: _t('璇疯緭鍏�'),
+          type: 'datetime',
+          valueFormat: 'YYYY-MM-DD HH:mm',
+        },
+        componentName: 'el-date-picker',
+      },
+      {
+        label: _t('璁″垝缁撴潫鏃堕棿锛�'),
+        prop: 'planFinishTime',
+        value: '',
+        attrProps: {
+          placeholder: _t('璇疯緭鍏�'),
+          type: 'datetime',
+          valueFormat: 'YYYY-MM-DD HH:mm',
+        },
+        componentName: 'el-date-picker',
+      },
+    ])
+    const prodList = ref([])
+    const formList = ref([])
+    const onChange = async (value: unknown, item: unknown) => {
+      console.log(value, item)
+      // TO-DO 淇敼key 鍊�
+      const prop = get(item, 'prop')
+      if (prop === 'productId') {
+        const formulaIndex = form.findIndex((item) => item.prop === 'formulaId')
+        const versionIndex = form.findIndex(
+          (item) => item.prop === 'formulaVersionId'
+        )
+
+        // 鍏堝皢鍊兼竻绌�
+        set(form[formulaIndex], 'value', '')
+        set(form[versionIndex], 'value', '')
+
+        // 鏍规嵁鍨嬪彿鑾峰彇鐨勫伐鑹洪厤鏂� 鍙湁涓�涓厤鏂癸紱澶氫釜鐗堟湰
+        const list = await api.getFormula(value as string)
+        formList.value = list
+        let result = list.map((item) => ({
+          ...item,
+          model: item.name,
+          value: item.id,
+        }))
+        const completeFormula = head(result)
+        console.log('completeFormula', completeFormula)
+        // 缁欏伐鑹洪厤鏂硅祴鍊�
+        set(form[formulaIndex], 'nodeOptions', result)
+        // @ts-ignore
+        set(form[formulaIndex], 'value', completeFormula.id)
+      }
+    }
+    const initiateData = ref<any>({})
+
+    async function init() {
+      const result: any = await api.getModelOptions()
+      prodList.value = result.items
+      const key = 'productId'
+      const index = form.findIndex((item) => item.prop === key)
+      set(
+        form[index],
+        'nodeOptions',
+        result.items.map((item: any) => ({
+          ...item,
+          label: item.model,
+          value: item.id,
+        }))
+      )
+      console.log(result, 'result')
+      if (isEdit.value) {
+        form.forEach((item) => {
+          console.log('result222', props.dialogConfig, item.prop)
+          if (item.prop == 'productId') {
+            // @ts-ignore
+            item.value = props.dialogConfig.product.id
+            // @ts-ignore
+            onChange(props.dialogConfig.product.id, item)
+          } else if (item.prop == 'formulaId') {
+            // @ts-ignore
+            item.value = props.dialogConfig.formula.id
+          } else {
+            // @ts-ignore
+            item.value = props.dialogConfig[item.prop]
+          }
+        })
+      }
+
+      initiateData.value = cloneDeep(form)
+    }
+
+    init()
+
+    const onConfirm = async () => {
+      const emptyList = form.filter((item) => !item.value)
+      if (emptyList.length) {
+        const item = head(emptyList)!.label
+        const msg = item.replace(/:$/, '')
+
+        ElMessage.error(`${msg}${_t('瀛楁涓嶈兘涓虹┖')}`)
+        return
+      }
+
+      const params = form.reduce(
+        (obj, item) => ({
+          ...obj,
+          [item.prop]: item.formatter ? item.formatter(item.value) : item.value,
+        }),
+        {}
+      )
+
+      if (!/^[1-9][0-9]*$/.test(params.planQty)) {
+        ElMessage.error(_t(`璁″垝鏁伴噺璇疯緭鍏ユ鏁存暟`))
+        return
+      }
+
+      // 棰濆澶勭悊- 鎼哄甫鐗堟湰鍙峰悕绉�
+
+      // @ts-ignore
+      if (isEdit.value) {
+        // @ts-ignore
+        params['concurrencyStamp'] = get(
+          props,
+          'dialogConfig.concurrencyStamp',
+          ''
+        )
+      }
+      // @ts-ignore
+      console.log(prodList.value, formList.value)
+      // @ts-ignore
+      params.product = prodList.value.find((_: any) => _.id == params.productId)
+      // @ts-ignore
+      params.formula = formList.value.find((_: any) => _.id == params.formulaId)
+
+      console.log('params', params)
+      const methodApi = isEdit.value ? api.updateOrder : api.addOrder
+      const id = get(props, 'dialogConfig.id', '')
+      // await api.addOrder(params)
+      //   @ts-ignore
+      const result = await methodApi(params, id)
+      const msg = isEdit.value ? _t('鏇存柊') : _t('鏂板')
+      ElMessage.success(`${msg}${_t('鎴愬姛')}`)
+
+      ctx.emit('callback')
+    }
+
+    const checkIsEqualObject = () => {
+      const check = isEqual(initiateData.value, form)
+      console.log(initiateData.value, form, check)
+      return check
+    }
+
+    const beforeClose = (done: () => void) => {
+      console.log('beforeClose')
+      if (dialogVisible.value) {
+        if (checkIsEqualObject()) {
+          dialogVisible.value = false
+          done && done()
+        } else {
+          ConfirmBox(_t('鏄惁淇濆瓨宸ュ崟璁剧疆锛�'))
+            .then(() => {
+              onConfirm()
+            })
+            .catch(() => {
+              dialogVisible.value = false
+              done && done()
+            })
+        }
+      }
+    }
+    const onClose = () => {
+      console.log('onClose')
+      dialogVisible.value = false
+    }
+
+    return {
+      dialogVisible,
+      dialogTableVisible,
+      title,
+      isEdit,
+      form,
+      _t,
+      isEqual,
+      onChange,
+      onConfirm,
+      checkIsEqualObject,
+      beforeClose,
+      onClose,
+      ConfirmBox,
+    }
+  },
+})
+</script>
+
+<style lang="scss" scoped>
+@import '../styles/input.scss';
+
+.dialog-content {
+  overflow-y: scroll;
+  overflow-x: hidden;
+}
+
+.baseCss {
+  width: 98px;
+  height: 26px;
+}
+
+.customFormItem-container {
+  width: 100%;
+  margin-top: 10px;
+  .customFormItem {
+    .label-content {
+      color: #666;
+    }
+  }
+
+  :deep(.cs-input__wrapper) {
+    display: flex;
+  }
+}
+</style>
+
+<style lang="scss">
+@import url('../styles/common.scss');
+</style>

--
Gitblit v1.9.3