You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

726 lines
19 KiB

3 years ago
<template>
<view :class="['page', { show: isDetail }]">
3 years ago
<view class="block">
<view class="l-title">基本信息</view>
<view class="form-list">
<view class="line">
<view class="name">商务经理</view>
2 years ago
<view class="val">{{ form.businessManagerName }}</view>
3 years ago
</view>
2 years ago
<view :class="['line req', {err: err === 'customerName'}]">
3 years ago
<view class="name">客户名称</view>
<view v-if="isDetail" class="val">{{ form.customerName }}</view>
<view v-else :class="['ph', {val: form.customerName}]" @click="customerVisible = true">{{ form.customerName || '请选择客户' }}</view>
</view>
<view class="line">
<view class="name">省份</view>
<view class="val">{{ form.provinceName }}</view>
</view>
<view class="line">
<view class="name">城市</view>
<view class="val">{{ form.cityName }}</view>
</view>
<view class="line">
<view class="name">联系人</view>
2 years ago
<view class="val">{{ form.orderContact }}</view>
3 years ago
</view>
<view class="line">
<view class="name">电话</view>
<view class="val">{{ form.phone }}</view>
</view>
<view class="line">
<view class="name">邮箱</view>
<view class="val">{{ form.email }}</view>
</view>
2 years ago
<view :class="['line req', {err: err === 'orderType'}]">
3 years ago
<view class="name">订单类型</view>
2 years ago
<view v-if="isDetail" class="val">{{ orderTypes.find(e => e.value === form.orderType).text }}</view>
2 years ago
<uni-data-picker v-else class="picker-input" placeholder="请选择订单类型" popup-title="请选择订单类型" preload :clear-icon="false" :localdata="orderTypes" v-model="form.orderType" @change="calcTotal(1)"></uni-data-picker>
3 years ago
</view>
<view class="line">
<view class="name">订单编号</view>
<view class="val">{{ form.orderNumber }}</view>
</view>
<view class="line">
<view class="name">订单时间</view>
<view class="val">{{ form.createTime }}</view>
</view>
<view class="line">
<view class="name">订单金额</view>
<view class="val">{{ form.orderAmount }}</view>
</view>
3 years ago
</view>
3 years ago
</view>
3 years ago
<template v-for="c in courseList">
2 years ago
<view v-if="c.list.length" class="block pro-wrap" id="products">
<view class="l-title">{{ c.name }}</view>
3 years ago
<uni-icons class="arrow" type="top" size="20" color="#007EFF" @click="toggle(c)"></uni-icons>
<ul class="pro-list" v-show="!c.shrink">
2 years ago
<li v-for="(item, i) in c.list" @click.stop="editCourse(c, i)">
<view class="name">
<view class="left">
2 years ago
<image class="icon" :src="$util.getIcon(item)" mode="widthFix"></image>
{{ item.productName }}
</view>
2 years ago
<image v-if="!isDetail" class="del" src="@/static/image/trash.png" mode="widthFix" @click.stop="delCourse(c, i)"></image>
3 years ago
</view>
<view class="info">
<view class="line">
<view class="label">使用期限</view>
<view class="val">{{ item.startTime + ' - ' + item.endTime }}</view>
</view>
<view class="line">
<view class="label">市场价</view>
<view class="val">{{ item.marketValue }}</view>
</view>
<view class="line">
<view class="label">结算价</view>
2 years ago
<view class="val">{{ item.settlementPrice }}</view>
</view>
<view class="line">
<view class="label">折扣率</view>
<view class="val">{{ item.discountRate }}</view>
</view>
<view class="line">
2 years ago
<view class="label">市场服务费</view>
2 years ago
<view class="val">{{ item.serviceFee }}</view>
</view>
<view class="line done">
<view class="val">成交价格</view>
<view class="price">{{ item.finalPrice }}</view>
</view>
3 years ago
</view>
</li>
</ul>
</view>
</template>
3 years ago
3 years ago
<view class="bottom">
2 years ago
<view v-if="!orderId" class="add-wrap">
<view class="add-btn" @click="toAdd">
<uni-icons class="icon" type="plus" color="#007FFF"></uni-icons>
添加产品
</view>
3 years ago
</view>
2 years ago
<view :class="['product', isDetail ? 'show' : 'edit']">
3 years ago
<view class="text">
<view class="total">
2 years ago
<view v-if="isDetail">共选<text class="num">{{ courses.length }}</text>个产品</view>
<view class="column">总成交价合计<text class="num">{{ form.orderAmount }}</text></view>
3 years ago
</view>
<view class="info">
2 years ago
<view class="line">
总采购成本:<text class="num">{{ form.purchaseCost }}</text>
</view>
<view class="line">
总产品利润:<text class="num"> {{ form.profit }}</text>
</view>
3 years ago
</view>
3 years ago
</view>
2 years ago
<view v-if="!isDetail" class="btn" @click="submit">提交({{ courses.length }})</view>
3 years ago
</view>
3 years ago
</view>
<view class="popup-mask" v-show="customerVisible" @click="closeCustomer"></view>
<view class="popup" v-show="customerVisible">
<view class="top">请选择客户</view>
<uni-icons class="close" type="closeempty" size="20" @click="closeCustomer"></uni-icons>
<uni-search-bar class="search" radius="5" placeholder="请输入客户名称" v-model="keyword" clearButton="auto" cancelButton="none" />
3 years ago
<view class="list">
3 years ago
<view class="item" v-for="item in customerList" @click="customerChange(item)">{{ item.customerName }}</view>
3 years ago
</view>
</view>
</view>
</template>
<script>
3 years ago
import { queryCustomer, queryCustomerDetails } from '@/apis/modules/client.js'
3 years ago
import { add, update, getDetail } from '@/apis/modules/order.js'
2 years ago
import { getPartnerTeamRates } from '@/apis/modules/parner.js'
3 years ago
export default {
data() {
return {
3 years ago
isDetail: false,
orderId: '',
3 years ago
orderTypes: [{
text: '正式',
3 years ago
value: 1
3 years ago
}, {
text: '试用',
3 years ago
value: 2
3 years ago
}],
form: {
2 years ago
businessManagerName: uni.getStorageSync('team').userName,
3 years ago
// orderNumber: '', // 编号
provinceId: '', // 省份id
provinceName: '',
3 years ago
orderContact: '', // 联系人
email: '',
customerId: '', // 客户id
customerName: '',
orderType: '',
cityId: '',
cityName: '',
3 years ago
phone: '',
orderAmount: 0,
customerName: '',
3 years ago
profit: 0, // 利润
2 years ago
purchaseCost: 0, // 采购成本
2 years ago
teamId: uni.getStorageSync('team').id,
businessManagerId: this.$util.getBmId()
3 years ago
},
courseList: {},
3 years ago
courses: [], // 缓存的产品列表
3 years ago
contract: { // 合同信息
contractName: '', // 合同名称
contractFile: '', // 合同文件
contractMoney: '', // 合同金额
contractNumber: '',// 合同编号
startTime: '', // 期限-头
endTime: '' // 期限-尾
},
3 years ago
customerVisible: false,
keyword: '',
searchTimer: null,
customerList: [],
customerListAll: [],
2 years ago
err: '',
rate: ''
3 years ago
}
},
2 years ago
watch: {
keyword () {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(() => {
this.filterCustomer()
}, 500)
}
},
3 years ago
onShow() {
const pages = getCurrentPages()
3 years ago
const { options } = pages[pages.length - 1]
this.orderId = options.orderId
this.isDetail = !!options.show
3 years ago
const store = uni.getStorageSync('courses')
2 years ago
this.getRate()
3 years ago
if (this.orderId) {
this.getInfo()
} else if (store) {
3 years ago
// 新增取缓存,取了删除
3 years ago
const list = []
for (const i in store) {
list.push(...store[i].list)
}
this.courseList = store
this.courses = list
2 years ago
this.$nextTick(() => {
uni.pageScrollTo({
selector: '#products',
})
})
3 years ago
try {
uni.removeStorageSync('courses')
} catch (e) {}
this.calcTotal()
2 years ago
} else {
// 如果是客户订单记录页面点的新增,会有客户id,要默认选中该客户
const { customerId } = options
customerId && this.customerChange({
customerId
})
3 years ago
}
3 years ago
// 非详情才需要查询客户
if (!this.isDetail) {
this.getCustomer()
}
// 设置标题
uni.setNavigationBarTitle({
3 years ago
title: this.orderId ?
(this.isDetail ?
3 years ago
'订单详情' :
'编辑订单') :
'新增订单'
})
3 years ago
},
methods: {
3 years ago
// 获取详情
getInfo() {
2 years ago
uni.showLoading({
title: '加载中'
})
3 years ago
getDetail({
orderId: this.orderId
3 years ago
}).then(({ orderDetails }) => {
const order = orderDetails
this.contract = order.contractInformation
this.form = order.order
this.courses = order.orderOther
this.handleProduct(order.orderOther)
2 years ago
if(!this.orderId) {
this.calcTotal()
}
2 years ago
uni.hideLoading()
}).catch(e => {
uni.hideLoading()
})
3 years ago
},
// 转换产品列表
handleProduct(list) {
const courses = {
practice: {
3 years ago
shrink: false,
name: '实训课程产品',
list: []
},
theory: {
3 years ago
shrink: false,
name: '理论课程产品',
list: []
},
data: {
3 years ago
shrink: false,
name: '数据产品',
list: []
}
}
// 3个分类的课程分别push到不同数组(0->理论 1-实训 2 数据产品)
list.map(e => {
2 years ago
console.log('e.=>',e)
console.log('this.rate=>',this.rate)
e.serviceFee = (e.finalPrice * (this.rate / 100)).toFixed(2) // 服务费 != 0 && 才需要算
console.log('e.serviceFee=>',e.serviceFee)
const type = e.productType
!type ?
courses.theory.list.push(e) :
type === 1 ?
courses.practice.list.push(e) :
courses.data.list.push(e)
})
this.courseList = courses
},
3 years ago
// 获取客户列表
getCustomer() {
queryCustomer({
countries: '中国',
provinceId: '',
cityId: '',
searchContent: this.keyword,
page: 1,
size: 10000
}).then(({ message }) => {
this.customerListAll = message.list
this.customerList = message.list
}).catch(res => {})
3 years ago
},
3 years ago
// 客户模糊匹配
filterCustomer() {
const { keyword } = this
this.customerList = keyword ?
this.customerListAll.filter(e => e.customerName.includes(keyword)) :
this.customerListAll
},
// 关闭客户弹框
closeCustomer() {
this.customerVisible = false
this.keyword = ''
},
// 客户名称选择回调
customerChange(item) {
const { form } = this
// 获取客户详情
queryCustomerDetails({
customerId: item.customerId
}).then(({ result }) => {
2 years ago
this.handleErr('customerName')
3 years ago
const e = result.customer
form.customerId = e.customerId
form.customerName = e.customerName
form.provinceId = e.provinceId
form.cityId = e.cityId
form.provinceName = e.provinceName
form.cityName = e.cityName
3 years ago
form.phone = e.phone
form.email = e.email
2 years ago
form.orderContact = e.name
3 years ago
}).catch(e => {})
this.closeCustomer()
},
2 years ago
// 查询合伙人团队费率
getRate() {
getPartnerTeamRates({
teamId: uni.getStorageSync('team').teamId
}).then(({ teamRates }) => {
2 years ago
this.rate = teamRates.annualMarketingFee || 0
2 years ago
}).catch(res => {})
},
3 years ago
// 跳转
3 years ago
toAdd() {
3 years ago
uni.setStorageSync('courses', this.courses)
const { customerId, orderType } = this.form
customerId ?
this.$util.to(`../addCourse/addCourse?orderType=${orderType}&customerId=${customerId}`) :
this.$util.errMsg('请先选择客户!')
3 years ago
},
2 years ago
// 编辑课程
editCourse(c, i) {
if (this.isDetail) return false
uni.setStorageSync('courses', this.courses)
const { customerId, orderType } = this.form
this.$util.to(`../editCourse/editCourse?orderType=${orderType}&customerId=${customerId}`)
},
3 years ago
// 删除课程
delCourse(c, i) {
2 years ago
const that = this
3 years ago
uni.showModal({
title: '提示',
content: '确定要删除吗?',
success(res) {
2 years ago
if (res.confirm) {
c.list.splice(i, 1)
const courses = []
const list = that.courseList
for (const j in list) {
list[j].list.map(n => {
courses.push(n)
})
}
that.courses = courses
that.calcTotal()
}
3 years ago
}
})
},
3 years ago
// 收缩产品
toggle(c) {
c.shrink = !c.shrink
},
3 years ago
// 计算订单总额
2 years ago
calcTotal(out) {
2 years ago
this.handleErr('orderType')
3 years ago
const { form } = this
2 years ago
const isTrial = form.orderType === 2 // 是否试用
2 years ago
let total = 0
2 years ago
const list = this.courses
let purchase = 0 // 总采购成本
let profit = 0 // 总利润
/**
* 1总采购成本+总产品利润=总成交价格
2单个产品采购成本 =结算价+平台服务费
3平台服务费=结算价*10%
4单个产品的利润=成交价-采购成本
总成本和总利润为单个产品的采购成本价和利润的和
*/
list.map(e => {
2 years ago
// out=1 && 试用,则把结算价等重置为0
if (out && isTrial) {
2 years ago
e.settlementPrice = 0
e.serviceFee = 0
e.finalPrice = 0
e.finalValue = 0
e.discountRate = '0%'
} else {
2 years ago
this.calcDiscount(e)
this.dealSettlePrice(e)
this.calcFinalPrice(e)
2 years ago
const curPurchase = +e.settlementPrice + +e.serviceFee
purchase += curPurchase
profit += +e.finalPrice - curPurchase
}
2 years ago
})
2 years ago
form.purchaseCost = purchase
form.profit = profit
form.orderAmount = (+form.purchaseCost + +form.profit).toFixed(2)
3 years ago
},
2 years ago
calcDiscount(row) {
const price = row.authority ? row.finalPrice : row.finalValue
const { marketValue } = row
// (原价-现价)÷原价 x100%
if (price) row.discountRate = marketValue != 0 ? ((marketValue - price) / marketValue * 100).toFixed(2) + '%' : '0%'
},
// 计算结算价及平台服务费
dealSettlePrice(row) {
2 years ago
console.log('row==>',row)
2 years ago
// 如果是试用,结算价和平台服务费都是0
if (this.form.orderType == 2) {
row.settlementPrice = 0
row.serviceFee = 0
} else {
const unit = row.options // 使用期限单位
const useUnit = row.periodOfUse // 使用期限
let sPrice = ''
if (row.settlementMethod == 0) {
// 结算单价。计算规则:结算单价(**元/年)*购买时长(单位年)*数量(课程为1,数据为账号数量)
const priceUnit = row.settlementPriceUnit
sPrice = ((!unit ?
priceUnit / 365 * useUnit :
unit === 1 ?
priceUnit / 12 * useUnit :
priceUnit * useUnit) * (row.authority ?
1 :
row.accountNum)).toFixed((2))
} else {
// 比例分成。计算规则:成交价*商务分成比例
sPrice = (row.finalPrice * row.businessProportion / 100).toFixed((2))
}
row.settlementPrice = this.$util.handleNaN(sPrice)
// 平台服务费(结算价*10%)
if (row.settlementPrice) {
row.serviceFee = (row.finalPrice * (this.rate / 100)).toFixed(2)
}
}
},
// 计算成交价。计算规则:成交单价*账号数*时间(成交单价为元/账号/年,所以时间要换算成年的单位去计算)
calcFinalPrice(row) {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
const { finalValue, accountNum, periodOfUse, finalPrice } = row
if (periodOfUse) {
if (accountNum) {
// 有成交单价,则成交价=成交单价*账号数*时间
if (finalValue) {
row.finalPrice = Math.round(finalValue * periodOfUse * accountNum)
} else if (!finalValue && finalPrice) {
// 有成交价,没有成交单价,则成交单价=成交价/账号数/时间
row.finalValue = (finalPrice / periodOfUse / accountNum).toFixed(2)
this.calcDiscount(row)
}
} else if (finalValue && finalPrice && !row.authority) {
// 有成交价、成交单价,没有数量,则数量=成交价/时间/成交单价
row.accountNum = Math.floor(finalPrice / periodOfUse / finalValue)
}
}
this.dealSettlePrice(row)
}, 500)
},
2 years ago
// 处理错误提示
handleErr(val) {
if (val === this.err) this.err = ''
},
3 years ago
// 提交
submit() {
3 years ago
const { form, courses } = this
2 years ago
if (!form.customerId) {
this.err = 'customerName'
return this.$util.errMsg('请选择客户!')
}
if (!form.orderType) {
this.err = 'orderType'
return this.$util.errMsg('请选择订单类型!')
}
3 years ago
if (!courses.length) return this.$util.errMsg('请选择课程权限或数据权限后再确认订单!')
courses.map(e => {
e.startTime = this.$util.formatDate(new Date(e.startTime), 'yyyy-MM-dd')
3 years ago
})
2 years ago
uni.showLoading({
title: '提交中'
})
3 years ago
const data = {
contractInformation: this.contract, // 合同信息
order: form, // 订单基本数据
3 years ago
orderOther: courses // 产品列表
}
if (this.orderId) {
update(data).then(res => {
2 years ago
uni.hideLoading()
3 years ago
this.$util.sucMsg('编辑成功')
setTimeout(() => {
3 years ago
uni.navigateBack()
3 years ago
}, 1500)
2 years ago
}).catch(res => {
uni.hideLoading()
})
3 years ago
} else {
add(data).then(res => {
2 years ago
uni.hideLoading()
3 years ago
this.$util.sucMsg('添加成功')
setTimeout(() => {
3 years ago
uni.navigateBack()
3 years ago
}, 1500)
2 years ago
}).catch(res => {
uni.hideLoading()
})
3 years ago
}
}
3 years ago
}
}
</script>
<style scoped lang="scss">
3 years ago
.page {
2 years ago
padding-bottom: 420rpx;
3 years ago
}
.show {
2 years ago
padding-bottom: 280rpx;
}
3 years ago
.pro-wrap {
position: relative;
padding: 0;
.l-title {
margin: 0 24rpx;
}
}
.arrow {
position: absolute;
top: 20rpx;
right: 30rpx;
3 years ago
}
.pro-list {
.name {
3 years ago
display: flex;
justify-content: space-between;
align-items: center;
padding: 14rpx 24rpx;
font-size: 30rpx;
color: #333;
background: linear-gradient(90deg, #FFF5E5 0%, #FFFFFF 100%);
}
.left {
display: inline-flex;
align-items: center;
}
2 years ago
.del {
width: 40rpx;
}
3 years ago
.icon {
width: 60rpx;
height: 60rpx;
margin-right: 12rpx;
border-radius: 10rpx;
}
.info {
padding: 12rpx 24rpx;
3 years ago
}
.line {
display: flex;
3 years ago
justify-content: space-between;
padding: 12rpx 0;
3 years ago
margin: 5px 0;
font-size: 12px;
}
3 years ago
.label {
font-size: 28rpx;
color: #999;
}
.val {
font-size: 28rpx;
color: #333;
}
3 years ago
.done {
3 years ago
margin-top: 12rpx;
padding-top: 24rpx;
3 years ago
font-size: 13px;
color: #333;
3 years ago
border-top: 1px solid #E6E8ED;
3 years ago
}
3 years ago
.price {
font-size: 32rpx;
color: #007EFF;
}
}
3 years ago
.bottom {
position: fixed;
2 years ago
bottom: 0;
padding-bottom: env(safe-area-inset-bottom);
3 years ago
width: 100%;
2 years ago
background-color: #fff;
2 years ago
box-shadow: 0 -2px 2px #f5f5f5;
2 years ago
box-sizing: border-box;
3 years ago
}
2 years ago
.add-wrap {
padding: 16rpx 24rpx 40rpx;
background-color: #f5f5f5;
}
3 years ago
/deep/.add-btn {
display: flex;
justify-content: center;
align-items: center;
font-size: 28rpx;
line-height: 88rpx;
color: #007EFF;
background-color: #fff;
border: 1px solid #007EFF;
border-radius: 16rpx;
.icon {
margin-right: 10rpx;
}
.uni-icons {
font-size: 38rpx !important;
3 years ago
}
}
.product {
3 years ago
display: flex;
2 years ago
justify-content: space-between;
3 years ago
align-items: center;
3 years ago
padding: 24rpx;
3 years ago
background-color: #fff;
.total {
2 years ago
white-space: nowrap;
}
2 years ago
.line {
&:first-child {
margin-bottom: 8px;
}
}
2 years ago
&.show {
padding: 24rpx 50rpx;
.total {
2 years ago
display: flex;
2 years ago
margin-bottom: 30rpx;
font-size: 30rpx;
font-weight: 600;
color: #333;
2 years ago
.column {
margin-left: 10rpx;
}
2 years ago
.num {
2 years ago
margin: 0 5rpx;
font-size: 34rpx;
font-weight: 600;
2 years ago
color: #007EFF;
}
}
}
&.edit {
.total {
margin-bottom: 10rpx;
2 years ago
text-align: right;
2 years ago
font-size: 30rpx;
2 years ago
color: #666;
2 years ago
.num {
font-weight: 600;
2 years ago
font-size: 34rpx;
2 years ago
}
2 years ago
}
3 years ago
.num {
3 years ago
margin: 0 5rpx;
2 years ago
font-size: 30rpx;
3 years ago
color: #007EFF;
}
3 years ago
}
3 years ago
.info {
font-size: 24rpx;
color: #333;
2 years ago
white-space: nowrap;
3 years ago
}
.btn {
2 years ago
width: 180rpx;
2 years ago
margin-left: 30rpx;
3 years ago
line-height: 80rpx;
3 years ago
font-size: 32rpx;
3 years ago
text-align: center;
color: #fff;
border-radius: 10rpx;
background-color: #007EFF;
}
3 years ago
}
</style>