廖井涛
2025-02-18 b95bdc2199e991c4643814663a005c5e0e7d5048
north-glass-erp/northglass-erp/src/views/sd/order/CreateOrder.vue
@@ -1,5 +1,5 @@
<script lang="ts"  setup>
import {onMounted, reactive, ref, watch} from "vue"
import {nextTick, onMounted, reactive, ref, watch} from "vue"
import {useRouter,useRoute} from "vue-router"
import * as XLXS from "xlsx"
import {ElMessage, ElMessageBox} from "element-plus"
@@ -8,6 +8,8 @@
import  useUserInfoStore from '@/stores/userInfo'
import companyInfo from "@/stores/sd/companyInfo"
import SelectProduct from "@/views/sd/product/SelectProduct.vue"
import CreateProduct from "@/views/sd/product/CreateProduct.vue"
import CreateCustomer from "@/views/sd/customer/CreateCustomer.vue"
import OrderOtherMoney from "@/components/sd/order/OrderOtherMoney.vue"
import OrderSizeCheck from "@/components/sd/order/OrderSizeCheck.vue"
import {changeFilterEvent,filterChanged} from "@/hook"
@@ -134,7 +136,7 @@
  keyboardConfig:{
    isArrow: true,
    isDel: true,
    isEnter: true,
    //isEnter: true,
    isTab: true,
    isEdit: true,
    isChecked: true
@@ -143,7 +145,7 @@
    trigger: 'dblclick',
    mode: 'cell',
    showStatus: true,
    showIcon:false
    showIcon:false,
  },//表头参数
  columns:[
    {type: 'seq',fixed:"left", title: t('basicData.Number'), width: 80 },
@@ -323,11 +325,10 @@
            return
          }
          /*const project = titleUploadData.value.project
          if(project === null || project === undefined || project === ''){
            ElMessage.error(t('order.msg.projectCheck'))
            return
          }*/
          const project = titleUploadData.value.project
          if(project === null || project === undefined ){
            titleUploadData.value.project=''
          }
          const customer = titleUploadData.value.customerId
          if(customer === null || customer === undefined || customer === ''){
            ElMessage.error(t('order.msg.customerCheck'))
@@ -735,7 +736,7 @@
//初始化判断是否有id传入
onMounted(async ()=>{
  gridOptions.loading = true
  await initOrder()
  await initOrder(0)
  //启用表格拖动选中
  addListener(xGrid.value,gridOptions)
@@ -754,6 +755,8 @@
  request.post(`/order/getOrderById/${str}`).then((res) => {
    if(res.code==200){
      titleUploadData.value = res.data.order
      const customer = titleSelectJson.value.customer.filter(item => item.id === titleUploadData.value.customerId)
      projects.value = customer[0].projectList
      newOrderId.value=titleUploadData.value.orderId
      if(history.state.orderId!=null){
        titleUploadData.value.orderId=''
@@ -885,47 +888,48 @@
//页面第一次加载执行
const initOrder = async ()=>{
const initOrder = async (val)=>{
  await request.get(`/basicData/orderBasicData`).then((res) => {
    if(res.code==200){
      titleSelectJson.value=deepClone(res.data)
      //其他金额
      otherMoney.value = titleSelectJson.value.orderOtherMoney[0]
      //let columns = []
      otherMoney.value.forEach(item => {
        let column = {
          field: `otherColumns.${item.column}`,
          width:100,
          title: item.alias,
          editRender: {
            name: 'input',
      if(val===0){
        //其他金额
        otherMoney.value = titleSelectJson.value.orderOtherMoney[0]
        //let columns = []
        otherMoney.value.forEach(item => {
          let column = {
            field: `otherColumns.${item.column}`,
            width:100,
            title: item.alias,
            editRender: {
              name: 'input',
            }
          }
        }
        //判断  其他列是否是数字
        if(item.column.indexOf('M')>-1){
          gridOptions.editRules[`otherColumns.${item.column}`] = [
            {
              validator ({ cellValue }) {
                const regex = /^(0(\.\d{1,3})?|([1-9]\d{0,4})(\.\d{1,3})?|99999(\.9{1,3})?)$/
                if (cellValue && !regex.test(cellValue)) {
                  return new Error(t('basicData.msg.range99999Dec3'))
          //判断  其他列是否是数字
          if(item.column.indexOf('M')>-1){
            gridOptions.editRules[`otherColumns.${item.column}`] = [
              {
                validator ({ cellValue }) {
                  const regex = /^(0(\.\d{1,3})?|([1-9]\d{0,4})(\.\d{1,3})?|99999(\.9{1,3})?)$/
                  if (cellValue && !regex.test(cellValue)) {
                    return new Error(t('basicData.msg.range99999Dec3'))
                  }
                }
              }
            }
          ]
        }else{
          gridOptions.editRules[`otherColumns.${item.column}`] = [
            { required: false},
            { min: 0, max: 255, message: t('basicData.msg.max255') }
          ]
        }
            ]
          }else{
            gridOptions.editRules[`otherColumns.${item.column}`] = [
              { required: false},
              { min: 0, max: 255, message: t('basicData.msg.max255') }
            ]
          }
        //columns.push(column)
        gridOptions.columns.push(column)
          //columns.push(column)
          gridOptions.columns.push(column)
      })
        })
      }
      //进入页面下拉框设置默认值
      titleUploadData.value.orderType = titleSelectJson.value.orderType[0].basicName
      titleUploadData.value.orderClassify = titleSelectJson.value.orderClassify[0].basicName
@@ -1000,7 +1004,9 @@
  request.post(`/order/saveOrderTitle`,order).then((res) => {
    if(res.code==200){
      ElMessage.success(t('basicData.msg.saveSuccess'))
      router.push({path:'/main/order/selectOrder'})
      router.push({path:'/main/order/createOrder',query:{
          orderId:titleUploadData.value.orderId,
          random:Math.random()}})
    }else {
      ElMessage.error(res.msg)
    }
@@ -1114,6 +1120,20 @@
  reviewOrder(2)
}
let projects = ref([])
const changeProject = (item) => {
  if(typeof item === 'string'){
    titleUploadData.value.project = item
    return
  }
  titleUploadData.value.project = item.project
  titleUploadData.value.salesmanId = item.salesmanId
  titleUploadData.value.salesman = item.salesman
  titleUploadData.value.contacts = item.contacts
  titleUploadData.value.contactNumber = item.contactNumber
}
const changeCustomer =  () => {
  const changedCustomerId = titleUploadData.value.customerId
  const customer = titleSelectJson.value.customer.filter(item => item.id === changedCustomerId)
@@ -1121,12 +1141,15 @@
  titleUploadData.value.project = customer[0].project
  titleUploadData.value.salesmanId = customer[0].salesmanId
  titleUploadData.value.salesman = customer[0].salesman
  titleUploadData.value.contacts = customer[0].contacts
  titleUploadData.value.contactNumber = customer[0].contactNumber
  projects.value = customer[0].projectList
}
const changeSaleMan = () => {
  const changedSaleManId = titleUploadData.value.salesmanId
  const SaleMan = titleSelectJson.value.saleMan.filter(item => item.id === changedSaleManId)
  titleUploadData.value.salesman = SaleMan[0].basicName
  titleUploadData.value.salesman = SaleMan[0]['basicName']
}
const area = (row) => {
@@ -1252,7 +1275,6 @@
//行单元格修改修改触发此事件
const editClosedEvent = ({ row, column }) => {
  //判断修改相应的数值修改面积与金额
   if (['width', 'height', 'quantity', 'price'].includes(column.property)) {
     if(titleUploadData.value?.orderReview!==2){
@@ -1292,7 +1314,6 @@
   //   }
   // }
  titleUploadData.value.money=countMoney(xGrid.value.getTableData().fullData).toString()
}
@@ -1375,7 +1396,7 @@
}
//表格回车,在表格最后一行添加一行空数据
const handleKeyDown = (evnt) =>{
const handleKeyDown =async (evnt) =>{
  //判断表示是否为筛选状态
  if(xGrid.value.isFilter()){
    return
@@ -1387,13 +1408,50 @@
  }
  if(evnt.$event.keyCode === 13 ){
    const { rowIndex,row,column } = xGrid.value.getSelectedCell() || xGrid.value.getEditRecord()
    let nextRowIndex = xGrid.value.getRowIndex(row) + 1;
    if (nextRowIndex < xGrid.value.getTableData().fullData.length) {
    let nextRowIndex = xGrid.value.getRowIndex(row) + 1
    switch (column.field){
      case 'width':
        xGrid.value.setSelectCell(row, 'height')
        break;
      case 'height':
        xGrid.value.setSelectCell(row, 'quantity')
        break;
      case 'quantity':
        if(nextRowIndex === length){
          await editClosedEvent({row,column})
          xGrid.value.clearEdit()
          let rowNext = row
          delete rowNext._X_ROW_KEY
          xGrid.value.insertAt(rowNext, xGrid.value.getTableData.length || -1)
          //xGrid.value.insertAt({}, xGrid.value.getTableData.length || -1)
        }
        const nextRow = xGrid.value.getTableData().fullData[nextRowIndex]
        xGrid.value.setCurrentRow(nextRow)
        xGrid.value.scrollToRow(nextRow)
        xGrid.value.setSelectCell(nextRow, 'width')
        break;
      default:
        if(nextRowIndex === length){
          xGrid.value.insertAt({}, xGrid.value.getTableData.length || -1)
        }
        const nextRow1 = xGrid.value.getTableData().fullData[nextRowIndex]
        xGrid.value.setCurrentRow(nextRow1)
        xGrid.value.scrollToRow(nextRow1)
        xGrid.value.setSelectCell(nextRow1, column.field)
        break;
    }
    /*if (nextRowIndex < xGrid.value.getTableData().fullData.length) {
      xGrid.value.setCurrentRow(xGrid.value.getTableData().fullData[nextRowIndex]);
    }
    if(rowIndex === length-1){
      xGrid.value.insertAt({}, xGrid.value.getTableData.length || -1)
    }
    }*/
  }
  if(evnt.$event.keyCode === 38 ){
@@ -1418,6 +1476,27 @@
  xGrid.value.clearSelected()
}
//切换产品界面
const productFlag = ref(true)
const changeProduct = (val)=>{
  productFlag.value = val
}
const closeProductDialog = ()=>{
  productFlag.value = true
}
//改变产品页面切换
const changePage = () => {
  productFlag.value = true
}
// 创建客户显示
let createCustomerVisible = ref(false)
//创建客户成功返回方法
const createCustomerSuccess = async () => {
  await initOrder(1)
  createCustomerVisible.value = false
}
</script>
<template>
@@ -1425,7 +1504,18 @@
    <div class="order-primary" style="background-color: white">
      <el-row>
        <el-col  :span="2"><el-text>*{{$t('order.project')}}:</el-text></el-col>
        <el-col  :span="2"><el-input v-model.trim="titleUploadData.project"/></el-col>
        <el-col  :span="2">
<!--          <el-input v-model.trim="titleUploadData.project"/>-->
          <el-select v-model.trim="titleUploadData.project"
                     @change="changeProject"
                     clearable placeholder=" " allow-create  filterable >
            <el-option v-for="item in projects"
                       :label="item.project"
                       :value="item"/>
          </el-select>
        </el-col>
        <el-col  :span="2"><el-text>*{{$t('order.customers')}}:</el-text></el-col>
        <el-col  :span="2">
          <el-select  v-model="titleUploadData.customerId"
@@ -1438,6 +1528,11 @@
                       :label="item.id+' '+item.customerName"
                       :value="item.id"
                       />
            <template #footer>
              <el-button @click="createCustomerVisible=true"  text bg size="small" >
                {{$t('basicData.create')}}
              </el-button>
            </template>
          </el-select>
        </el-col>
        <el-col  :span="2"><el-text>*{{$t('order.orderType')}}:</el-text></el-col>
@@ -1587,15 +1682,30 @@
      </vxe-grid>
    </div>
    <el-dialog v-model="dialogTableVisible" :title="$t('order.processingNote')" style="width: 60%;height:75% ">
    <el-dialog v-model="dialogTableVisible" :draggable="true" :title="$t('order.processingNote')" style="width: 60%;height:75% ">
      <el-input
          v-model="titleUploadData.processingNote"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 20 }"
      />
    </el-dialog>
    <el-dialog id="product" v-model="productVisible"  style="width: 80%;height:75% ">
      <select-product :rowIndex="rowIndex" @getProductRow="getProductRow" style="width: 100%;height: 100%" />
    <el-dialog id="product"
               class="product1"
               v-model="productVisible"
               @closed="closeProductDialog"
               :destroy-on-close="true"
               style="width: 80%;height:75%; ">
      <template #header >
        <div class="my-header">
        <el-button @click="changeProduct(true)">{{$t('basicData.search')}}</el-button>
        <el-button @click="changeProduct(false)">{{$t('basicData.create')}}</el-button>
        </div>
      </template>
      <select-product v-if="productFlag" :rowIndex="rowIndex" @getProductRow="getProductRow" style="width: 100%;height: 100%" />
      <create-product v-else
                      :productFlag="productFlag"
                      @changePage="changePage"
                      style="text-align: left;background-color: #D5EAFF;"/>
    </el-dialog>
<!--误差结算-->
    <el-dialog v-model="errorAreaVisible"  style="width: 300px;height:150px ">
@@ -1647,7 +1757,18 @@
          @getParent="gaveOrderSizeCheck"
          :orderId="titleUploadData.orderId"
          :OrderDetail="xGrid"/>
<!--      <create-customer/>-->
    </el-dialog>
    <!--    客户创建窗口-->
    <el-dialog
        id="createCustomer"
        :title="$t('customer.page.createCustomer')"
        v-model="createCustomerVisible"
        style="width: 700px;height:445px;text-align: left "
    >
      <create-customer :getOrderPage="'order'" @getOrderFunction="createCustomerSuccess" />
    </el-dialog>
  </div>
</template>
@@ -1661,7 +1782,7 @@
  .el-col{
    border: #181818 1px solid;
  }
  :deep(.el-input__wrapper) {
  :deep(.order-primary .el-input__wrapper) {
    box-shadow: 0 0 0 0 var(--el-input-border-color, var(--el-border-color)) inset;
    cursor: default;
    border: none !important;
@@ -1687,9 +1808,13 @@
    width: 100%;
  }
  :deep(#sizeCheck .el-dialog__body){
  :deep(#sizeCheck .el-dialog__body,#createCustomer .el-dialog__body){
    height: 90%;
    width: 100%;
  }
  .my-header {
    display: flex;
    /*flex-direction : row;
    justify-content: space-between;*/
  }
</style>