瀏覽代碼

feat: 订单审核模块,通用订单回显逻辑添加

cuiyalong 3 月之前
父節點
當前提交
a4b48f22d3

+ 10 - 3
src/store/order.js

@@ -431,9 +431,16 @@ export default {
     },
     // 恢复页面数据
     async restorePageInfo({ commit, dispatch }, order) {
-      const r = sortOrderInfo(order)
-      // await dispatch('resetPageInfo')
-      console.log(r)
+      const { pageFormValue, productArr } = sortOrderInfo(order)
+      await dispatch('resetPageInfo')
+      if (pageFormValue) {
+        for (const key in pageFormValue) {
+          commit('setPageForm', { key, data: pageFormValue[key] })
+        }
+      }
+      if (Array.isArray(productArr) && productArr.length > 0) {
+        commit('setOrderProductInfoList', productArr)
+      }
     },
     // 获取备选项
     async getSelectOptions({ commit, state }) {

+ 8 - 2
src/views/create-order/components/schema-form/params.js

@@ -8,7 +8,7 @@ export function orderParams(type) {
 
 // 获取回款计划
 function getReturnPlant(pageForm, totalMoney) {
-  let planList = undefined
+  let planList = []
   if (Array.isArray(pageForm.paybackTableData) && pageForm.paybackTableData.length > 0) {
     planList = pageForm.paybackTableData.map((p, index) => {
       return {
@@ -17,13 +17,19 @@ function getReturnPlant(pageForm, totalMoney) {
         money: mul(p.money, 100) || 0
       }
     })
-    if (planList) {
+    if (planList.length > 0) {
       planList.push({
         code: '合计',
         time: '-',
         money: mul(totalMoney, 100) || 0
       })
     }
+  } else {
+    planList.push({
+      code: '合计',
+      time: pageForm.expectedPaymentDeadlineTime,
+      money: mul(totalMoney, 100) || 0
+    })
   }
   return {
     day_num: pageForm.paymentDeadline - 0,

+ 130 - 6
src/views/create-order/components/schema-form/resort/index.js

@@ -1,15 +1,139 @@
 import { cloneDeep } from 'lodash'
-import { defaultPageFormValue, OrderProductCardItem } from '@/views/create-order/data/interface'
+import { defaultPageFormValue, OrderProductCardItem, PayBackTableRow, SalePersonTableRow } from '@/views/create-order/data/interface'
+import { dateFormatter } from '@/utils/globalFun'
+import { payWayOptions } from '@/views/create-order/data/index.js'
+import { findUserInDeptTree, calcChannelSelectorList } from "@/views/create-order/hooks/utils"
+import dayjs from 'dayjs'
+import { div } from '@/utils/number'
 
+function findItemInOptions(options, cb) {
+  const t = options.find(r => cb(r))
+  if (t) {
+    return t || {}
+  } else {
+    return {}
+  }
+}
 
 
 // 将接口参数转换为store需要的参数
-
-export function sortOrderInfo(order) {
+export function sortOrderInfo(order = {}) {
   const pageFormValue = cloneDeep(defaultPageFormValue)
-  console.log(order)
-}
+  const { orderData, contractRes, returnMoneyPlant, productData, saleDataRes } = order
+  if (orderData) {
+    // 基本信息
+    pageFormValue.buySubject = orderData.buy_subject || defaultPageFormValue.buySubject
+    pageFormValue.companyName = orderData.company_name || defaultPageFormValue.companyName
+    pageFormValue.username = orderData.personName || defaultPageFormValue.username // 联系人名称
+    pageFormValue.userTel = orderData.personPhone || defaultPageFormValue.userTel // 联系人电话
+    pageFormValue.accountTel = orderData.user_phone || defaultPageFormValue.accountTel // 开通服务手机号
+    pageFormValue.signUnit = orderData.signing_subject || defaultPageFormValue.signUnit // 签约主体
+    pageFormValue.orderChannel = orderData.order_channel || defaultPageFormValue.orderChannel // 下单渠道
+    pageFormValue.channelCommission = orderData.commission ? div(orderData.commission, 100) : defaultPageFormValue.channelCommission // 渠道佣金
+
+    // 其他信息
+    if (orderData.pay_way) {
+      const t = findItemInOptions(payWayOptions, v => v.label === orderData.pay_way)
+      if (t.value) {
+        pageFormValue.reservationPayWay = t.value // 约定支付方式
+      }
+    }
+    pageFormValue.paymentAccountName = orderData.payment_user || defaultPageFormValue.paymentAccountName // 付款户名
+    pageFormValue.orderRemark = orderData.remark || defaultPageFormValue.orderRemark // 订单备注
+  }  
+  
+  // 协议信息
+  if (contractRes) {
+    pageFormValue.agreeStatus = contractRes.contract_status || defaultPageFormValue.agreeStatus
+    pageFormValue.signCode = contractRes.contract_code || defaultPageFormValue.signCode // 协议编号
+    if (contractRes.contract_time) {
+      pageFormValue.signTime = dayjs(contractRes.contract_time).valueOf() // 协议签订时间
+    }
+    // 协议信息-电子协议
+    pageFormValue.e_contract_type = contractRes.seal_type || defaultPageFormValue.e_contract_type // 有无电子章
+    pageFormValue.e_contract_userA_type = contractRes.partyA_type || defaultPageFormValue.e_contract_userA_type // 协议甲方类型
+    pageFormValue.e_contract_userA_name = contractRes.partyA_name || defaultPageFormValue.e_contract_userA_name // 协议甲方
+    pageFormValue.e_contract_userA_contacts_name = contractRes.partyA_person || defaultPageFormValue.e_contract_userA_contacts_name // 协议甲方联系人
+    pageFormValue.e_contract_userA_contacts_tel = contractRes.partyA_tel || defaultPageFormValue.e_contract_userA_contacts_tel // 协议甲方联系方式
+    pageFormValue.e_contract_userA_contacts_address = contractRes.partyA_address || defaultPageFormValue.e_contract_userA_contacts_address // 协议甲方联系地址
+    pageFormValue.e_contract_userB_contacts_name = contractRes.partyB_person || defaultPageFormValue.e_contract_userB_contacts_name // 协议乙方联系人
+    pageFormValue.e_contract_remark = contractRes.remark || defaultPageFormValue.e_contract_remark // 协议备注
+  }
 
-export function sortProductArr(product) {
+  // 回款计划
+  if (returnMoneyPlant) {
+    const planInfo = returnMoneyPlant.list
+    if (planInfo) {
+      const planListStr = planInfo.plantList || '[]'
+      const planList = JSON.parse(planListStr)
+      
+      if (planList.length > 1) {
+        pageFormValue.paybackTimes = planList.length - 1
+        // console.log('回款计划 多次------------------------')
+        pageFormValue.paybackTableData = planList.filter(p => p.code !== '合计').map(item => {
+          return new PayBackTableRow(dayjs(item.time).valueOf(), div(item.money, 100))
+        })
+      } else {
+        pageFormValue.paybackTimes = 1
+        pageFormValue.paymentDeadline = planInfo.day_num || '' // 预计回款工作日
+        if (planInfo.expect_time) {
+          pageFormValue.expectedPaymentDeadlineTime = dateFormatter(planInfo.expect_time, 'yyyy-MM-dd') // 预计回款日期
+        }
+      }
+    }
+  }
+
+  // 业绩归属
+  if (saleDataRes && saleDataRes.saleFinal) {
+    const saleFinalList = saleDataRes.saleFinal.list
+    if (Array.isArray(saleFinalList) && saleFinalList.length > 0) {
+      if (saleFinalList.length === 1) {
+        const saleInfo = saleFinalList[0]
+        if (saleInfo) {
+          const userInfo = findUserInDeptTree(saleInfo.name)
+          if (userInfo && userInfo.id) {
+            pageFormValue.salePerson = [userInfo.id]
+          }
+          const channelArr = calcChannelSelectorList(saleInfo.distribution_channel)
+          if (Array.isArray(channelArr) && channelArr.length === 2) {
+            pageFormValue.saleWay = channelArr
+          }
+        }
+      } else {
+        const salePerson = []
+        pageFormValue.salePersonTableList = saleFinalList.map(sale => {
+          const userInfo = findUserInDeptTree(sale.name)
+          const saleWay = calcChannelSelectorList(sale.distribution_channel)
+          salePerson.push(userInfo?.id)
+          return new SalePersonTableRow(sale.name, userInfo?.id, div(sale.money, 100), saleWay)
+        })
+        pageFormValue.salePerson = salePerson
+      }
+    }
+  }
+
+  // const defaultPageFormValue = {
+  //   orderMoney0Type: '1', // 0元订单类型
+  // }
+
+  let productArr = []
+  if (Array.isArray(productData) && productData.length > 0) {
+    productArr = productData.map(pd => {
+      const productForm = sortProductFormArr(pd)
+      const config = {
+        productCode: pd.productItemCode,
+        waitingRestoreForm: productForm,
+      }
+      return new OrderProductCardItem(undefined, undefined, config)
+    })
+  }
+  console.log('sortOrderInfo', order, {pageFormValue,productArr})
+  return {
+    pageFormValue,
+    productArr,
+  }
+}
 
+export function sortProductFormArr(product) {
+  // console.log(product)
 }

+ 14 - 4
src/views/create-order/data/interface.js

@@ -49,15 +49,25 @@ export const defaultPageFormValue = {
 
 // 产品列表卡片类
 export class OrderProductCardItem {
-  constructor(title, subtitle2) {
-    this.title = title
+  constructor(title, subtitle2, conf = {}) {
+    this.title = title || '产品'
     this.subtitle2 = subtitle2
     this.id = getRandomString()
+
+    const {
+      productCode,
+      standardPrice,
+      waitingRestoreForm,
+    } = conf
+
     this.productCardInfo = {
       info: {},
       form: {},
-      result: {},
-      standardPrice: '',
+      waitingRestoreForm,
+      result: {
+        productCode,
+      },
+      standardPrice: standardPrice || '',
     }
   }
 

+ 35 - 0
src/views/create-order/hooks/utils.js

@@ -0,0 +1,35 @@
+import store from '@/store'
+
+// 从部门树中,根据名字获取人员信息
+export function findUserInDeptTree(name) {
+  const list = store.getters['order/depTreeList']
+  let nameObj = undefined
+  list.find(dep => {
+    if (Array.isArray(dep.children)) {
+      const t = dep.children.find(user => user.name === name)
+      if (t) {
+        nameObj = t
+      }
+    }
+    return nameObj
+  })
+  return nameObj
+}
+
+// 营销渠道:根据营销渠道最深层级的id。整理出其选择器的选中列表
+export function calcChannelSelectorList(code) {
+  const list = store.state.order.conf?.channel || []
+  let channelArr = []
+  list.find(f => {
+    if (Array.isArray(f.children)) {
+      const t = f.children.find(s => {
+        if (s.item_code === code) {
+          channelArr = [f.item_code, s.item_code]
+          return true
+        }
+      })
+      return t
+    }
+  })
+  return channelArr
+}

+ 2 - 1
src/views/order/components/OrderReviewCard.vue

@@ -24,6 +24,7 @@
 import CreateOrder from '@/views/create-order/components/create.vue'
 import AuditRecordsColumns from '@/views/create-order/components/order-detail-submodule/AuditRecordsColumns.vue'
 import { mapActions } from 'vuex'
+import { cloneDeep } from "lodash"
 
 export default {
   name: 'OrderReviewCard',
@@ -49,7 +50,7 @@ export default {
       deep: true,
       immediate: true,
       handler(n) {
-        this.restoreData(n)
+        this.restoreData(cloneDeep(n))
       }
     }
   },