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.
283 lines
7.8 KiB
283 lines
7.8 KiB
3 years ago
|
<template>
|
||
|
<view class="page">
|
||
|
<uni-card :is-shadow="false" :border="false" padding="0" is-full>
|
||
|
<uni-search-bar class="search" radius="5" placeholder="请输入产品名称" clearButton="auto" cancelButton="none" v-model="keyword" />
|
||
|
</uni-card>
|
||
|
|
||
|
<ul class="tab">
|
||
|
<li v-for="(tab, i) in tabs" :class="{active: curTab === tab.id}" @click="tabChange(tab)">{{ tab.name }}</li>
|
||
|
</ul>
|
||
|
|
||
|
<ul class="list">
|
||
|
<li v-for="item in list">
|
||
3 years ago
|
<uni-data-checkbox class="check" multiple v-model="item.check" :localdata="item.checkData"></uni-data-checkbox>
|
||
3 years ago
|
<image v-if="item.miniProgramPictureAddress" class="icon" :src="item.miniProgramPictureAddress" mode="widthFix"></image>
|
||
3 years ago
|
{{ item.productName }}
|
||
3 years ago
|
</li>
|
||
|
</ul>
|
||
3 years ago
|
<uni-load-more :status="status" />
|
||
3 years ago
|
|
||
|
<view class="btn-wrap">
|
||
|
<uni-data-checkbox class="check" multiple v-model="checkAll" :localdata="checkAllData" @change="checkChange"></uni-data-checkbox>
|
||
|
<view class="btn" @click="submit">确定</view>
|
||
|
</view>
|
||
|
</view>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { AppletsDataProductList } from '@/apis/modules/product.js'
|
||
3 years ago
|
import { renew } from '@/apis/modules/order.js'
|
||
3 years ago
|
export default {
|
||
|
data() {
|
||
|
return {
|
||
|
orderType: 0,
|
||
3 years ago
|
customerId: '',
|
||
3 years ago
|
curTab: '',
|
||
|
tabs: [
|
||
|
{
|
||
3 years ago
|
name: '全部',
|
||
3 years ago
|
id: ''
|
||
|
},
|
||
|
{
|
||
|
name: '实训课程',
|
||
|
id: 1
|
||
|
},
|
||
|
{
|
||
|
name: '理论课程',
|
||
|
id: 0
|
||
|
},
|
||
|
{
|
||
|
name: '数据产品',
|
||
3 years ago
|
id: 2
|
||
3 years ago
|
}
|
||
|
],
|
||
3 years ago
|
reachBottom: 0, // 是否是上拉加载。0->否,1->是,-1->加载完所有数据
|
||
|
status: 'more', // 上拉加载状态 more|loading|noMore
|
||
3 years ago
|
searchTimer: null,
|
||
|
orderStatus: '',
|
||
|
productStatus: '',
|
||
|
keyword: '',
|
||
|
list: [],
|
||
|
listAll: [],
|
||
|
page: 1,
|
||
|
pageSize: 10,
|
||
|
checkData: [{
|
||
|
text: '',
|
||
|
value: 1
|
||
|
}],
|
||
|
checkAll: [],
|
||
|
checkAllData: [{
|
||
|
text: '全部',
|
||
|
value: 1
|
||
|
}],
|
||
3 years ago
|
courses: uni.getStorageSync('courses') || []
|
||
3 years ago
|
}
|
||
|
},
|
||
|
watch: {
|
||
|
keyword () {
|
||
|
clearTimeout(this.searchTimer)
|
||
|
this.searchTimer = setTimeout(() => {
|
||
|
this.getList()
|
||
|
}, 500)
|
||
|
}
|
||
|
},
|
||
|
// 下拉刷新
|
||
|
onPullDownRefresh() {
|
||
3 years ago
|
this.initList()
|
||
3 years ago
|
setTimeout(() => {
|
||
|
uni.stopPullDownRefresh()
|
||
|
}, 1500)
|
||
|
},
|
||
3 years ago
|
// 上拉加载
|
||
|
onReachBottom() {
|
||
|
if (this.reachBottom >= 0) {
|
||
|
this.reachBottom = 1
|
||
|
this.status = 'loading'
|
||
|
this.getList()
|
||
|
}
|
||
|
},
|
||
3 years ago
|
onShow() {
|
||
|
const pages = getCurrentPages()
|
||
3 years ago
|
const { options } = pages[pages.length - 1]
|
||
|
this.orderType = options.orderType
|
||
|
this.customerId = options.customerId
|
||
3 years ago
|
this.getList()
|
||
|
},
|
||
|
methods: {
|
||
3 years ago
|
// 获取课程列表
|
||
3 years ago
|
getList() {
|
||
3 years ago
|
AppletsDataProductList({
|
||
|
sort: '',
|
||
|
keywords: '',
|
||
|
productType: this.curTab,
|
||
|
pageNum: this.page,
|
||
|
pageSize: this.pageSize
|
||
|
}).then(({ data }) => {
|
||
|
const { records } = data
|
||
3 years ago
|
const list = this.courses
|
||
|
// 添加选择框字段
|
||
3 years ago
|
records.map(e => {
|
||
3 years ago
|
const checkData = {
|
||
|
text: '',
|
||
|
value: 1
|
||
|
}
|
||
3 years ago
|
e.check = []
|
||
3 years ago
|
// 筛选已经勾选的产品
|
||
3 years ago
|
if (list.find(n => n.dataOrCourseId == e.id)) {
|
||
3 years ago
|
checkData.disable = true // 已经选择了的则禁止选择
|
||
|
e.check = [1]
|
||
|
}
|
||
|
e.checkData = [checkData]
|
||
3 years ago
|
})
|
||
3 years ago
|
|
||
|
// 未加载完所有数据,并且不是筛选,则拼接list,否则直接赋值
|
||
|
this.list = this.reachBottom > 0 ? [...this.list, ...records] : records
|
||
|
this.page++ // 每次获取了数据后page+1
|
||
|
const noMore = this.list.length === data.total // 是否加载完所有数据
|
||
|
this.status = noMore ? 'noMore' : 'more' // 加载完了则设置为noMore
|
||
|
this.reachBottom = noMore ? -1 : 0 // 加载完了则设置为-1
|
||
3 years ago
|
}).catch(e => {})
|
||
|
},
|
||
3 years ago
|
initList() {
|
||
|
this.page = 1
|
||
|
this.reachBottom = 0
|
||
|
this.getList()
|
||
|
},
|
||
3 years ago
|
// tab切换
|
||
|
tabChange(tab) {
|
||
|
this.curTab = tab.id
|
||
3 years ago
|
this.initList()
|
||
3 years ago
|
},
|
||
|
// 全选
|
||
|
checkChange(e) {
|
||
|
const checked = !!e.detail.value.length
|
||
|
this.list.map(e => e.check = [checked ? 1 : '']) // 选中则为[1],取消选中为[]
|
||
|
},
|
||
|
// 生成产品参数
|
||
|
createParam(e) {
|
||
|
return {
|
||
3 years ago
|
dataOrCourseId: e.id, // id
|
||
|
productName: e.productName, // 名称
|
||
3 years ago
|
periodOfUse: '', // 使用期限
|
||
|
startTime: this.$util.formatDate(new Date(), 'yyyy-MM-dd'), // 开始
|
||
|
endTime: '', // 终止
|
||
|
remainingPeriod: '', // 剩余期限
|
||
|
marketValue: '', // 市场价
|
||
|
marketPrice: e.marketPrice, // 市场单价
|
||
|
finalPrice: this.orderType === 2 ? 0 : '', // 成交价
|
||
|
discountRate: '', // 折扣率
|
||
3 years ago
|
accountNum: e.productType === 2 ? '' : 1, // 账号数
|
||
3 years ago
|
totalAmount: '', // 总价
|
||
|
isEnable: 1, // 启用否:1启用,0禁用
|
||
|
ship: 0, // 发货否(0未发货,1已发货,默认不发货)
|
||
3 years ago
|
authority: e.productType === 2 ? 0 : 1, // 区分权限 0为数据平台权限,1为课程权限
|
||
|
productType: e.productType, // 课程分类 (0->理论 1-实训 2 数据产品)
|
||
3 years ago
|
options: 1,
|
||
3 years ago
|
miniProgramPictureAddress: e.miniProgramPictureAddress, // 图标
|
||
3 years ago
|
settlementPrice: '', // 结算价
|
||
|
settlementMethod: e.settlementMethod, // 结算方式,0为单价,1为分成
|
||
|
settlementPriceUnit: e.settlementPrice, // 结算单价
|
||
|
businessProportion: e.businessProportion, // 商务占比
|
||
3 years ago
|
serviceFee: 0 // 平台服务费(前端计算后展示,不入库)
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
// 判断是否为客户已有的课程
|
||
|
handleRenew(authority, customerId, productId, result, resolve, reject) {
|
||
|
renew({
|
||
|
authority,
|
||
|
customerId,
|
||
|
productId
|
||
|
}).then(({ orderOthers }) => {
|
||
|
result.map(e => {
|
||
|
const item = orderOthers.find(n => n.dataOrCourseId == e.dataOrCourseId && n.authority == authority && e.authority == authority)
|
||
|
if (item) {
|
||
|
let date = new Date(item.endTime)
|
||
|
date = new Date(date.setDate(date.getDate() + 1))
|
||
|
e.startTime = this.$util.formatDate(date, 'yyyy-MM-dd')
|
||
|
}
|
||
|
})
|
||
|
resolve()
|
||
|
}).catch(e => {
|
||
|
reject()
|
||
|
})
|
||
|
},
|
||
3 years ago
|
// 确定
|
||
|
submit() {
|
||
|
const list = this.list.filter(e => e.check.length) // 筛选出选中了的产品
|
||
|
if (list.length) {
|
||
3 years ago
|
const result = this.courses
|
||
|
const courseIds = []
|
||
|
const dataIds = []
|
||
|
const { customerId } = this
|
||
3 years ago
|
list.map(e => {
|
||
3 years ago
|
// 新勾选的产品,则获取到id,下面要调用,
|
||
3 years ago
|
if (!result.find(n => n.dataOrCourseId == e.id && n.authority == e.authority)) {
|
||
3 years ago
|
e.productType === 2 ? dataIds.push(e.id) : courseIds.push(e.id)
|
||
|
result.push(this.createParam(e))
|
||
|
}
|
||
|
})
|
||
|
const promises = []
|
||
3 years ago
|
// 课程和数据的分别调接口
|
||
3 years ago
|
dataIds.length && promises.push(new Promise((resolve, reject) => {
|
||
|
this.handleRenew(0, customerId, dataIds, result, resolve, reject)
|
||
|
}))
|
||
|
courseIds.length && promises.push(new Promise((resolve, reject) => {
|
||
|
this.handleRenew(1, customerId, courseIds, result, resolve, reject)
|
||
|
}))
|
||
|
Promise.all(promises).then(_ => {
|
||
|
uni.setStorageSync('courses', result) // 把选中的产品添加至缓存
|
||
|
uni.redirectTo({
|
||
|
url: `../editCourse/editCourse?customerId=${customerId}`
|
||
|
})
|
||
3 years ago
|
})
|
||
|
} else {
|
||
|
this.$util.errMsg('请选择产品!')
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
|
.page {
|
||
3 years ago
|
padding-bottom: 130rpx;
|
||
3 years ago
|
}
|
||
|
.list {
|
||
|
li {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
padding: 30rpx 24rpx;
|
||
|
margin: 16rpx 24rpx;
|
||
|
font-size: 30rpx;
|
||
|
color: #333;
|
||
|
background-color: #fff;
|
||
|
border-radius: 16rpx;
|
||
|
}
|
||
|
.icon {
|
||
|
width: 80rpx;
|
||
|
margin: 0 20rpx;
|
||
|
}
|
||
|
}
|
||
|
/deep/.check {
|
||
|
.checklist-box {
|
||
|
margin: 0 !important;
|
||
|
}
|
||
|
.checkbox__inner {
|
||
|
width: 40rpx !important;
|
||
|
height: 40rpx !important;
|
||
|
border-radius: 50% !important;
|
||
|
}
|
||
|
.checkbox__inner-icon {
|
||
|
top: 8rpx !important;
|
||
|
left: 14rpx !important;
|
||
|
}
|
||
|
}
|
||
|
.btn-wrap {
|
||
|
justify-content: space-between;
|
||
|
.btn {
|
||
|
width: 340rpx;
|
||
|
margin-left: 27rpx;
|
||
|
}
|
||
|
}
|
||
|
</style>
|