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.

528 lines
13 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>
<view class="val">{{ $util.getBmName() }}</view>
3 years ago
</view>
<view class="line req">
<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>
<view class="val">{{ form.name }}</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">
<view class="name">订单类型</view>
<view v-if="isDetail" class="val">{{ form.industryClassName }}</view>
<uni-data-picker v-else class="picker-input" placeholder="请选择订单类型" popup-title="请选择订单类型" preload :clear-icon="false" :localdata="orderTypes" v-model="form.orderType"></uni-data-picker>
</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">
<view v-if="c.list.length" class="block pro-wrap">
<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">
<li v-for="(item, i) in c.list">
<view class="name">
<view class="left">
<image v-if="item.miniProgramPictureAddress" class="icon" :src="item.miniProgramPictureAddress" mode="widthFix"></image>
{{ item.productName }}
</view>
<uni-icons v-if="!isDetail" class="del" type="trash" size="25" color="#ADADAD" @click="delCourse(c, i)"></uni-icons>
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>
<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>
3 years ago
</view>
</li>
</ul>
</view>
</template>
3 years ago
3 years ago
<view class="bottom">
3 years ago
<view v-if="!orderId" class="add-btn" @click="toAdd">
3 years ago
<uni-icons class="icon" type="plus" color="#007FFF"></uni-icons>
添加产品
</view>
<view class="product">
<view class="text">
<view class="total">
已选
3 years ago
<text class="num">{{ courses.length }}</text>
3 years ago
个产品&emsp;
总成交价合计
3 years ago
<text class="num">{{ form.orderAmount }}</text>
3 years ago
</view>
<view class="info">
总采购成本:
3 years ago
<text class="num num1">{{ purchase }}</text>
3 years ago
总产品利润:
<text class="num"> {{ profit }}</text>
3 years ago
</view>
3 years ago
</view>
<view v-if="!isDetail" class="btn" @click="submit">提交</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'
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: {
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: '',
businessManagerId: this.$util.getBmId()
3 years ago
},
courseList: {},
3 years ago
courses: [], // 缓存的产品列表
3 years ago
purchase: 0,
profit: 0,
contract: { // 合同信息
contractName: '', // 合同名称
contractFile: '', // 合同文件
contractMoney: '', // 合同金额
contractNumber: '',// 合同编号
startTime: '', // 期限-头
endTime: '' // 期限-尾
},
3 years ago
customerVisible: false,
keyword: '',
searchTimer: null,
customerList: [],
customerListAll: [],
3 years ago
}
},
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')
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
3 years ago
try {
uni.removeStorageSync('courses')
} catch (e) {}
this.calcTotal()
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() {
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)
this.calcTotal()
3 years ago
}).catch(e => {})
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 => {
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
},
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 }) => {
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
form.name = e.name
}).catch(e => {})
this.closeCustomer()
},
// 跳转
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
},
// 删除课程
delCourse(c, i) {
3 years ago
uni.showModal({
title: '提示',
content: '确定要删除吗?',
success(res) {
res.confirm && c.list.splice(i, 1)
3 years ago
}
})
},
3 years ago
// 收缩产品
toggle(c) {
c.shrink = !c.shrink
},
3 years ago
// 计算订单总额
3 years ago
calcTotal() {
3 years ago
let total = 0
3 years ago
const list = this.courses
let purchase = 0 // 总采购成本
let profit = 0 // 总利润
/**
* 1总采购成本+总产品利润=总成交价格
2单个产品采购成本 =结算价+平台服务费
3平台服务费=结算价*10%
4单个产品的利润=成交价-采购成本
总成本和总利润为单个产品的采购成本价和利润的和
*/
list.map(e => {
const curPurchase = +e.settlementPrice + +e.serviceFee
purchase += curPurchase
profit += +e.finalPrice - curPurchase
})
this.purchase = Math.round(purchase)
this.profit = Math.round(profit)
this.form.orderAmount = +this.purchase + +this.profit
3 years ago
},
// 提交
submit() {
3 years ago
const { form, courses } = this
if (!form.customerId) return this.$util.errMsg('请选择客户!')
if (!form.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
})
3 years ago
const data = {
contractInformation: this.contract, // 合同信息
order: form, // 订单基本数据
3 years ago
orderOther: courses // 产品列表
}
if (this.orderId) {
update(data).then(res => {
this.$util.sucMsg('编辑成功')
setTimeout(() => {
this.$util.to('../orders/orders')
}, 1500)
}).catch(res => {})
} else {
add(data).then(res => {
this.$util.sucMsg('添加成功')
setTimeout(() => {
this.$util.to('../orders/orders')
}, 1500)
}).catch(res => {})
}
}
3 years ago
}
}
</script>
<style scoped lang="scss">
3 years ago
.page {
height: calc(100vh - 300rpx);
overflow: auto;
}
.show {
height: calc(100vh - 130rpx);
}
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;
}
.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;
bottom: 0;
3 years ago
width: 100%;
3 years ago
}
3 years ago
/deep/.add-btn {
display: flex;
justify-content: center;
align-items: center;
margin: 16rpx 24rpx;
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;
justify-content: flex-end;
3 years ago
align-items: center;
3 years ago
padding: 24rpx;
margin-top: 40rpx;
3 years ago
background-color: #fff;
.total {
3 years ago
margin-bottom: 10rpx;
font-size: 24rpx;
color: #666;
.num {
font-size: 30rpx;
color: #007EFF;
}
3 years ago
}
3 years ago
.info {
font-size: 24rpx;
color: #333;
.num {
font-size: 24rpx;
color: #007EFF;
3 years ago
}
}
3 years ago
.num1 {
margin-right: 10rpx;
}
.btn {
width: 196rpx;
margin-left: 27rpx;
line-height: 80rpx;
font-size: 30rpx;
text-align: center;
color: #fff;
border-radius: 10rpx;
background-color: #007EFF;
}
3 years ago
}
</style>