|
@@ -1,6 +1,6 @@
|
|
// index.ts
|
|
// index.ts
|
|
|
|
|
|
-import { api_shopProduct } from "../../api/login";
|
|
|
|
|
|
+import { api_shopInstruments, api_shopProduct } from "../../api/login";
|
|
import { debounce, formatPrice } from '../../utils/util'
|
|
import { debounce, formatPrice } from '../../utils/util'
|
|
|
|
|
|
// 获取应用实例
|
|
// 获取应用实例
|
|
@@ -34,23 +34,28 @@ Page({
|
|
'https://oss.dayaedu.com/ktyq/1739182557976.png',
|
|
'https://oss.dayaedu.com/ktyq/1739182557976.png',
|
|
'https://oss.dayaedu.com/ktyq/1739182545221.png'
|
|
'https://oss.dayaedu.com/ktyq/1739182545221.png'
|
|
],
|
|
],
|
|
- formatSelectGood: {
|
|
|
|
- typeName: '',
|
|
|
|
- showSalePrice: '', // 显示的现价
|
|
|
|
- originalPrice: 0, // 原价
|
|
|
|
- salePrice: 0, // 现价
|
|
|
|
- discountPrice: '' // 已省
|
|
|
|
- } as any, // 格式化所有选中的数据
|
|
|
|
current: 0,
|
|
current: 0,
|
|
autoplay: false,
|
|
autoplay: false,
|
|
interval: 5000,
|
|
interval: 5000,
|
|
duration: 500,
|
|
duration: 500,
|
|
popupShow: false,
|
|
popupShow: false,
|
|
|
|
+ instrumentList: [] as any,
|
|
list: [] as any,
|
|
list: [] as any,
|
|
isOverSaled: false, // 是否所有商品都没有库存
|
|
isOverSaled: false, // 是否所有商品都没有库存
|
|
|
|
+ smallGoods: {}, // 最小金额商品
|
|
selected: {} as any,
|
|
selected: {} as any,
|
|
|
|
+ selectInstrumentId: '', // 选中的乐器
|
|
|
|
+ selectedInstrument: {} as any,
|
|
|
|
+ formatSelectGood: {
|
|
|
|
+ typeName: '',
|
|
|
|
+ showSalePrice: '', // 显示的现价
|
|
|
|
+ originalPrice: 0, // 原价
|
|
|
|
+ salePrice: 0, // 现价
|
|
|
|
+ discountPrice: '' // 已省
|
|
|
|
+ } as any, // 格式化所有选中的数据
|
|
showService: false,
|
|
showService: false,
|
|
- isFromPreviewImage: false
|
|
|
|
|
|
+ isFromPreviewImage: false,
|
|
|
|
+ showBuyer: true, // 收益人
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -64,13 +69,26 @@ Page({
|
|
*/
|
|
*/
|
|
async onInit() {
|
|
async onInit() {
|
|
try {
|
|
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 { data } = await api_shopProduct({ appId: app.globalData.appId });
|
|
const list = data.data || []
|
|
const list = data.data || []
|
|
let selected: any = {}
|
|
let selected: any = {}
|
|
let isOverSaled = true // 是否销售完
|
|
let isOverSaled = true // 是否销售完
|
|
|
|
+
|
|
|
|
+ // 最少金额商品
|
|
|
|
+ let smallGoods: any = {}
|
|
list.forEach((item: any) => {
|
|
list.forEach((item: any) => {
|
|
- item.originalPrice = formatPrice(item.originalPrice, 'ALL');
|
|
|
|
|
|
+ item.originalPrice = formatPrice(item.originalPrice, "ALL");
|
|
|
|
+ item.showSalePrice = formatPrice(item.salePrice, "ALL");
|
|
item.typeName = this.formatPeriod(item.num, item.period);
|
|
item.typeName = this.formatPeriod(item.num, item.period);
|
|
|
|
+ item.discountPrice = formatPrice(
|
|
|
|
+ item.originalPrice - item.salePrice,
|
|
|
|
+ "ALL"
|
|
|
|
+ );
|
|
const prices: any = formatPrice(item.salePrice)
|
|
const prices: any = formatPrice(item.salePrice)
|
|
item.integerPart = prices.integerPart
|
|
item.integerPart = prices.integerPart
|
|
item.decimalPart = prices.decimalPart
|
|
item.decimalPart = prices.decimalPart
|
|
@@ -80,16 +98,30 @@ Page({
|
|
selected = item
|
|
selected = item
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 获取最小金额
|
|
|
|
+ if(smallGoods?.salePrice) {
|
|
|
|
+ smallGoods = smallGoods.salePrice <= item.salePrice ? smallGoods : item
|
|
|
|
+ } else {
|
|
|
|
+ smallGoods = item
|
|
|
|
+ }
|
|
});
|
|
});
|
|
if (isOverSaled) {
|
|
if (isOverSaled) {
|
|
// 没有可购买商品则默认选中第一个商品
|
|
// 没有可购买商品则默认选中第一个商品
|
|
selected = list[0]
|
|
selected = list[0]
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ console.log(smallGoods, 'smallGoods')
|
|
this.setData({
|
|
this.setData({
|
|
list,
|
|
list,
|
|
|
|
+ instrumentList, // 乐器列表
|
|
isOverSaled,
|
|
isOverSaled,
|
|
- selected
|
|
|
|
|
|
+ selected,
|
|
|
|
+ smallGoods,
|
|
|
|
+ selectInstrumentId: '',
|
|
|
|
+ selectedInstrument: {}
|
|
|
|
+ }, () => {
|
|
|
|
+ this.onFormatGoods()
|
|
})
|
|
})
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log(e, 'e')
|
|
console.log(e, 'e')
|
|
@@ -117,8 +149,31 @@ Page({
|
|
}
|
|
}
|
|
this.setData({
|
|
this.setData({
|
|
selected: item || {}
|
|
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()
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
onFirstChange(e: any) {
|
|
onFirstChange(e: any) {
|
|
const detail = e.detail;
|
|
const detail = e.detail;
|
|
if (detail.source === 'touch' || detail.source == 'autoplay') {
|
|
if (detail.source === 'touch' || detail.source == 'autoplay') {
|
|
@@ -178,6 +233,7 @@ Page({
|
|
params.decimalPart = prices.decimalPart
|
|
params.decimalPart = prices.decimalPart
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ console.log(params, "params")
|
|
this.setData({
|
|
this.setData({
|
|
formatSelectGood: params
|
|
formatSelectGood: params
|
|
})
|
|
})
|
|
@@ -249,6 +305,16 @@ Page({
|
|
})
|
|
})
|
|
}, 500)()
|
|
}, 500)()
|
|
},
|
|
},
|
|
|
|
+ onSelectBuyer() {
|
|
|
|
+ this.setData({
|
|
|
|
+ showBuyer: true
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ onCloseBuyer(e: {detail: any}) {
|
|
|
|
+ this.setData({
|
|
|
|
+ showBuyer: e.detail
|
|
|
|
+ })
|
|
|
|
+ },
|
|
onPreivewBannerImg(e: { currentTarget: { dataset: any } }) {
|
|
onPreivewBannerImg(e: { currentTarget: { dataset: any } }) {
|
|
wx.previewImage({
|
|
wx.previewImage({
|
|
current: e.currentTarget.dataset.src,
|
|
current: e.currentTarget.dataset.src,
|