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.
1201 lines
35 KiB
1201 lines
35 KiB
<template> |
|
<view :class="['page', { show: isDetail }]"> |
|
<view class="block"> |
|
<view class="l-title">基本信息</view> |
|
<view class="form-list"> |
|
<view class="line"> |
|
<view class="name">商务经理</view> |
|
<view class="val">{{ form.businessManagerName }}</view> |
|
</view> |
|
<view :class="['line req', {err: err === 'customerName'}]"> |
|
<view class="name">客户名称</view> |
|
<view v-if="isDetail" class="val">{{ form.customerName }}</view> |
|
<view v-else class="customer-wrap"> |
|
<view :class="['ph', {val: form.customerName}]" @click="customerVisible = true">{{ form.customerName || '请选择客户' }}</view> |
|
<!-- <view class="create" @click="toClient">找不到客户?马上创建</view> --> |
|
</view> |
|
</view> |
|
<view class="line" v-if="form.customerName"> |
|
<view class="name">省份</view> |
|
<view class="val">{{ form.provinceName }}</view> |
|
</view> |
|
<view class="line" v-if="form.customerName"> |
|
<view class="name">城市</view> |
|
<view class="val">{{ form.cityName }}</view> |
|
</view> |
|
<view class="line" v-if="form.customerName"> |
|
<view class="name">联系人</view> |
|
<view class="val">{{ form.orderContact }}</view> |
|
</view> |
|
<view class="line" v-if="form.customerName"> |
|
<view class="name">电话</view> |
|
<view class="val">{{ form.phone }}</view> |
|
</view> |
|
<view class="line" v-if="form.customerName"> |
|
<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> |
|
<template v-if="edited"> |
|
<view v-if="form.orderNumber" class="line"> |
|
<view class="name">订单编号</view> |
|
<view class="val">{{ form.orderNumber }}</view> |
|
</view> |
|
<view v-if="form.createTime" 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> |
|
</template> |
|
</view> |
|
</view> |
|
|
|
<view id="products"> |
|
<template v-for="c in courseList"> |
|
<view v-if="c.list.length" class="block pro-wrap"> |
|
<view class="type-wrap"> |
|
<view class="l-title">{{ c.name }}</view> |
|
<view v-if="!isDetail" class="batch"> |
|
<input class="deadline" type="number" v-model="c.deadline" placeholder="批量输入" @change="batchDeadlineChange(c)"> |
|
<view :class="['unit', {placeholder: c.unit === ''}]" @click="batchUnitChange(c)">{{ c.unit ? units.find(e => e.id === c.unit).text : '请选择' }}</view> |
|
</view> |
|
<uni-icons class="arrow" type="top" size="20" color="#007EFF" @click="toggle(c)"></uni-icons> |
|
</view> |
|
|
|
<ul class="pro-list" v-show="!c.shrink"> |
|
<li v-for="(item, i) in c.list"> |
|
<view class="name"> |
|
<view class="left"> |
|
<image class="icon" :src="$util.getIcon(item)" mode="widthFix"></image> |
|
{{ item.productName }} |
|
</view> |
|
<view class="course-action"> |
|
<image v-if="!isDetail" 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 v-if="isDetail || isEdit" class="ph">{{ item.endTime ? item.startTime + ' - ' + item.endTime : item.startTime}}</view> |
|
<uni-datetime-picker v-else type="date" v-model="item.startTime" :border="false" @change="dateChange(item)"> |
|
<view :class="['ph', {val: item.startTime}]"> |
|
{{ item.endTime ? item.startTime + ' - ' + item.endTime : item.startTime}} |
|
</view> |
|
</uni-datetime-picker> |
|
</view> |
|
<view class="line" :class="[ {err: err === 'periodOfUse' + item.dataOrCourseId + item.authority}]"> |
|
<view class="label">使用期限</view> |
|
<view v-if="isDetail" class="ph">{{item.periodOfUse}}{{ units.find(e => e.id === item.options).text }}</view> |
|
<template v-else> |
|
<input class="period" type="number" v-model="item.periodOfUse" placeholder="请输入" @input="dateChange(item, !item.authority)" @change="handleErr(item, 'periodOfUse')"> |
|
<view class="val unit" @click="selectUnit(item)"> |
|
<text>{{ units.find(e => e.id === item.options).text }}</text> |
|
<image class="icon" src="@/static/image/arrow-down.png" mode="widthFix"></image> |
|
</view> |
|
</template> |
|
</view> |
|
<view :class="['line req', {err: err === 'accountNum' + item.dataOrCourseId + item.authority}]"> |
|
<view class="label">数量</view> |
|
<view v-if="item.authority || (!item.authority && isDetail)" class="ph">1</view> |
|
<view v-else class="inline"> |
|
<input type="number" v-model="item.accountNum" placeholder="请输入账号数量" @input="calcFinalPrice(item)" @change="handleErr(item, 'accountNum')"> |
|
</view> |
|
</view> |
|
<view class="line"> |
|
<view class="label">{{ item.authority ? '市场价' : '市场单价' }}</view> |
|
<view class="ph">{{ item.marketValue && item.marketValue + '元' }}</view> |
|
</view> |
|
<view class="line"> |
|
<view class="label">结算价</view> |
|
<view class="ph">{{ item.settlementPrice && item.settlementPrice + '元' }}</view> |
|
</view> |
|
<view class="line"> |
|
<view class="label">折扣率</view> |
|
<view class="ph">{{ item.discountRate }}</view> |
|
</view> |
|
<view class="line"> |
|
<view class="label">市场服务费</view> |
|
<view class="ph">{{ item.serviceFee }}元</view> |
|
</view> |
|
<view :class="['line req', {err: err === 'finalPrice' + item.dataOrCourseId + item.authority}]"> |
|
<view class="label">成交价</view> |
|
<view v-if="isDetail" class="ph">{{ item.finalPrice }}</view> |
|
<view class="inline" v-else> |
|
<input type="number" v-model="item.finalPrice" placeholder="请输入" @input="calcFinalValue(item)" @change="handleErr(item, 'finalPrice')"> |
|
元 |
|
</view> |
|
</view> |
|
<view v-if="(item.authority == 0 || item.authority == 3 || item.authority == 4) && item.shipInfo" class="line"> |
|
<view class="label">发货信息</view> |
|
<view class="ph ship-info" v-html="item.shipInfo" @click="copy(item)"></view> |
|
</view> |
|
</view> |
|
</li> |
|
</ul> |
|
</view> |
|
</template> |
|
</view> |
|
|
|
<view class="bottom"> |
|
<template v-if="!edited && !orderId"> |
|
<view class="next-wrap"> |
|
<view class="lg-btn next" @click="toAdd(0)">下一步</view> |
|
</view> |
|
</template> |
|
<template v-else> |
|
<view v-if="!orderId" class="add-wrap"> |
|
<view class="lg-btn" @click="toAdd(1)"> |
|
<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> |
|
<view v-if="!isDetail" class="btn" @click="submit">提交({{ courses.length }})</view> |
|
</view> |
|
</template> |
|
</view> |
|
|
|
<view v-if="isDetail && form.isDel !== 1 && form.orderStatus === 1" class="action"> |
|
<view class="item" @click="toAction(`../orderDetail/orderDetail?orderId=${orderId}&action=renew`)"> |
|
<uni-icons class="icon" custom-prefix="iconfont" type="icon-product" size="30" color="#959595"></uni-icons> |
|
<view class="text">续费</view> |
|
</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="create" @click="toClient">找不到客户?马上创建</view> |
|
<view class="list"> |
|
<view class="item" v-for="item in customerList" @click="customerChange(item)">{{ item.customerName }}</view> |
|
</view> |
|
</view> |
|
</view> |
|
</template> |
|
|
|
<script> |
|
import { productTypeList, delCart } from '@/apis/modules/product.js' |
|
import { queryCustomer, queryCustomerDetails } from '@/apis/modules/client.js' |
|
import { add, getDetail, renew, queryCitySettlementPrice, getOrderOtherTime } from '@/apis/modules/order.js' |
|
import { getPartnerTeamRates } from '@/apis/modules/parner.js' |
|
export default { |
|
data() { |
|
return { |
|
isDetail: false, |
|
isRenew: 0, // 续费 |
|
orderId: '', |
|
edited: false, |
|
shopCart: false, |
|
orderTypes: [{ |
|
text: '正式', |
|
value: 1 |
|
}, { |
|
text: '试用', |
|
value: 2 |
|
}], |
|
form: { |
|
businessManagerName: uni.getStorageSync('team').userName, |
|
// orderNumber: '', // 编号 |
|
provinceId: '', // 省份id |
|
provinceName: '', |
|
orderContact: '', // 联系人 |
|
email: '', |
|
customerId: '', // 客户id |
|
customerName: '', |
|
orderType: '', |
|
cityId: '', |
|
cityName: '', |
|
phone: '', |
|
orderAmount: 0, |
|
customerName: '', |
|
profit: 0, // 利润 |
|
purchaseCost: 0, // 采购成本 |
|
teamId: uni.getStorageSync('team').id, |
|
businessManagerId: this.$util.getBmId() |
|
}, |
|
courseList: {}, |
|
courses: [], // 缓存的产品列表 |
|
contract: { // 合同信息 |
|
contractName: '', // 合同名称 |
|
contractFile: '', // 合同文件 |
|
contractMoney: '', // 合同金额 |
|
contractNumber: '',// 合同编号 |
|
startTime: '', // 期限-头 |
|
endTime: '' // 期限-尾 |
|
}, |
|
|
|
customerVisible: false, |
|
keyword: '', |
|
searchTimer: null, |
|
customerList: [], |
|
customerListAll: [], |
|
err: '', |
|
promises: [], |
|
rate: '', |
|
orderRepeat:[], |
|
units: [{ |
|
text: '日', |
|
id: 0 |
|
}, { |
|
text: '月', |
|
id: 1 |
|
}, { |
|
text: '年', |
|
id: 2 |
|
}], |
|
unitText: ['日', '月', '年'], |
|
} |
|
}, |
|
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 |
|
const { action } = options |
|
this.isRenew = action === 'renew' |
|
this.edited = options.edited // 已经编辑过产品的标识 |
|
this.shopCart = options.shopCart // 从购物车进来的标识 |
|
const store = uni.getStorageSync('courses') |
|
const form = uni.getStorageSync('orderForm') |
|
if (form) { |
|
this.form = form |
|
uni.removeStorageSync('orderForm') |
|
} |
|
this.getRate() |
|
if (this.orderId) { |
|
this.getInfo() |
|
} else if (options.edited && store) { // 不是从购物车进来,并且有产品缓存(即是从当前页面点下一步编辑完产品回来的情况),则处理缓存里的产品 |
|
uni.showLoading({ |
|
title: '加载中' |
|
}) |
|
// 新增取缓存,取了删除 |
|
const list = [] |
|
for (const i in store) { |
|
// 发货信息处理 |
|
store[i].list.map(e => { |
|
let val = [] |
|
e.mallNonAssociatedLinks && e.mallNonAssociatedLinks.forEach(e => { |
|
val.push(e.urlName + ':' + e.url) |
|
}) |
|
e.shipInfo = e.shipContent || val.join('<br>') |
|
e.copyInfo = e.shipContent || val.join(';') |
|
}) |
|
list.push(...store[i].list) |
|
} |
|
this.courseList = store |
|
this.courses = list |
|
uni.pageScrollTo({ |
|
selector: '#products' |
|
}) |
|
try { |
|
uni.removeStorageSync('courses') |
|
} catch (e) {} |
|
this.calcTotal() |
|
this.$nextTick(() => { |
|
uni.hideLoading() |
|
}) |
|
} |
|
|
|
// 如果是客户订单记录页面点的新增,会有客户id,要默认选中该客户 |
|
const { customerId } = options |
|
customerId && this.customerChange({ |
|
customerId |
|
}) |
|
// 非详情才需要查询客户 |
|
if (!this.isDetail) { |
|
this.getCustomer() |
|
} |
|
// 设置标题 |
|
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 // 非续费才回显合同 |
|
this.form = order.order |
|
order.orderOther.forEach(e => { |
|
e.settlementPriceUnit = e.settlementPrice |
|
}) |
|
this.courses = order.orderOther |
|
for (let i = 0; i < 5; i++) { |
|
this.handleRenew(i) |
|
} |
|
Promise.all(this.promises).then(_ => { |
|
this.handleProduct(this.courses) |
|
this.calcTotal() |
|
uni.hideLoading() |
|
}) |
|
}).catch(e => { |
|
uni.hideLoading() |
|
}) |
|
}, |
|
// 转换产品列表 |
|
handleProduct(list) { |
|
let courses = {} |
|
// 产品分类 |
|
productTypeList().then(res => { |
|
res.typeList.forEach(e => { |
|
courses['list' + e.typeId] = { |
|
shrink: false, |
|
name: e.typeName, |
|
deadline: '', |
|
unit: '', |
|
list: [] |
|
} |
|
}) |
|
const isTrial = this.form.orderType == 2 |
|
// 3个分类的课程分别push到不同数组(0->理论 1-实训 2 数据产品) |
|
list.map(e => { |
|
// 发货信息处理 |
|
let val = [] |
|
e.mallNonAssociatedLinks && e.mallNonAssociatedLinks.forEach(e => { |
|
val.push(e.urlName + ':' + e.url) |
|
}) |
|
e.shipInfo = e.shipContent || val.join('<br>') |
|
e.copyInfo = e.shipContent || val.join(';') |
|
|
|
e.serviceFee = (e.finalPrice * (this.rate / 100)).toFixed(2) // 服务费 != 0 && 才需要算 |
|
|
|
// 试用则默认赋值1月 |
|
if (isTrial) { |
|
e.periodOfUse = 1 |
|
e.options = 1 |
|
this.calcDate(e, !e.authority) |
|
} |
|
courses['list' + e.typeId].list.push(e) |
|
}) |
|
this.courseList = courses |
|
}).catch(e => {}) |
|
}, |
|
// 处理开始结束时间和订单状态(参考pc,订单模块不是本人开发的,所以也不懂这里逻辑) |
|
handleRenew(authority) { |
|
const list = this.courses.filter(e => e.authority == authority) |
|
const productId = list.map(e => e.mallId) |
|
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 => { |
|
// e.settlementPriceUnit = e.settlementPrice |
|
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] |
|
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() |
|
}) |
|
})) |
|
}, |
|
// 获取客户列表 |
|
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 = '' |
|
}, |
|
// 客户名称选择回调 |
|
async customerChange(item) { |
|
const { form } = this |
|
// 获取客户详情 |
|
const { result } = await queryCustomerDetails({ |
|
customerId: item.customerId |
|
}) |
|
this.handleErr('customerName') |
|
const e = result.customer |
|
const { provinceId, cityId } = e |
|
form.customerId = e.customerId |
|
form.customerName = e.customerName |
|
form.provinceId = provinceId |
|
form.cityId = cityId |
|
form.provinceName = e.provinceName |
|
form.cityName = e.cityName |
|
form.phone = e.phone |
|
form.email = e.email |
|
form.orderContact = e.name |
|
|
|
// 获取平台结算价重新计算课程的相关参数 |
|
const list = this.courseList |
|
const courses = [] |
|
const promises = [] |
|
for (const i in list) { |
|
list[i].list.forEach(n => { |
|
promises.push(new Promise(async (resolve, reject) => { |
|
const res = await queryCitySettlementPrice(n.mallId, provinceId, cityId) |
|
if (res.mallPrice) n.settlementPriceUnit = res.mallPrice.discountRate || 0 |
|
courses.push(n) |
|
resolve() |
|
})) |
|
}) |
|
} |
|
Promise.all(promises).then(_ => { |
|
this.courses = courses |
|
this.calcTotal() |
|
this.closeCustomer() |
|
}) |
|
}, |
|
// 查询合伙人团队费率 |
|
getRate() { |
|
getPartnerTeamRates({ |
|
teamId: uni.getStorageSync('team').teamId |
|
}).then(({ teamRates }) => { |
|
this.rate = teamRates.annualMarketingFee || 0 |
|
}).catch(res => {}) |
|
}, |
|
// 跳转 |
|
toAdd(add) { |
|
const { form } = this |
|
if (!form.customerId) { |
|
this.err = 'customerName' |
|
return this.$util.errMsg('请选择客户!') |
|
} |
|
if (!form.orderType) { |
|
this.err = 'orderType' |
|
return this.$util.errMsg('请选择订单类型!') |
|
} |
|
|
|
add && uni.setStorageSync('courses', this.courses) |
|
uni.setStorageSync('orderForm', this.form) |
|
const { customerId, orderType } = this.form |
|
// 从购物车进来的,直接跳转到编辑产品;否则跳转到选择产品 |
|
const url = this.shopCart ? |
|
`../editCourse/editCourse` : |
|
`../addCourse/addCourse` |
|
this.$util.to(url + `?orderType=${orderType}&customerId=${customerId}&provinceId=${this.form.provinceId}&cityId=${this.form.cityId}`) |
|
}, |
|
// 前往创建客户 |
|
toClient() { |
|
this.shopCart || uni.setStorageSync('courses', this.courses) |
|
this.$util.to(`/order/clientDetail/clientDetail?order=1${this.shopCart ? '&shopCart=1' : ''}`) |
|
}, |
|
// 删除课程 |
|
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 |
|
}, |
|
// 计算订单总额 |
|
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 { |
|
this.calcDiscount(e) |
|
this.dealSettlePrice(e) |
|
// this.calcFinalPrice(e) |
|
const curPurchase = +e.settlementPrice + +e.serviceFee |
|
purchase += curPurchase |
|
profit += +e.finalPrice - curPurchase |
|
} |
|
}) |
|
form.purchaseCost = purchase.toFixed(2) |
|
form.profit = profit.toFixed(2) |
|
form.orderAmount = (+form.purchaseCost + +form.profit).toFixed(2) |
|
}, |
|
// 计算订单总额 |
|
calcAmount() { |
|
const { form } = this |
|
const list = this.courses |
|
let purchase = 0 // 总采购成本 |
|
let profit = 0 // 总利润 |
|
list.map(e => { |
|
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).toFixed(2) |
|
}, |
|
// 使用期限输入回调 |
|
dateChange(row, fromData) { |
|
clearTimeout(this.timer) |
|
this.timer = setTimeout(() => { |
|
this.calcDate(row, fromData) |
|
}, 500) |
|
}, |
|
// 使用期限转换以及计算剩余天数 |
|
calcDate(row, fromData) { |
|
const { periodOfUse, options } = row |
|
let optionsData = 0 |
|
if (periodOfUse) { |
|
if (options == 1){ |
|
optionsData = periodOfUse === '12' ? 31536000000 : periodOfUse*30*24*60*60*1000 |
|
} else if (options == 2){ |
|
optionsData = periodOfUse*365*24*60*60*1000 |
|
} else { |
|
optionsData = periodOfUse*24*60*60*1000 |
|
} |
|
} |
|
let time = new Date(row.startTime).getTime() |
|
let endTime = time + optionsData |
|
row.endTime = time + optionsData |
|
let dt = new Date(endTime) |
|
row.endTime = (dt.getFullYear()) + "-" + (dt.getMonth() + 1) + "-" + (dt.getDate()) |
|
let endYear = endTime - time |
|
let endYears = endYear/1000/60/60/24 |
|
row.remainingPeriod = endYears |
|
const unit = row.options // 使用期限单位 |
|
const useUnit = row.periodOfUse // 使用期限 |
|
// 计算市场价 |
|
const price = row.marketPrice || 0 // 市场单价 |
|
// 结算单价是元/年,所以如果选择的不是年,要进行换算(日:/365,月:/12) |
|
row.marketValue = (!unit ? |
|
price / 365 * useUnit : |
|
unit === 1 ? |
|
price / 12 * useUnit : |
|
price * useUnit).toFixed(2) |
|
this.dealSettlePrice(row) |
|
// 只有改变了起止日期才需要调接口查询订单,该接口作用是把开始时间传过去,会返回一个提示或者时间,如果是时间,则把时间+1天,如果是提示,则无法保存 |
|
if (!fromData) { |
|
const cId = row.dataOrCourseId |
|
const date = new Date(row.startTime) |
|
const orderRepeat = this.orderRepeat |
|
getOrderOtherTime({ |
|
authority: row.authority, |
|
customerId: this.form.customerId, |
|
id: cId, |
|
startTime: this.$util.formatDate(date, 'yyyy-MM-dd'), |
|
endTime: row.endTime |
|
}).then(res => { |
|
orderRepeat.includes(cId) && orderRepeat.splice(orderRepeat.findIndex(e => e == cId), 1) |
|
if (res.endTime) { |
|
let time = new Date(res.endTime) |
|
time = new Date(time.setDate(time.getDate() + 1)) |
|
row.startTime = this.$util.formatDate(time, 'yyyy-MM-dd') |
|
} |
|
}).catch(res => { |
|
this.repeatMsg = res.message |
|
orderRepeat.includes(cId) || orderRepeat.push(cId) |
|
}) |
|
} |
|
// 折扣率 |
|
this.calcDiscount(row) |
|
}, |
|
dealSettlePrice(row) { |
|
// 如果是试用或者没选择,结算价和平台服务费都是0 |
|
if (this.form.orderType != 1) { |
|
row.settlementPrice = 0 |
|
row.serviceFee = 0 |
|
} else { |
|
const unit = row.options // 使用期限单位 |
|
const useUnit = row.periodOfUse // 使用期限 |
|
let sPrice = '' |
|
// 结算单价。计算规则:结算单价(**元/年)*购买时长(单位年)*数量(课程为1,数据为账号数量) |
|
const priceUnit = row.settlementPriceUnit |
|
sPrice = ((!unit ? |
|
priceUnit / 365 * useUnit : |
|
unit === 1 ? |
|
priceUnit / 12 * useUnit : |
|
priceUnit * useUnit) * (row.authority ? |
|
1 : |
|
row.accountNum)).toFixed((2)) |
|
row.settlementPrice = this.$util.handleNaN(sPrice) |
|
// 平台服务费 |
|
row.serviceFee = (row.finalPrice * (this.rate / 100)).toFixed(2) |
|
this.calcAmount() |
|
} |
|
}, |
|
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%' |
|
}, |
|
// 批量设置产品时间 |
|
batchDeadlineChange (c) { |
|
c.list.map(e => { |
|
e.periodOfUse = c.deadline |
|
this.calcDate(e, !e.authority) |
|
}) |
|
}, |
|
// 批量设置产品期限单位 |
|
batchUnitChange(c) { |
|
const that = this |
|
uni.showActionSheet({ |
|
title: '标题', |
|
itemList: that.unitText, |
|
success: ({ tapIndex }) => { |
|
c.unit = tapIndex |
|
c.list.map(e => { |
|
e.options = tapIndex |
|
that.calcDate(e, !e.authority) |
|
}) |
|
} |
|
}) |
|
}, |
|
// 单个产品选择年月日 |
|
selectUnit(item) { |
|
const that = this |
|
uni.showActionSheet({ |
|
title: '标题', |
|
itemList: that.unitText, |
|
success: ({ tapIndex }) => { |
|
item.options = tapIndex |
|
that.calcDate(item) |
|
} |
|
}) |
|
}, |
|
// 成交价修改后,计算成交单价,数据才需要 计算规则:成交价/账号数/时间(成交单价为元/账号/年,所以时间要换算成年的单位去计算) |
|
calcFinalValue(row) { |
|
clearTimeout(this.timer) |
|
this.timer = setTimeout(() => { |
|
const { authority, periodOfUse, options, accountNum, finalPrice } = row |
|
if (!authority && periodOfUse && accountNum && finalPrice) { |
|
row.finalValue = (finalPrice / accountNum / periodOfUse).toFixed(2) |
|
} |
|
// 折扣率 |
|
this.calcDiscount(row) |
|
this.dealSettlePrice(row) |
|
}, 500) |
|
}, |
|
// 计算成交价。计算规则:成交单价*账号数*时间(成交单价为元/账号/年,所以时间要换算成年的单位去计算) |
|
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) |
|
}, |
|
// 复制发货信息 |
|
copy(row) { |
|
const that = this |
|
uni.setClipboardData({ |
|
data: row.copyInfo, |
|
success() { |
|
that.$util.sucMsg('复制成功') |
|
} |
|
}) |
|
}, |
|
// 处理错误提示 |
|
handleErr(val) { |
|
if (val === this.err) this.err = '' |
|
}, |
|
toAction(url) { |
|
uni.redirectTo({ |
|
url |
|
}) |
|
}, |
|
// 消息推送授权 |
|
publicNotice() { |
|
uni.requestSubscribeMessage({ |
|
tmplIds: ['8pDVfWYqh9c-nn3CeA1NXJtBxdd1FYiCtrl5BeLvbgU', 'mg3RiI8tDNaChVQKjImXzYK63C5Il3BENfBwF0NDzDM'], |
|
success: (res) => { |
|
uni.switchTab({ |
|
url: '/pages/orders/orders' |
|
}) |
|
}, |
|
fail: function(err) { |
|
uni.showToast({ |
|
title: err, |
|
duration: 2000, |
|
icon: 'error' |
|
}); |
|
} |
|
}) |
|
}, |
|
// 从购物车选择产品下单的,则提交订单后删除购物车相对应产品 |
|
async delShopCart(courses) { |
|
const list = courses.filter(e => e.shopCartId) |
|
list.length && await delCart(list.map(e => e.shopCartId)) |
|
}, |
|
// 提交 |
|
submit() { |
|
const { form } = this |
|
const courses = [] |
|
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) |
|
} |
|
if (!courses.length) return this.$util.errMsg('请选择课程权限或数据权限后再确认订单!') |
|
let invalid = 0 |
|
courses.forEach(e => { |
|
if (!e.periodOfUse) { |
|
invalid = 1 |
|
return this.$util.errMsg('请输入使用期限!') |
|
} |
|
e.startTime = this.$util.formatDate(new Date(e.startTime), 'yyyy-MM-dd') |
|
}) |
|
if (invalid) return false |
|
if (this.isRenew || courses.some(e => e.renew)) form.orderNature = 2 |
|
uni.showLoading({ |
|
title: '提交中' |
|
}) |
|
const data = { |
|
contractInformation: this.contract, // 合同信息 |
|
order: form, // 订单基本数据 |
|
orderOther: courses // 产品列表 |
|
} |
|
// 职站商城只能新增订单跟续费订单,这两个动作都是调新增接口,只有发货跟编辑才是调编辑接口 |
|
add(data).then(res => { |
|
this.delShopCart(courses) |
|
uni.hideLoading() |
|
this.$util.sucMsg('添加成功') |
|
|
|
// #ifdef MP-WEIXIN |
|
this.publicNotice() |
|
// #endif |
|
|
|
// #ifdef MP-TOUTIAO |
|
setTimeout(() => { |
|
uni.switchTab({ |
|
url: '/pages/orders/orders' |
|
}) |
|
}, 1500) |
|
// #endif |
|
}).catch(res => { |
|
uni.hideLoading() |
|
}) |
|
} |
|
} |
|
} |
|
</script> |
|
|
|
<style scoped lang="scss"> |
|
.page { |
|
padding-bottom: 420rpx; |
|
|
|
.type-wrap { |
|
display: flex; |
|
justify-content: space-between; |
|
align-items: center; |
|
} |
|
.batch { |
|
display: inline-flex; |
|
align-items: center; |
|
.deadline, .unit { |
|
font-size: 28rpx; |
|
color: #333; |
|
} |
|
.deadline { |
|
width: 130rpx; |
|
} |
|
.unit { |
|
min-width: 80rpx; |
|
text-align: center; |
|
} |
|
} |
|
} |
|
.show { |
|
padding-bottom: 280rpx; |
|
} |
|
.form-list { |
|
.customer-wrap { |
|
text-align: right; |
|
} |
|
} |
|
.create { |
|
padding: 0 20rpx; |
|
font-size: 20rpx; |
|
text-align: right; |
|
color: #f00; |
|
} |
|
.pro-wrap { |
|
position: relative; |
|
padding: 0; |
|
.l-title { |
|
margin: 0 24rpx; |
|
} |
|
} |
|
.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; |
|
max-width: 480rpx; |
|
margin-right: 10rpx; |
|
} |
|
.course-action { |
|
display: inline-flex; |
|
align-items: center; |
|
} |
|
.course-btn { |
|
padding: 0 16rpx; |
|
font-size: 28rpx; |
|
white-space: nowrap; |
|
} |
|
.del { |
|
width: 40rpx; |
|
margin-right: 20rpx; |
|
} |
|
.icon { |
|
width: 60rpx; |
|
height: 60rpx; |
|
margin-right: 12rpx; |
|
border-radius: 10rpx; |
|
} |
|
.info { |
|
padding: 12rpx 24rpx; |
|
} |
|
.line { |
|
display: flex; |
|
justify-content: space-between; |
|
padding: 28rpx 0; |
|
font-size: 12px; |
|
border-bottom: 1px solid #E6E8ED; |
|
&:last-child { |
|
border-bottom: 0; |
|
} |
|
} |
|
.label { |
|
margin-right: 20rpx; |
|
font-size: 28rpx; |
|
white-space: nowrap; |
|
color: #333; |
|
} |
|
.ph { |
|
font-size: 28rpx; |
|
color: #999; |
|
&.ship-info { |
|
text-align: right; |
|
} |
|
} |
|
.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; |
|
} |
|
.period { |
|
flex: none; |
|
width: 100rpx; |
|
font-size: 28rpx; |
|
text-align: center; |
|
} |
|
} |
|
.bottom { |
|
z-index: 2; |
|
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; |
|
} |
|
.next-wrap { |
|
padding: 24rpx 24rpx 0; |
|
} |
|
/deep/.lg-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; |
|
} |
|
&.next { |
|
color: #fff; |
|
background-color: #007EFF; |
|
} |
|
} |
|
} |
|
.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; |
|
} |
|
.btn { |
|
width: 180rpx; |
|
margin-left: 30rpx; |
|
line-height: 80rpx; |
|
font-size: 32rpx; |
|
text-align: center; |
|
color: #fff; |
|
border-radius: 10rpx; |
|
background-color: #007EFF; |
|
} |
|
} |
|
.unit { |
|
display: inline-flex; |
|
align-items: center; |
|
.icon { |
|
width: 28rpx; |
|
margin-left: 20rpx; |
|
} |
|
input { |
|
font-size: 28rpx; |
|
} |
|
text{ |
|
font-size: 28rpx; |
|
} |
|
&.placeholder { |
|
color: #797979 !important; |
|
} |
|
} |
|
.line { |
|
.inline { |
|
display: flex; |
|
align-items: center; |
|
font-size: 28rpx; |
|
input { |
|
text-align: right; |
|
margin-right: 10rpx; |
|
margin-left: 20rpx; |
|
color: #333; |
|
} |
|
} |
|
.edit { |
|
margin-left: 10rpx; |
|
} |
|
} |
|
.action { |
|
z-index: 2; |
|
position: fixed; |
|
bottom: 24rpx; |
|
display: flex; |
|
justify-content: flex-end; |
|
width: 100%; |
|
padding-right: 50rpx; |
|
padding-bottom: env(safe-area-inset-bottom); |
|
// background-color: #fff; |
|
// border-top: 1px solid #f3f3f3; |
|
// box-shadow: 0 -2px 2px #f5f5f5; |
|
box-sizing: border-box; |
|
&:empty { |
|
padding: 0 !important; |
|
} |
|
.item { |
|
text-align: center; |
|
} |
|
.text { |
|
font-size: 10px; |
|
color: #959595; |
|
} |
|
} |
|
</style>
|
|
|