或然中台小程序
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.

811 lines
23 KiB

2 years ago
<template>
<view :class="['page', { show: isDetail }]">
<view class="block">
<view class="l-title">基本信息</view>
<view class="form-list">
<view :class="['line req', {err: err === 'customerName'}]">
<view class="name">客户名称</view>
<view v-if="orderId" class="val">{{ form.customerName }}</view>
2 years ago
<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>
<view class="val">{{ form.orderContact }}</view>
</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>
<view :class="['line req', {err: err === 'orderType'}]">
<view class="name">订单类型</view>
<view v-if="isDetail" class="val">{{ orderTypes.find(e => e.value === form.orderType).text }}</view>
<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>
</view>
2 years ago
<view class="line">
<view class="name">团队</view>
<view v-if="isDetail" class="val">{{ form.partnerClassificationName }}</view>
<uni-data-picker v-else class="picker-input" placeholder="请选择团队" popup-title="请选择团队" preload :clear-icon="false" :localdata="teams" :map="{text: 'partnerClassificationName', value: 'id'}" v-model="form.teamId" @change="getBm"></uni-data-picker>
</view>
<view class="line">
<view class="name">商务经理</view>
<view v-if="isDetail" class="val">{{ form.businessManagerName }}</view>
<uni-data-picker v-else class="picker-input" placeholder="请选择商务经理" popup-title="请选择商务经理" preload :localdata="bms" :map="{text: 'userName', value: 'partnerId'}" v-model="form.businessManagerId" :readonly="form.teamId ? false : true"></uni-data-picker>
</view>
2 years ago
<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>
</view>
</view>
<template v-for="(c, n) in courseList">
2 years ago
<view v-if="c.list.length" class="block pro-wrap" id="products">
<view class="l-title">{{ c.name }}</view>
<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" :key="i" @click.stop="editCourse(c, i)">
<view class="name">
<view class="left">
<image class="icon" :src="$util.getIcon(item)" mode="widthFix"></image>
{{ item.productName }}
</view>
<view class="course-action">
<!-- 1查看时不可操作
2发货和启用不要同时出现生效前只会显示发货不发货按钮生效后只显示禁启用按钮
3处理中的订单显示发货不显示禁用 -->
<button v-if="item.status === 1 || isHandle || !orderId" class="course-btn" type="primary" @click.stop="handleDeliver(n, i)">{{ item.ship ? '取消' : ''}}发货</button>
<button v-else-if="!isDetail" class="course-btn" type="primary" @click.stop="handleEnable(n, i)">{{ item.isEnable ? '禁用' : '启用'}}</button>
<image v-if="!orderId || isRenew" class="del" src="@/static/image/trash.png" mode="widthFix" @click.stop="delCourse(c, i)"></image>
</view>
</view>
<view class="info">
<view class="line">
<view class="label">使用期限</view>
<view class="val">{{ item.startTime + (item.endTime && ' - ' + 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>
<view class="val">{{ item.settlementPrice }}</view>
</view>
<view class="line">
<view class="label">折扣率</view>
<view class="val">{{ item.discountRate }}</view>
</view>
<view class="line">
<view class="label">平台服务费</view>
<view class="val">{{ item.serviceFee }}</view>
</view>
<view class="line done">
<view class="val">成交价格</view>
<view class="price">{{ item.finalPrice }}</view>
</view>
</view>
</li>
2 years ago
</ul>
</view>
</template>
<view class="bottom">
<view v-if="!orderId" class="add-wrap">
<view class="add-btn" @click="toAdd">
<uni-icons class="icon" type="plus" color="#007FFF"></uni-icons>
添加产品
</view>
</view>
<view :class="['product', isDetail ? 'show' : 'edit']">
<view class="text">
<view class="total">
<view v-if="isDetail">共选<text class="num">{{ courses.length }}</text>个产品</view>
<view class="column">总成交价合计<text class="num">{{ form.orderAmount }}</text></view>
</view>
<view class="info">
<view class="line">
总采购成本:<text class="num">{{ form.purchaseCost }}</text>
</view>
<view class="line">
总产品利润:<text class="num"> {{ form.profit }}</text>
</view>
</view>
</view>
2 years ago
<view class="product-btns">
<view v-if="!isDetail" class="btn" @click="submit">提交({{ courses.length }})</view>
<view v-if="isHandle || (!orderId && courses.length)" class="btn" @click="batchDeliver">{{ courses.find(e => !e.ship) ? '一键发货' : '取消全部发货' }}</view>
</view>
2 years ago
</view>
</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" />
<view class="list">
<view class="item" v-for="item in customerList" @click="customerChange(item)">{{ item.customerName }}</view>
</view>
</view>
</view>
</template>
<script>
import { queryCustomer, queryCustomerDetails } from '@/apis/modules/client.js'
2 years ago
import { add, update, getDetail, renew, ship, miniProgramOrderRecord, bulkShipping } from '@/apis/modules/order.js'
import { teamList, getAllTeam } from '@/apis/modules/parner.js'
2 years ago
export default {
data() {
return {
isDetail: false,
isEdit: 0, // 编辑
isHandle: 0, // 处理
isRenew: 0, // 续费
2 years ago
orderId: '',
orderTypes: [{
text: '正式',
value: 1
}, {
text: '试用',
value: 2
}],
form: {
2 years ago
businessManagerId: '',
businessManagerName: '',
2 years ago
// orderNumber: '', // 编号
provinceId: '', // 省份id
provinceName: '',
orderContact: '', // 联系人
email: '',
customerId: '', // 客户id
customerName: '',
orderType: '',
cityId: '',
cityName: '',
phone: '',
orderAmount: 0,
customerName: '',
profit: 0, // 利润
purchaseCost: 0, // 采购成本
2 years ago
teamId: '',
partnerClassificationName: '',
2 years ago
},
2 years ago
teams: [],
bms: [],
2 years ago
courseList: {},
courses: [], // 缓存的产品列表
contract: { // 合同信息
contractName: '', // 合同名称
contractFile: '', // 合同文件
contractMoney: '', // 合同金额
contractNumber: '',// 合同编号
startTime: '', // 期限-头
endTime: '' // 期限-尾
},
customerVisible: false,
keyword: '',
searchTimer: null,
customerList: [],
customerListAll: [],
err: '',
promises: [],
2 years ago
}
},
watch: {
keyword () {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(() => {
this.filterCustomer()
}, 500)
}
},
onShow() {
const pages = getCurrentPages()
const { options } = pages[pages.length - 1]
this.orderId = options.orderId
this.isDetail = !!options.show
this.isEdit = options.text === '修改'
this.isHandle = options.text === '处理'
this.isRenew = options.text === '续费'
2 years ago
this.getTeam()
2 years ago
const store = uni.getStorageSync('courses')
2 years ago
if (store) {
2 years ago
// 新增取缓存,取了删除
const list = []
for (const i in store) {
list.push(...store[i].list)
}
this.courseList = store
this.courses = list
this.$nextTick(() => {
uni.pageScrollTo({
selector: '#products',
})
})
try {
uni.removeStorageSync('courses')
} catch (e) {}
this.calcTotal()
} else {
// 如果是客户订单记录页面点的新增,会有客户id,要默认选中该客户
const { customerId } = options
customerId && this.customerChange({
customerId
})
}
// 非详情才需要查询客户
this.isDetail || this.getCustomer()
2 years ago
// 设置标题
uni.setNavigationBarTitle({
title: this.orderId ?
(this.isDetail ?
'订单详情' :
'编辑订单') :
'新增订单'
})
},
methods: {
// 获取详情
getInfo() {
uni.showLoading({
title: '加载中'
})
getDetail({
orderId: this.orderId
}).then(({ orderDetails }) => {
const order = orderDetails
if (!this.isRenew) this.contract = order.contractInformation // 非续费才回显合同
2 years ago
this.form = order.order
2 years ago
// 如果有teamId的,则遍历团队列表来获取团队名称
const { teamId } = this.form
if (teamId) {
const item = this.teams.find(e => e.id == teamId)
if (item) this.form.partnerClassificationName = item.partnerClassificationName
if (!this.isDetail) {
this.form.businessManagerId = +this.form.businessManagerId
this.getBm()
}
}
2 years ago
this.courses = order.orderOther
this.handleRenew(0)
this.handleRenew(1)
this.handleRenew(2)
Promise.all(this.promises).then(_ => {
this.handleProduct(this.courses)
this.calcTotal()
uni.hideLoading()
})
2 years ago
}).catch(e => {
uni.hideLoading()
})
},
// 转换产品列表
handleProduct(list) {
const courses = {
practice: {
shrink: false,
name: '实训课程产品',
list: []
},
theory: {
shrink: false,
name: '理论课程产品',
list: []
},
data: {
shrink: false,
name: '数据产品',
list: []
}
}
// 3个分类的课程分别push到不同数组(0->理论 1-实训 2 数据产品)
list.map(e => {
e.serviceFee = (e.settlementPrice * 0.1).toFixed(2)
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
},
2 years ago
// 处理开始结束时间和订单状态(参考pc,订单模块不是本人开发的,所以也不懂这里逻辑)
handleRenew(authority) {
const productId = this.courses.filter(e => e.authority == authority).map(e => e.dataOrCourseId)
productId.length && this.promises.push(new Promise((resolve, reject) => {
renew({
authority,
customerId: this.form.customerId,
productId
}).then(({ orderOthers }) => {
const { courses } = this
const now = new Date()
orderOthers.map(e => {
const item = courses.find(n => n.dataOrCourseId == e.dataOrCourseId && n.authority == authority && e.authority == authority)
if (item) {
if (this.isRenew) { // 续费
let date = new Date(e.endTime)
if (now < date) { // 没过期,则返回的结束日期+1天作为开始时间
date = new Date(date.setDate(date.getDate() + 1))
item.startTime = this.$util.formatDate(date, 'yyyy-MM-dd')
} else { // 过期了则当前日期作为开始时间
item.startTime = this.$util.formatDate(now, 'yyyy-MM-dd')
}
item.endTime = ''
item.periodOfUse = ''
item.marketValue = e.marketValue
} else if (!this.isDetail) { // 如果不是查看
item.startTime = e.startTime.split(' ')[0]
2 years ago
item.endTime = e.endTime ? e.endTime.split(' ')[0] : ''
}
}
const startTime = new Date(item.startTime)
const endTime = new Date(item.endTime)
// 1: 未生效,2:生效中,3:已过期
item.status = now < startTime ?
1 :
now > startTime && now < endTime ?
2 :
3
if (item.status === 3) item.isEnable = 0 // 已过期的,变成禁用状态,且不能启用
})
resolve()
}).catch(e => {
reject()
})
}))
},
2 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 => {})
},
// 客户模糊匹配
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 }) => {
this.handleErr('customerName')
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
form.phone = e.phone
form.email = e.email
form.orderContact = e.name
}).catch(e => {})
this.closeCustomer()
},
2 years ago
// 获取团队
getTeam() {
getAllTeam().then(({ team }) => {
this.teams = team
this.orderId && this.getInfo()
}).catch(res => {})
},
// 获取商务经理
getBm() {
teamList({
pageNum: 1,
pageSize: 1000,
type: 1,
partnerClassificationId: this.form.teamId
}).then(({ pageList }) => {
this.bms = pageList.records
}).catch(res => {})
},
2 years ago
// 跳转
toAdd() {
uni.setStorageSync('courses', this.courses)
const { customerId, orderType } = this.form
customerId ?
this.$util.to(`../addCourse/addCourse?orderType=${orderType}&customerId=${customerId}`) :
this.$util.errMsg('请先选择客户!')
},
// 编辑课程
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}&action=${this.isEdit ? 'edit' : this.isRenew ? 'renew' : this.isHandle ? 'handle' : !this.orderId ? 'add' : ''}`)
2 years ago
},
// 删除课程
delCourse(c, i) {
const that = this
uni.showModal({
title: '提示',
content: '确定要删除吗?',
success(res) {
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()
}
}
})
},
// 收缩产品
toggle(c) {
c.shrink = !c.shrink
},
2 years ago
// 处理禁用启用
handleEnable(c, i) {
this.courseList[c].list[i].isEnable = this.courseList[c].list[i].isEnable ? 0 : 1
},
// 处理发货
handleDeliver(c, i) {
const row = this.courseList[c].list[i]
row.ship = row.ship ? 0 : 1
this.isEdit && ship(row).then(res => {}).catch(res => {}) // 编辑的情况下,需要调接口去直接发货
},
2 years ago
// 计算订单总额
calcTotal(out) {
this.handleErr('orderType')
const { form } = this
const isTrial = form.orderType === 2 // 是否试用
let total = 0
const list = this.courses
let purchase = 0 // 总采购成本
let profit = 0 // 总利润
/**
* 1总采购成本+总产品利润=总成交价格
2单个产品采购成本 =结算价+平台服务费
3平台服务费=结算价*10%
4单个产品的利润=成交价-采购成本
总成本和总利润为单个产品的采购成本价和利润的和
*/
list.map(e => {
// out=1 && 试用,则把结算价等重置为0
if (out && isTrial) {
e.settlementPrice = 0
e.serviceFee = 0
e.finalPrice = 0
e.finalValue = 0
e.discountRate = '0%'
} else {
const curPurchase = +e.settlementPrice + +e.serviceFee
purchase += curPurchase
profit += +e.finalPrice - curPurchase
}
})
form.purchaseCost = Math.round(purchase)
form.profit = Math.round(profit)
form.orderAmount = +form.purchaseCost + +form.profit
},
// 处理错误提示
handleErr(val) {
if (val === this.err) this.err = ''
},
2 years ago
// 发送服务通知
publicNotice(form, id) {
miniProgramOrderRecord({
content: form.orderOther.map(e => e.productName).join(),
openId: uni.getStorageSync('openid'),
page: `orderId=201&show=1?id=${id}&isShow=1`,
school: form.customerName,
state: '已完成',
}).then(res => {
uni.hideLoading()
this.$util.sucMsg('编辑成功')
setTimeout(() => {
uni.navigateBack()
}, 1500)
}).catch(res => {
uni.hideLoading()
})
},
// 一键发货/取消全部发货
batchDeliver() {
const list = this.courseList
const ship = this.courses.find(e => !e.ship) ? 1 : 0 // 是否发货。如果全部发货了,则全部遍历为0,否则为1(1发货,0未发货)
const courses = []
for (const i in list) {
list[i].list.forEach(e => {
e.ship = ship
courses.push(e)
})
}
this.courses = courses
this.isEdit && bulkShipping({orderOthers: courses}).then(res => {}).catch(res => {}) // 编辑的情况下,需要调接口去直接发货
console.log(11, this.courses)
},
2 years ago
// 提交
submit() {
const { form } = this
const courses = []
2 years ago
if (!form.customerId) {
this.err = 'customerName'
return this.$util.errMsg('请选择客户!')
}
if (!form.orderType) {
this.err = 'orderType'
return this.$util.errMsg('请选择订单类型!')
}
for (const i in this.courseList) {
courses.push(...this.courseList[i].list)
}
2 years ago
if (!courses.length) return this.$util.errMsg('请选择课程权限或数据权限后再确认订单!')
courses.map(e => {
e.startTime = this.$util.formatDate(new Date(e.startTime), 'yyyy-MM-dd')
})
if (this.isRenew || courses.some(e => e.renew)) form.orderNature = 2
2 years ago
uni.showLoading({
title: '提交中'
})
const data = {
contractInformation: this.contract, // 合同信息
order: form, // 订单基本数据
orderOther: courses // 产品列表
}
2 years ago
if (this.isEdit || this.isHandle) {
2 years ago
update(data).then(res => {
uni.hideLoading()
this.$util.sucMsg('编辑成功')
setTimeout(() => {
uni.navigateBack()
}, 1500)
}).catch(res => {
uni.hideLoading()
})
} else {
add(data).then(res => {
2 years ago
// form.orderOther.find(e => !e.ship) || this.publicNotice(form, orderId) // 新增的时候要判断是否全部产品都发货了,全部发货了才发服务通知
2 years ago
uni.hideLoading()
this.$util.sucMsg('添加成功')
setTimeout(() => {
uni.navigateBack()
}, 1500)
}).catch(res => {
uni.hideLoading()
})
}
}
}
}
</script>
<style scoped lang="scss">
.page {
padding-bottom: 420rpx;
}
.show {
padding-bottom: 280rpx;
}
.pro-wrap {
position: relative;
padding: 0;
.l-title {
margin: 0 24rpx;
}
}
.arrow {
position: absolute;
top: 20rpx;
right: 30rpx;
}
.pro-list {
.name {
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
.course-action {
display: inline-flex;
align-items: center;
}
.course-btn {
padding: 0 16rpx;
margin-right: 10rpx;
font-size: 28rpx;
}
2 years ago
.del {
width: 40rpx;
}
.icon {
width: 60rpx;
height: 60rpx;
margin-right: 12rpx;
border-radius: 10rpx;
}
.info {
padding: 12rpx 24rpx;
}
.line {
display: flex;
justify-content: space-between;
padding: 12rpx 0;
margin: 5px 0;
font-size: 12px;
}
.label {
font-size: 28rpx;
color: #999;
}
.val {
font-size: 28rpx;
color: #333;
}
.done {
margin-top: 12rpx;
padding-top: 24rpx;
font-size: 13px;
color: #333;
border-top: 1px solid #E6E8ED;
}
.price {
font-size: 32rpx;
color: #007EFF;
}
}
.bottom {
position: fixed;
bottom: 0;
padding-bottom: env(safe-area-inset-bottom);
width: 100%;
background-color: #fff;
box-shadow: 0 -2px 2px #f5f5f5;
box-sizing: border-box;
}
.add-wrap {
padding: 16rpx 24rpx 40rpx;
background-color: #f5f5f5;
}
/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;
}
}
.product {
display: flex;
justify-content: space-between;
align-items: center;
padding: 24rpx;
background-color: #fff;
.total {
white-space: nowrap;
}
.line {
&:first-child {
margin-bottom: 8px;
}
}
&.show {
padding: 24rpx 50rpx;
.total {
display: flex;
margin-bottom: 30rpx;
font-size: 30rpx;
font-weight: 600;
color: #333;
.column {
margin-left: 10rpx;
}
.num {
margin: 0 5rpx;
font-size: 34rpx;
font-weight: 600;
color: #007EFF;
}
}
}
&.edit {
.total {
margin-bottom: 10rpx;
text-align: right;
font-size: 30rpx;
color: #666;
.num {
font-weight: 600;
font-size: 34rpx;
}
}
.num {
margin: 0 5rpx;
font-size: 30rpx;
color: #007EFF;
}
}
.info {
font-size: 24rpx;
color: #333;
white-space: nowrap;
}
2 years ago
.product-btns {
display: inline-flex;
align-items: center;
margin-left: 20rpx;
}
2 years ago
.btn {
2 years ago
padding: 0 20rpx;
margin-left: 16rpx;
2 years ago
line-height: 80rpx;
2 years ago
font-size: 30rpx;
2 years ago
text-align: center;
color: #fff;
border-radius: 10rpx;
background-color: #007EFF;
}
}
</style>