12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- Page({
- data: {
- item: {},
- selectedSpec: '基础款(50粒)',
- quantity: 1,
- showimg: '',
- gouwucimg: '',
- gaoliao: 0,
- },
- onLoad(options) {
- console.log('进了');
- const itemData = decodeURIComponent(options.data);
- const item = JSON.parse(itemData);
- this.setData({
- item: item
- });
- const fileIDs = [
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show.png',
- // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/gouwuc_img.png'
- ];
-
- // 并发下载多个 fileID
- Promise.all(
- fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
- ).then(results => {
- // 每个 result 对应一个下载结果
- const tempFilePaths = results.map(r => r.tempFilePath);
- console.log('全部下载成功:', tempFilePaths);
- this.setData({
- showimg: tempFilePaths[0],
- // gouwucimg: tempFilePaths[1]
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
- handleSpecSelect(e) {
- const spec = e.currentTarget.dataset.spec;
- this.setData({ selectedSpec: spec });
- },
-
- handleQuantityChange(e) {
- const action = e.currentTarget.dataset.action;
- let quantity = this.data.quantity;
- if (action === 'plus') {
- quantity++;
- } else if (action === 'minus' && quantity > 1) {
- quantity--;
- }
- this.setData({ quantity });
- },
-
- addToCart() {
- // 加入购物车逻辑
- console.log('加入购物车');
- },
-
- buyNow() {
- // 立即购买逻辑
- console.log('立即购买');
- }
- });
|