|
@@ -1,8 +1,6 @@
|
|
|
// index.ts
|
|
|
-
|
|
|
-import { api_shopInstruments, api_shopProduct } from "../../api/login";
|
|
|
import { api_schoolAreaDetail, api_schoolAreaList, api_sysAreaQueryAllProvince, api_userBeneficiarySave, api_userBeneficiaryUpdate } from "../../api/new";
|
|
|
-import { debounce, formatPrice, GRADE_ENUM } from '../../utils/util'
|
|
|
+import { GRADE_ENUM } from '../../utils/util'
|
|
|
|
|
|
const classList: any = [];
|
|
|
for (let i = 1; i <= 40; i++) {
|
|
@@ -49,27 +47,17 @@ Page({
|
|
|
*/
|
|
|
data: {
|
|
|
goodsImgList: [
|
|
|
- 'https://oss.dayaedu.com/ktyq/1739523537634.png',
|
|
|
+ 'https://oss.dayaedu.com/ktyq/1739524049205.png',
|
|
|
'https://oss.dayaedu.com/ktyq/1739523564827.png',
|
|
|
'https://oss.dayaedu.com/ktyq/1739523574402.png',
|
|
|
'https://oss.dayaedu.com/ktyq/1739523583463.png'
|
|
|
],
|
|
|
current: 0,
|
|
|
popupShow: false,
|
|
|
- instrumentList: [] as any,
|
|
|
- list: [] as any,
|
|
|
- isOverSaled: false, // 是否所有商品都没有库存
|
|
|
- smallGoods: {}, // 最小金额商品
|
|
|
- selected: {} as any,
|
|
|
- selectInstrumentId: '', // 选中的乐器
|
|
|
- selectedInstrument: {} as any,
|
|
|
- formatSelectGood: {
|
|
|
- typeName: '',
|
|
|
- showSalePrice: '', // 显示的现价
|
|
|
- originalPrice: 0, // 原价
|
|
|
- salePrice: 0, // 现价
|
|
|
- discountPrice: '' // 已省
|
|
|
- } as any, // 格式化所有选中的数据
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
showService: false,
|
|
|
isFromPreviewImage: false,
|
|
|
showBuyer: false, // 收益人
|
|
@@ -142,173 +130,7 @@ Page({
|
|
|
onLoad() {
|
|
|
// this.onInit()
|
|
|
},
|
|
|
- /**
|
|
|
- * 获取基础信息
|
|
|
- */
|
|
|
- async onInit() {
|
|
|
- try {
|
|
|
- const result = await api_shopInstruments({ appId: app.globalData.appId })
|
|
|
- const instrumentList = result.data.data || []
|
|
|
- instrumentList?.forEach((item: any) => {
|
|
|
- item.showSalePrice = formatPrice(item.salePrice || 0, 'ALL')
|
|
|
- })
|
|
|
- const { data } = await api_shopProduct({ appId: app.globalData.appId });
|
|
|
- const list = data.data || []
|
|
|
- let selected: any = {}
|
|
|
- let isOverSaled = true // 是否销售完
|
|
|
-
|
|
|
- // 最少金额商品
|
|
|
- let smallGoods: any = {}
|
|
|
- list.forEach((item: any) => {
|
|
|
- item.originalPrice = formatPrice(item.originalPrice, "ALL");
|
|
|
- item.showSalePrice = formatPrice(item.salePrice, "ALL");
|
|
|
- item.typeName = this.formatPeriod(item.num, item.period);
|
|
|
- item.discountPrice = formatPrice(
|
|
|
- item.originalPrice - item.salePrice,
|
|
|
- "ALL"
|
|
|
- );
|
|
|
- const prices: any = formatPrice(item.salePrice)
|
|
|
- item.integerPart = prices.integerPart
|
|
|
- item.decimalPart = prices.decimalPart
|
|
|
- if (item.stockNum > 0) {
|
|
|
- isOverSaled = false
|
|
|
- if (!selected.id) {
|
|
|
- selected = item
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取最小金额
|
|
|
- if (smallGoods?.salePrice) {
|
|
|
- smallGoods = smallGoods.salePrice <= item.salePrice ? smallGoods : item
|
|
|
- } else {
|
|
|
- smallGoods = item
|
|
|
- }
|
|
|
- });
|
|
|
- if (isOverSaled) {
|
|
|
- // 没有可购买商品则默认选中第一个商品
|
|
|
- selected = list[0]
|
|
|
- }
|
|
|
-
|
|
|
- this.setData({
|
|
|
- list,
|
|
|
- instrumentList, // 乐器列表
|
|
|
- isOverSaled,
|
|
|
- selected,
|
|
|
- smallGoods,
|
|
|
- selectInstrumentId: '',
|
|
|
- selectedInstrument: {},
|
|
|
-
|
|
|
- userBeneficiaryId: '',
|
|
|
- userBeneficiaryInfo: {
|
|
|
- name: '',
|
|
|
- phoneNumber: '',
|
|
|
- schoolInfo: ''
|
|
|
- }
|
|
|
- }, () => {
|
|
|
- this.onFormatGoods()
|
|
|
- })
|
|
|
- } catch (e) {
|
|
|
- console.log(e, 'e')
|
|
|
- }
|
|
|
- },
|
|
|
- // 格式化类型
|
|
|
- formatPeriod(num: number, type: string) {
|
|
|
- const template: any = {
|
|
|
- DAY: "天卡",
|
|
|
- MONTH: "月卡",
|
|
|
- YEAR: "年卡"
|
|
|
- }
|
|
|
- if (type === "YEAR" && num >= 99) {
|
|
|
- return '永久卡'
|
|
|
- }
|
|
|
- return num + (template[type] || '')
|
|
|
- },
|
|
|
- /** 切换swiper */
|
|
|
- onSwiperChange(e: any) {
|
|
|
- console.log(e, 'e')
|
|
|
- return false
|
|
|
- },
|
|
|
- // 选择
|
|
|
- onSelectGoods(e: any) {
|
|
|
- const { dataset } = e.currentTarget
|
|
|
- const item = this.data.list.find((item: any) => item.id === dataset.id)
|
|
|
- // 判断是否有库存
|
|
|
- if (item.stockNum <= 0) {
|
|
|
- return
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- selected: item || {}
|
|
|
- }, () => {
|
|
|
- this.onFormatGoods()
|
|
|
- })
|
|
|
- },
|
|
|
- /** 选中乐器 */
|
|
|
- onSelectInstrument(e: any) {
|
|
|
- const { dataset } = e.currentTarget;
|
|
|
- if (dataset.id === this.data.selectInstrumentId) {
|
|
|
- this.setData({
|
|
|
- selectInstrumentId: '',
|
|
|
- selectedInstrument: {}
|
|
|
- }, () => {
|
|
|
- this.onFormatGoods()
|
|
|
- })
|
|
|
- } else {
|
|
|
- const item = this.data.instrumentList.find((item: any) => item.id === dataset.id);
|
|
|
- this.setData({
|
|
|
- selectInstrumentId: dataset.id,
|
|
|
- selectedInstrument: item || {}
|
|
|
- }, () => {
|
|
|
- this.onFormatGoods()
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- /** 格式化选中的商品 */
|
|
|
- onFormatGoods() {
|
|
|
- const selected = this.data.selected;
|
|
|
- const selectedInstrument = this.data.selectedInstrument
|
|
|
-
|
|
|
- const params = {
|
|
|
- typeName: '',
|
|
|
- showSalePrice: '' as any, // 显示的现价
|
|
|
- originalPrice: 0, // 原价
|
|
|
- salePrice: 0, // 现价
|
|
|
- discountPrice: '' as any, // 已省
|
|
|
- integerPart: '',
|
|
|
- decimalPart: '',
|
|
|
- }
|
|
|
- // 选中期限
|
|
|
- if (selected.id) {
|
|
|
- params.typeName = selected.typeName
|
|
|
- params.showSalePrice = selected.showSalePrice
|
|
|
- params.originalPrice = selected.originalPrice
|
|
|
- params.salePrice = selected.salePrice
|
|
|
- params.discountPrice = selected.discountPrice
|
|
|
-
|
|
|
- const prices: any = formatPrice(params.salePrice);
|
|
|
- params.integerPart = prices.integerPart
|
|
|
- params.decimalPart = prices.decimalPart
|
|
|
- }
|
|
|
- // 选中乐器
|
|
|
- if (selectedInstrument.id) {
|
|
|
- params.typeName = selected.typeName ? selected.typeName + '+' + selectedInstrument.name : selectedInstrument.name
|
|
|
- params.originalPrice = Number(selected.originalPrice) + Number(selectedInstrument.originalPrice)
|
|
|
- params.salePrice = Number(selected.salePrice) + Number(selectedInstrument.salePrice)
|
|
|
- params.showSalePrice = formatPrice(params.salePrice, "ALL");
|
|
|
- params.discountPrice = formatPrice(
|
|
|
- params.originalPrice - params.salePrice,
|
|
|
- "ALL"
|
|
|
- );
|
|
|
-
|
|
|
- const prices: any = formatPrice(params.salePrice);
|
|
|
- params.integerPart = prices.integerPart
|
|
|
- params.decimalPart = prices.decimalPart
|
|
|
- }
|
|
|
-
|
|
|
- this.setData({
|
|
|
- formatSelectGood: params
|
|
|
- })
|
|
|
- },
|
|
|
+
|
|
|
isLogin() {
|
|
|
// 判断是否登录
|
|
|
if (!app.globalData.isLogin) {
|
|
@@ -329,6 +151,16 @@ Page({
|
|
|
url: '../orders/orders',
|
|
|
})
|
|
|
},
|
|
|
+ /** 申请加入 */
|
|
|
+ onBuyGoods() {
|
|
|
+ // 判断是否登录
|
|
|
+ if (!this.isLogin()) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '../select-goods/index',
|
|
|
+ })
|
|
|
+ },
|
|
|
/** 客服 */
|
|
|
onService() {
|
|
|
this.setData({
|
|
@@ -361,67 +193,7 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- onSubmit() {
|
|
|
- // 判断是否登录
|
|
|
- const that = this
|
|
|
- if (!this.data.userBeneficiaryId) {
|
|
|
- wx.showToast({
|
|
|
- title: '请填写享用者的个人信息',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- debounce(function () {
|
|
|
- if (!that.isLogin()) {
|
|
|
- return
|
|
|
- }
|
|
|
- const params = [] as any
|
|
|
- const selected = that.data.selected
|
|
|
- if (selected.id) {
|
|
|
- params.push({
|
|
|
- pic: selected.pic,
|
|
|
- name: selected.name,
|
|
|
- period: selected.period,
|
|
|
- num: selected.num,
|
|
|
- originalPrice: selected.originalPrice,
|
|
|
- salePrice: selected.salePrice,
|
|
|
- shopId: selected.shopId,
|
|
|
- id: selected.id,
|
|
|
- goodsType: 'ACTIVATION_CODE', // INSTRUMENTS
|
|
|
- })
|
|
|
- }
|
|
|
- const selectedInstrument = that.data.selectedInstrument
|
|
|
- if (selectedInstrument.id) {
|
|
|
- params.push({
|
|
|
- pic: selectedInstrument.pic,
|
|
|
- name: selectedInstrument.name,
|
|
|
- period: selectedInstrument?.period,
|
|
|
- num: selectedInstrument?.num || 0,
|
|
|
- originalPrice: selectedInstrument.originalPrice,
|
|
|
- salePrice: selectedInstrument.salePrice,
|
|
|
- shopId: selectedInstrument.shopId,
|
|
|
- id: selectedInstrument.id,
|
|
|
- goodsType: 'INSTRUMENTS', // INSTRUMENTS
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- let info = JSON.stringify({
|
|
|
- ...params
|
|
|
- });
|
|
|
- info = encodeURIComponent(info);
|
|
|
-
|
|
|
- console.log(params, "params")
|
|
|
- wx.navigateTo({
|
|
|
- url: `../orders/order-detail?orderInfo=${info}&userBeneficiaryId=${that.data.userBeneficiaryId}`,
|
|
|
- success: () => {
|
|
|
- that.setData({
|
|
|
- popupShow: false,
|
|
|
- currentIndex: 1,
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }, 500)()
|
|
|
- },
|
|
|
+
|
|
|
onPreivewGoodsImg(e: { currentTarget: { dataset: any } }) {
|
|
|
wx.previewImage({
|
|
|
current: e.currentTarget.dataset.src,
|
|
@@ -448,17 +220,10 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
- if (!this.data.isFromPreviewImage) {
|
|
|
- this.onInit()
|
|
|
- } else {
|
|
|
- this.setData({
|
|
|
- isFromPreviewImage: false
|
|
|
- })
|
|
|
- }
|
|
|
},
|
|
|
onShareAppMessage() {
|
|
|
return {
|
|
|
- title: '器乐数字AI工具',
|
|
|
+ title: '翼时代器乐数字Ai',
|
|
|
path: '/pages/index/index',
|
|
|
imageUrl: 'https://oss.dayaedu.com/ktyq/1733312164991.png'
|
|
|
}
|