|
@@ -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)
|
|
|
}
|