廖井涛
2024-04-25 ed6f35069824d71ee6da599a328d865eb0c58550
north-glass-erp/northglass-erp/src/views/pp/processCard/AddProcessCard.vue
New file
@@ -0,0 +1,781 @@
<script setup>
import request from "@/utils/request"
import deepClone from "@/utils/deepClone"
import {ElDatePicker, ElMessage} from "element-plus"
import useProductGlassTypeStore from "@/stores/sd/product/productGlassType"
import {nextTick, onMounted, onUnmounted, reactive, ref, watch} from "vue"
import {ArrowLeftBold, Search} from "@element-plus/icons-vue"
import GlassType from "@/components/sd/product/GlassType.vue"
import {useRouter} from 'vue-router'
import Sortable from 'sortablejs'
import BasicTable from '@/components/sd/product/BasicTable.vue'
import {VXETable} from "vxe-table";
import useUserInfoStore from "@/stores/userInfo";
import { useI18n } from 'vue-i18n'
//语言获取
const { t } = useI18n()
let productGlassTypeStore = useProductGlassTypeStore()
let router = useRouter()
const userStore = useUserInfoStore()
const username = userStore.user.userName
const getTableRow = (row, type) => {
  switch (type) {
    case 'edit' : {
      router.push({path: '/main/processCard/PrintFlowCard', query: {id: row.id}})
      break
    }
    case 'setType': {
      alert('我接收到子组件传送的删除信息')
      break
    }
    case 'delete': {
      request.post(`/processCard/deleteFlowCard/${row.orderId}/${row.processId}`).then((res) => {
        if (res.code == 200) {
          ElMessage.success(t('workOrder.deleteOk'))
          location.reload();
        } else {
          ElMessage.warning(res.msg)
         // router.push("/login")
        }
      })
      break
    }
  }
}
let flag = $ref(true)
function intoCreateProduct() {
  if (flag) {
    router.push(`/main/processCard/SplittingDetails?orderId=${orderId}`)
  } else {
    router.push('/main/processCard/SplittingDetails?orderId=${orderId}')
  }
  flag = !flag
}
//定义时间
const form = reactive({
  date1: '',
})
//表尾求和
const sumNum = (list, field) => {
  let count = 0
  list.forEach(item => {
    count += Number(item[field])
  })
  return count.toFixed(2)
}
//定义滚动条高度
let scrollTop = ref(null)
let scrollHeight = ref(null)
let clientHeight = ref(null)
const scrollEvnt = (row) => {
  // 内容高度
  scrollTop.value = row.$event.target.scrollTop
  scrollHeight.value = row.$event.target.scrollHeight
  clientHeight.value = row.$event.target.clientHeight
}
//筛选条件,有外键需要先定义明细里面的数据
let filterData = ref({})
//定义页面总页数
let pageTotal = ref('')
//定义数据返回结果
let produceList = ref([])
//定义当前页数
let pageNum = $ref(1)
let pageState = null
const {currentRoute} = useRouter()
const route = currentRoute.value
let orderId = route.query.orderId
let productionId = route.query.productionId
//第一次加载数据
request.post(`/processCard/selectNoCard/${orderId}/${productionId}`, filterData.value).then((res) => {
  if (res.code == 200) {
    pageTotal.value = res.data.total
    produceList = produceList.value.concat(deepClone(res.data.data))
    xGrid.value.reloadData(produceList)
    gridOptions.loading = false
  } else {
    ElMessage.warning(res.msg)
  }
})
/*使用筛选,后端获取数据*/
const changeFilterEvent = (event, option, $panel,) => {
  // 手动触发筛选
  $panel.changeOption(event, !!option.data, option)
}
function padLeftZero(str) {
  return ('00' + str).substr(str.length)
}
/*后端返回结果多层嵌套展示*/
const hasDecimal = (value) => {
  const regex = /\./; // 定义正则表达式,查找小数点
  return regex.test(value); // 返回true/false
}
//筛选方法
const filterChanged = ({option, row, column}) => {
  if (option.data) {
    return row[column.field].toString().toLowerCase().indexOf(option.data) > -1
  }
  return true
  //@filter-change="filterChanged"
}
//右侧子组件接收参数
const xGrid = ref()
const gridOptions = reactive({
  border: "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe: true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true, height: 30},//鼠标移动或选择高亮
  id: 'CustomerList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY: {enabled: true},//开启虚拟滚动
  showOverflow: true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
                    //remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },//表头参数
  columns: [
    {type: 'checkbox', fixed: "left", title: t('basicData.check')},
    {
      field: 'orderNumber',
      title: t('order.OrderNum'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      filterMethod: filterChanged
    },
    {
      field: 'shape',
      title: t('order.shape'),
      showOverflow: "ellipsis",
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      filterMethod: filterChanged
    },
    {
      field: 'width',
      title: t('order.width'),
      sortable: true,
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      filterMethod: filterChanged,
      width: '60px'
    },
    {
      field: 'height',
      title: t('order.height'),
      sortable: true,
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      filterMethod: filterChanged,
      width: '60px'
    },
    {field: 'baiscQuantity', title: t('processCard.quantityToDivided'), showOverflow: "ellipsis", width: '60px'},
    {field: 'computeGrossArea', title: t('processCard.areaToDivided'), width: '60px'},
    {field: 'totalThickness', title: t('processCard.totalThickness'), width: '80px'},
    {field: 'thickness', title: t('processCard.glassThickness'), width: '60px'},
    {field: 'weight', title: t('processCard.weight')}
  ],//表头按钮
  toolbarConfig: {
    // buttons: [{
    //
    // }],
    // import: false,
    // export: true,
    // print: true,
    zoom: true,
    custom: true
  },
  data: [],//table body实际数据
  //脚部求和
  footerMethod({columns, data}) {//页脚函数
    let footList = ['', '', '', '', '']
    return [
      columns.map((column, columnIndex) => {
        if (columnIndex === 0) {
          return t('basicData.total')
        }
        if (footList.includes(column.field)) {
          return sumNum(data, column.field)
        }
        return ''
      })
    ]
  }
})
//左侧子组件接收参数
const xGridLeft = ref()
const gridLeftOptions = reactive({
  border: "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe: true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true, height: 30},//鼠标移动或选择高亮
  id: 'CustomerList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY: {enabled: true},//开启虚拟滚动
  showOverflow: true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
                    //remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },//表头参数
  columns: [
    {type: 'checkbox', fixed: "left", title: t('basicData.check')},
    {
      field: 'processId',
      title: t('processCard.processId'),
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      width: 130,
      filterMethod: filterChanged
    },
    {
      field: 'orderNumber',
      title: t('order.OrderNum'),
      showOverflow: "ellipsis",
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'}
      , filterMethod: filterChanged
    },
    {
      field: 'landingSequence',
      title: '落架顺序',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      filterMethod: filterChanged
    },
    {field: 'shape', title: t('order.shape'), filters: [{data: ''}], slots: {filter: 'num1_filter'}, filterMethod: filterChanged},
    {field: 'width', title: t('order.width'), showOverflow: "ellipsis"},
    {field: 'height', title: t('order.height')},
    {field: 'quantity', title: t('order.quantity')},
    {field: 'totalThickness', title: t('processCard.totalThickness')},
  ],//表头按钮
  toolbarConfig: {
    buttons: [
      {code: 'saveFlowCard', name: t('basicData.save'), status: 'primary', icon: 'vxe-icon-save'},
    ],
    // import: false,
    // export: true,
    // print: true,
    zoom: true,
    custom: true
  },
  data: [],//table body实际数据
  //脚部求和
  footerMethod({columns, data}) {//页脚函数
    let footList = ['']
    return [
      columns.map((column, columnIndex) => {
        if (columnIndex === 0) {
          return t('basicData.total')
        }
        if (footList.includes(column.field)) {
          return sumNum(data, column.field)
        }
        return ''
      })
    ]
  }
})
//定义输入数量
let checkedNum = ref('')
//创建流程卡
const createProcessCard = () => {
  const $grid = xGrid.value
  const checkedList = $grid.getCheckboxRecords()
  if (checkedList.length === 0) {
    ElMessage.warning(t('processCard.schedulingOk'))
    return
  }
  //productionId
  const $gridLeft = xGridLeft.value
  const leftData = $gridLeft.getTableData().fullData
  let index = 1
  if (leftData.length !== 0) {
    index = leftData[0].landingSequence + 1
    //index = index.toString().padStart(2, '0')
  }
  const processId = productionId + index.toString().padStart(3, '0')
  const regex = /^(\d+|)$/;
  if (!regex.test(checkedNum.value)) {
    ElMessage.warning(t('processCard.schedulingNo'))
    return
  }
  //判断正整数
  if (/^[1-9]\d*$/.test(checkedNum.value)) {
    checkedList.forEach((item) => {
      //定义key值保持
      //判断可用数量是否大于等于输入的数量,不满足则抛出异常
      if (item.baiscQuantity * 1 < checkedNum.value * 1) throw new Error(t('processCard.schedulingQuantity'));
      item.quantity =  checkedNum.value
      item.processId = processId
      item.landingSequence = index
      item.baiscQuantity=item.baiscQuantity - checkedNum.value
    })
    //删除key
    checkedList.forEach((item) => {
      let key = item._X_ROW_KEY
      delete item._X_ROW_KEY
      if (item.baiscQuantity===0){
        $grid.remove(checkedList)
      }
      $gridLeft.insertAt(checkedList)
      item._X_ROW_KEY = key
    })
//清除两边复选框
    $gridLeft.clearCheckboxRow()
    $grid.clearCheckboxRow()
  }
  else if (checkedNum.value === '') {//判断数量输入框无输入数字
    checkedList.forEach((item) => {
      item.processId = processId
      item.landingSequence = index
      item.quantity = item.baiscQuantity
    })
    //删除key
    checkedList.forEach((item) => {
      delete item._X_ROW_KEY
    })
    $gridLeft.insertAt(checkedList)
    $grid.remove(checkedList)
    //清除两边复选框
    $gridLeft.clearCheckboxRow()
    $grid.clearCheckboxRow()
  }
}
//向右边表格添加数据
const addRight = () => {
  try {
    //左边表格定义
    const $gridLeft = xGridLeft.value
    //右边表格定义
    const $grid = xGrid.value
    //获取左边表格checkbox选中的数据
    const checkedList = $gridLeft.getCheckboxRecords()
    //判断左边表格是否有选中的数据
    if (checkedList.length === 0) {
      ElMessage.warning(t('processCard.schedulingArea'))
      return
    }
    const regex = /^(\d+|)$/;
    if (!regex.test(checkedNum.value)) {
      ElMessage.warning(t('processCard.schedulingNo'))
      return
    }
    //判断正整数
    if (/^[1-9]\d*$/.test(checkedNum.value)) {
      //对选中的左边表格数据进行循环
      checkedList.forEach((item) => {
        //判断可用数量是否大于等于输入的数量,不满足则抛出异常
        if (item.quantity < checkedNum.value) throw new Error(t('processCard.schedulingQuantity'));
        //左边表格可用数量减去输入的数量
        item.quantity = item.quantity - checkedNum.value
        //右边表格数据
        let rightData = $grid.getTableData().fullData
        //右边表格数据中查找当前数据下标
        let filterIndex = rightData.findIndex(item1 => item1.orderNumber === item.orderNumber)
        //如果右边表格数据中存在当前数据则数量相加
        if (filterIndex >= 0) {
          rightData[filterIndex].baiscQuantity = rightData[filterIndex].baiscQuantity * 1 + checkedNum.value * 1
          //如果左边数量为0时删除此条数据
          if (item.quantity === 0) {
            $gridLeft.remove(item)
          }
        } else {
          //右边表格没有此条数据则往右边表格插入数据
          item.baiscQuantity = checkedNum.value
          if (item.quantity === 0) {
            $gridLeft.remove(item)
          }
          $grid.insert(item)
        }
      })
    } else if (checkedNum.value === '') {//判断数量输入框无输入数字
      checkedList.forEach((item) => {
        let rightData = $grid.getTableData().fullData
        let filterIndex = rightData.findIndex(item1 => item1.orderNumber === item.orderNumber)
        //无输入并且如果右边表格数据中存在当前数据则数量相加
        if (filterIndex > -1) {
          rightData[filterIndex].baiscQuantity = rightData[filterIndex].baiscQuantity * 1 + item.quantity * 1
        } else {
          delete item._X_ROW_KEY
          $grid.insert(item)
        }
        $gridLeft.remove(item)
      })
    }
    //清除两边复选框
    $gridLeft.clearCheckboxRow()
    $grid.clearCheckboxRow()
  } catch (e) {
    ElMessage.warning(e.message)
  }
}
//向左边表格添加数据
const addLeft = () => {
  try {
    //左边表格定义
    const $gridLeft = xGridLeft.value
    //右边表格定义
    const $grid = xGrid.value
    //获取右边表格checkbox选中的数据
    const checkedList = $grid.getCheckboxRecords()
    //获取左边表格checkbox选中的数据
    const checkedListLeft = $gridLeft.getCheckboxRecords()
    //判断右边表格是否有选中的数据
    if (checkedList.length * 1 === 0) {
      ElMessage.warning(t('processCard.schedulingOk'))
      return
    }
    if (checkedListLeft.length !== 1) {
      ElMessage.warning(t('processCard.schedulingTime'))
      return
    }
    const regex = /^(\d+|)$/;
    if (!regex.test(checkedNum.value)) {
      ElMessage.warning(t('processCard.schedulingNo'))
      return
    }
    //判断正整数
    if (/^[1-9]\d*$/.test(checkedNum.value)) {
      checkedList.forEach((item) => {
        //判断可用数量是否大于等于输入的数量,不满足则抛出异常
        if (item.baiscQuantity * 1 < checkedNum.value * 1) throw new Error("请输入小于等于待分数量的数字");
        item.baiscQuantity = item.baiscQuantity - checkedNum.value
        //定义key值保持
        let key = item._X_ROW_KEY
        //左边表格数据
        let leftData = $gridLeft.getTableData().fullData
        //左边表格数据中查找当前数据下标
        let filterIndex = leftData.findIndex(item1 => item1.orderNumber === item.orderNumber)
        //判断右侧勾选值与左侧是否相同
        if (checkedListLeft[0].orderNumber === item.orderNumber) {
          //如果右边表格数据中存在当前数据则数量相加
          if (filterIndex >= 0) {
            leftData[filterIndex].quantity = leftData[filterIndex].quantity * 1 + checkedNum.value * 1
            if (item.baiscQuantity === 0) {
              $grid.remove(checkedList)
            }
            //delete item._X_ROW_KEY
          } else {
            item.quantity = checkedNum.value
            item.processId = checkedListLeft[0].processId
            item.landingSequence = checkedListLeft[0].landingSequence
            delete item._X_ROW_KEY
            $gridLeft.insert(item)
            item._X_ROW_KEY = key
          }
        } else {
          //如果勾选两个值不同则插入同流程卡
          item.quantity = checkedNum.value
          item.processId = checkedListLeft[0].processId
          item.landingSequence = checkedListLeft[0].landingSequence
          if (item.baiscQuantity === 0) {
            $grid.remove(checkedList)
          }
          for (let i = 0; i < leftData.length; i++) {
            if (leftData[i].orderNumber === item.orderNumber && leftData[i].processId === item.processId) {
              leftData[i].quantity = leftData[i].quantity * 1 + checkedNum.value * 1
              break
            } else if (leftData[i].orderNumber === item.orderNumber && leftData[i].processId !== item.processId) {
              delete item._X_ROW_KEY
              $gridLeft.insert(item)
              item._X_ROW_KEY = key
              break
            }
            else if (leftData[i].orderNumber !== item.orderNumber && leftData[i].processId !== item.processId) {
              delete item._X_ROW_KEY
              $gridLeft.insert(item)
              item._X_ROW_KEY = key
              break
            }
          }
        }
      })
    } else if (checkedNum.value === '') {//判断数量输入框无输入数字
      checkedList.forEach((item) => {
        item.processId = checkedListLeft[0].processId
        item.landingSequence = checkedListLeft[0].landingSequence
        item.quantity = checkedListLeft[0].baiscQuantity
        delete item._X_ROW_KEY
      })
      $gridLeft.insertAt(checkedList)
      $grid.remove(checkedList)
    }
    //清除两边复选框
    if ($gridLeft || $grid) {
      $gridLeft.clearCheckboxRow()
      $grid.clearCheckboxRow()
    }
  } catch (e) {
    ElMessage.warning(e.message)
  }
}
//保存流程卡数据
const gridEvents = {
  toolbarButtonClick({code}) {
    const $grid = xGridLeft.value
    if ($grid) {
      switch (code) {
        case 'saveFlowCard': {
          const $table = xGridLeft.value
          const $tableRight = xGrid.value
          if ($table) {
            const selectRecords = $table.getCheckboxRecords()
          //  const selectRight = $tableRight.getCheckboxRecords()
            let leftData = $tableRight.getTableData().fullData
            if (selectRecords.length === 0) {
              ElMessage.warning("请先选择保存的数据")
              return
            }
            if (leftData.length > 0) {
              ElMessage.warning("请先将右侧数据全部建立流程卡后保存")
              return;
            }
            let flowCardData = ref({
              flowCard: selectRecords,
              userName: username,
              productionId: productionId
            })
            request.post("/processCard/addFlowCard", flowCardData.value).then((res) => {
              if (res.code == 200) {
                ElMessage.success("保存成功")
                //router.push('/main/processCard/SplittingDetails?orderId=${orderId}')
                router.push({
                  path: '/main/processCard/AddProcessCard',
                  query: {orderId: orderId, productionId: productionId, random: Math.random()}
                })
                //location.reload();
              } else {
                ElMessage.warning(res.msg)
              }
            })
          }
          return;
        }
      }
    }
  },
}
</script>
<template>
  <div style="width: 100%;height: 100%">
    <div class="common-layout" style="width: 100%;height: 100%">
      <div class="header" style="height: 5%;width: 100%">
        <el-button
            id="searchButton1"
            :icon="ArrowLeftBold"
            round
            style="float: left"
            type="primary"
            @click="intoCreateProduct">
          {{ flag ? t('processCard.return') : t('processCard.return') }}
        </el-button>
        <!--      <el-button  type="primary">保存分架</el-button>-->
        <!--              <el-button type="primary" :hidden="true">分架汇总</el-button>-->
        <div style="width: 100px;">
        </div>
      </div>
      <el-container style="height: 100%;width: 100%">
        <el-aside style="width: 44%;height: 100%">
          <vxe-grid
              ref="xGridLeft"
              class="mytable-scrollbar"
              max-height="100%"
              height="650px"
              v-bind="gridLeftOptions"
              v-on="gridEvents"
          >
            <!--      @toolbar-button-click="toolbarButtonClickEvent"-->
            <!--      下拉显示所有信息插槽-->
            <template #content="{ row }">
              <ul class="expand-wrapper">
                <li v-for="(item,index) in gridOptions.columns" v-show="item.field!=undefined ">
                  <span style="font-weight: bold">{{ item.title + ':  ' }}</span>
                  <span v-if="hasDecimal(item.field)">{{
                      row[item.field.split('.')[0]][item.field.split('.')[1]]
                    }}</span>
                  <span v-else>{{ row[item.field] }}</span>
                </li>
              </ul>
            </template>
            <template #num1_filter="{ column, $panel }">
              <div>
                <div v-for="(option, index) in column.filters" :key="index">
                  <input v-model="option.data"
                         type="text"
                         @input="changeFilterEvent($event, option, $panel)"/>
                </div>
              </div>
            </template>
          </vxe-grid>
        </el-aside>
        <div width="12%">
          <el-main style="">
            <span>{{$t('processCard.selectedQuantity')}}:<el-input v-model="checkedNum" clearable type="number"></el-input></span><br>
            <el-button type="primary" @click="addRight"> →</el-button>
            <br>
            <br>
            <el-button type="primary" @click="addLeft"> ←</el-button>
            <br>
            <br>
            <el-button type="primary" @click="createProcessCard">{{$t('processCard.establishProcessCards')}}</el-button>
          </el-main>
        </div>
        <!--        右侧-->
        <div style="height: 100%;width: 100%">
          <el-aside style="width: 100%;height: 100%">
            <vxe-grid
                ref="xGrid"
                class="mytable-scrollbar"
                max-height="100%"
                height="650px"
                v-bind="gridOptions"
            >
              <!--      @toolbar-button-click="toolbarButtonClickEvent"-->
              <!--      下拉显示所有信息插槽-->
              <template #content="{ row }">
                <ul class="expand-wrapper">
                  <li v-for="(item,index) in gridOptions.columns" v-show="item.field!=undefined ">
                    <span style="font-weight: bold">{{ item.title + ':  ' }}</span>
                    <span v-if="hasDecimal(item.field)">{{
                        row[item.field.split('.')[0]][item.field.split('.')[1]]
                      }}</span>
                    <span v-else>{{ row[item.field] }}</span>
                  </li>
                </ul>
              </template>
              <template #num1_filter="{ column, $panel }">
                <div>
                  <div v-for="(option, index) in column.filters" :key="index">
                    <input v-model="option.data"
                           type="text"
                           @input="changeFilterEvent($event, option, $panel)"/>
                  </div>
                </div>
              </template>
            </vxe-grid>
          </el-aside>
        </div>
      </el-container>
    </div>
  </div>
</template>
<style scoped>
.common-layout {
  height: 100%;
}
.header {
  width: 100%;
  height: 35px;
  margin-top: -20px;
}
.el-aside {
  height: 100%;
}
.el-main {
  height: 100%;
  text-align: center;
}
</style>