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.

386 lines
12 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-wrap">
1 year ago
<view class="tab">
<li :class="{active: curTab === ''}" @click="tabChange('')">全部</li>
</view>
<scroll-view scroll-x :scroll-left="scrollLeft" class="tab tab-scroll">
<li v-for="(tab, i) in tabs" :key="i" :class="{active: curTab === tab.id}" @click="tabChange(tab.id)">{{ tab.name }}</li>
</scroll-view>
3 years ago
</ul>
<ul class="list">
<li v-for="(item, i) in list" :key="i">
2 years ago
<uni-data-checkbox v-if="item.check" class="check" multiple :value="[1]" :localdata="item.checkData" @change="e => checkChange(e, i)"></uni-data-checkbox>
<uni-data-checkbox v-else class="check" multiple v-model="item.check" :localdata="item.checkData" @change="e => checkChange(e, i)"></uni-data-checkbox>
2 years ago
<image class="icon" :src="$util.getIcon(item)" mode="widthFix"></image>
{{ item.productName }}
3 years ago
</li>
</ul>
<uni-load-more :status="status" />
3 years ago
<view class="btn-wrap">
2 years ago
<uni-data-checkbox class="check" multiple v-model="checkAll" :localdata="checkAllData" @change="allChange"></uni-data-checkbox>
<view class="btn" @click="submit">确定({{ checked.length }})</view>
3 years ago
</view>
</view>
</template>
<script>
1 year ago
import { productTypeList, listOfGoods } from '@/apis/modules/product.js'
import { renew, queryCitySettlementPrice } from '@/apis/modules/order.js'
3 years ago
export default {
data() {
return {
// authority: 权限。0数据平台,1为课程,2职站增值模块,3实训课程(非集成),4实验工具
2 years ago
orderType: 1,
3 years ago
customerId: '',
provinceId: '',
cityId: '',
3 years ago
curTab: '',
1 year ago
tabs: [],
scrollLeft: 0,
reachBottom: 0, // 是否是上拉加载。0->否,1->是,-1->加载完所有数据
status: 'more', // 上拉加载状态 more|loading|noMore
3 years ago
searchTimer: null,
orderStatus: '',
productStatus: '',
keyword: '',
list: [],
listAll: [],
page: 1,
pageSize: 10,
2 years ago
check: [1],
noCheck: [],
3 years ago
checkData: [{
text: '',
value: 1
}],
checkAll: [],
checkAllData: [{
text: '全部',
value: 1
}],
2 years ago
checked: uni.getStorageSync('courses') || [], // 已经勾选的集合
3 years ago
courses: uni.getStorageSync('courses') || []
3 years ago
}
},
watch: {
keyword () {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(() => {
2 years ago
this.initList()
3 years ago
}, 500)
}
},
// 下拉刷新
onPullDownRefresh() {
this.initList()
3 years ago
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1500)
},
// 上拉加载
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
this.provinceId = options.provinceId
this.cityId = options.cityId
this.getTypes()
3 years ago
this.getList()
},
methods: {
1 year ago
// 产品类型
getTypes() {
1 year ago
productTypeList().then(res => {
res.typeList.forEach(e => {
e.id = e.typeId
e.name = e.typeName
})
1 year ago
this.tabs.push(...res.typeList)
}).catch(e => {})
},
3 years ago
// 获取课程列表
3 years ago
getList() {
2 years ago
uni.showLoading({
title: '加载中'
})
listOfGoods({
pageNum: this.page,
pageSize: this.pageSize,
sort: 0,
isShelves: 0,
hotTag: 1,
productName: this.keyword,
1 year ago
productType: this.curTab,
}).then(({ page }) => {
const { records } = page
3 years ago
const list = this.courses
2 years ago
const all = this.checkAll.length // 是否勾选了全选
const pageChange = this.reachBottom > 0 // 是否是翻页
const { checked } = this // 已选数据
3 years ago
// 添加选择框字段
3 years ago
records.map(e => {
3 years ago
const checkData = {
text: '',
value: 1
}
e.check = (all && pageChange) || checked.find(n => n.mallId === e.mallId) ? 1 : 0
3 years ago
// 筛选已经勾选的产品
1 year ago
if (list.find(n => n.mallId == e.mallId)) {
2 years ago
// 已经选择了的则禁止选择,并且直接选中
checkData.disable = true
2 years ago
e.check = 1
3 years ago
}
e.checkData = [checkData]
3 years ago
})
// 未加载完所有数据,并且不是筛选,则拼接list,否则直接赋值
2 years ago
this.list = pageChange ? [...this.list, ...records] : records
this.page++ // 每次获取了数据后page+1
const noMore = this.list.length === page.total // 是否加载完所有数据
this.status = noMore ? 'noMore' : 'more' // 加载完了则设置为noMore
this.reachBottom = noMore ? -1 : 0 // 加载完了则设置为-1
2 years ago
uni.hideLoading()
}).catch(e => {
uni.hideLoading()
})
3 years ago
},
initList() {
this.page = 1
this.reachBottom = 0
this.getList()
},
3 years ago
// tab切换
1 year ago
tabChange(id) {
this.curTab = id
this.initList()
3 years ago
},
2 years ago
// 选择框回调
checkChange(e, i) {
const { checked } = this
const item = this.list[i]
const { mallId } = item
const include = checked.findIndex(e => e.mallId === mallId)
2 years ago
// 选中的情况下,该产品如果没有push到已选数组里,则push
if (e.detail.value.length) {
include === -1 && checked.push(item)
} else {
// 取消选中的情况下,如果已选数组里存在该产品,则移除
2 years ago
if (include !== -1) {
checked.splice(include, 1)
this.checkAll = []
}
2 years ago
}
},
3 years ago
// 全选
2 years ago
allChange(e) {
2 years ago
const isCheck = !!e.detail.value.length // 是否选中
const { checked, list } = this
list.map(e => {
e.check = isCheck ? 1 : 0
const { mallId } = e
const include = checked.findIndex(n => n.mallId === mallId)
2 years ago
// 选中的情况下,该产品如果没有push到已选数组里,则push
if (isCheck) {
include === -1 && checked.push(e)
} else {
// 取消选中的情况下,如果已选数组里存在该产品,则移除
include === -1 || checked.splice(include, 1)
}
})
3 years ago
},
// 生成产品参数
createParam(e, authority) {
2 years ago
const { orderType } = this
2 years ago
const trial = orderType == 2 // 是否是试用
3 years ago
return {
dataOrCourseId: e.associatedProduct, // id
mallId: e.mallId,
productName: e.productName, // 名称
3 years ago
periodOfUse: '', // 使用期限
startTime: this.$util.formatDate(new Date(), 'yyyy-MM-dd'), // 开始
endTime: '', // 终止
remainingPeriod: '', // 剩余期限
marketValue: '', // 市场价
marketPrice: e.marketUnitPrice, // 市场单价
2 years ago
finalPrice: trial ? 0 : '', // 成交价
2 years ago
finalValue: trial ? 0 : '', // 成交单价(数据产品特有)
2 years ago
discountRate: trial ? '0%' : '', // 折扣率
accountNum: authority ? 1 : '', // 账号数
3 years ago
totalAmount: '', // 总价
isEnable: 0, // 启用否:1启用,0禁用
3 years ago
ship: 0, // 发货否(0未发货,1已发货,默认不发货)
authority, // 区分权限 0为数据平台权限,1为课程权限
2 years ago
options: 2,
miniProgramPictureAddress: e.appletIcon || '', // 图标
2 years ago
settlementPrice: trial ? 0 : '', // 结算价
settlementPriceUnit: e.settlementPrice || 0, // 结算单价
serviceFee: 0 // 平台服务费(前端计算后展示,不入库)
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() {
2 years ago
const list = this.checked // 已选产品
3 years ago
if (list.length) {
3 years ago
const result = this.courses
1 year ago
console.log(123, result)
const list1 = [] // 实训、理论
const list0 = [] // 数据前瞻
const list2 = [] // 职站增值
const list3 = [] // 实训课程(非集成)
const list4 = [] // 实验工具
3 years ago
const { customerId } = this
const listPromise = []
list.forEach(async e => {
listPromise.push(new Promise(async (resolve, reject) => {
// 新勾选的产品,则获取到id,下面要调用
if (!result.find(n => (n.dataOrCourseId == e.associatedProduct || n.dataOrCourseId == e.dataOrCourseId) && n.authority == e.authority)) {
// 查询产品管理设置的平台结算价
1 year ago
if (this.provinceId) {
const res = await queryCitySettlementPrice(e.mallId, this.provinceId, this.cityId)
if (res.mallPrice) e.settlementPrice = res.mallPrice.discountRate
}
console.log(44, e)
const classId = e.classificationId
const pid = +e.associatedProduct
if (classId == 1 || classId == 2) {
list1.push(pid)
} else if (classId == 3) {
list2.push(pid)
} else if (classId == 4) {
list3.push(pid)
} else if (classId == 5) {
list0.push(pid)
} else if (classId == 6) {
list4.push(pid)
}
result.push(this.createParam(e, this.$util.getOrderType(classId)))
resolve()
} else {
resolve()
}
}))
})
Promise.all(listPromise).then(_ => {
const promises = []
// 有5种产品,要传不同的authority调renew接口
list0.length && promises.push(new Promise((resolve, reject) => {
this.handleRenew(0, customerId, list0, result, resolve, reject)
}))
list1.length && promises.push(new Promise((resolve, reject) => {
this.handleRenew(1, customerId, list1, result, resolve, reject)
}))
list2.length && promises.push(new Promise((resolve, reject) => {
this.handleRenew(2, customerId, list2, result, resolve, reject)
}))
list3.length && promises.push(new Promise((resolve, reject) => {
this.handleRenew(3, customerId, list3, result, resolve, reject)
}))
list4.length && promises.push(new Promise((resolve, reject) => {
this.handleRenew(4, customerId, list4, result, resolve, reject)
}))
Promise.all(promises).then(_ => {
uni.setStorageSync('courses', result) // 把选中的产品添加至缓存
uni.redirectTo({
url: `../editCourse/editCourse?customerId=${customerId}&orderType=${this.orderType}`
})
})
3 years ago
})
} else {
this.$util.errMsg('请选择产品!')
}
}
}
}
</script>
<style scoped lang="scss">
.page {
padding-bottom: 130rpx;
3 years ago
}
.tab-wrap {
1 year ago
display: flex;
.tab-scroll {
width: calc(100% - 100rpx);
white-space: nowrap;
li {
display: inline-block;
}
}
}
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 {
2 years ago
position: fixed;
3 years ago
justify-content: space-between;
.btn {
width: 340rpx;
margin-left: 27rpx;
}
}
</style>