Эх сурвалжийг харах

feat: 通用化人员信息查找函数

cuiyalong 3 сар өмнө
parent
commit
b6614ec848

+ 5 - 2
src/views/create-order/components/schema-form/resort/index.js

@@ -97,7 +97,8 @@ export function sortOrderInfo(order = {}) {
       if (saleFinalList.length === 1) {
         const saleInfo = saleFinalList[0]
         if (saleInfo) {
-          const userInfo = findUserInDeptTree(saleInfo.name)
+          // const userInfo = findUserInDeptTree(saleInfo.name)
+          const userInfo = findUserInDeptTree((u) => u.name === saleInfo.name)
           if (userInfo && userInfo.id) {
             pageFormValue.salePerson = [userInfo.id]
           }
@@ -109,7 +110,8 @@ export function sortOrderInfo(order = {}) {
       } else {
         const salePerson = []
         pageFormValue.salePersonTableList = saleFinalList.map(sale => {
-          const userInfo = findUserInDeptTree(sale.name)
+          // const userInfo = findUserInDeptTree(sale.name)
+          const userInfo = findUserInDeptTree((u) => u.name === sale.name)
           const saleWay = calcChannelSelectorList(sale.distribution_channel)
           salePerson.push(userInfo?.id)
           return new SalePersonTableRow(sale.name, userInfo?.id, div(sale.money, 100), saleWay)
@@ -175,6 +177,7 @@ export function sortProductFormArr(type, product, order) {
     const common = sortCommonForm(product, order)
     const pForm = callback(product, order)
     Object.assign(map, common, pForm)
+    console.log(map, common , pForm)
   }
 
   return map

+ 11 - 5
src/views/create-order/hooks/utils.js

@@ -1,17 +1,23 @@
 import store from '@/store'
 
 // 从部门树中,根据名字获取人员信息
-export function findUserInDeptTree(name) {
+// cb是个函数,满足cb()为true则返回
+export function findUserInDeptTree(cb) {
   const depTree = store.getters['order/depTreeList']
   
   let nameObj = undefined
 
-  const findName = (list, name) => {
+  if (!cb) {
+    cb = () => {}
+  }
+
+  const findName = (list, cb) => {
     list.find(u => {
       if (Array.isArray(u.children) && u.children.length > 0) {
-        return findName(u.children, name)
+        return findName(u.children, cb)
       } else {
-        const t = u.name === name
+        // const t = u.name === name
+        const t = cb(u)
         if (t) {
           nameObj = u
         }
@@ -20,7 +26,7 @@ export function findUserInDeptTree(name) {
     })
   }
 
-  findName(depTree, name)
+  findName(depTree, cb)
   return nameObj
 }