123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import { models, db, _ } from '../../utils/cloudbase.js'
- Page({
- data: {
- item: {},
- quantity: 1,
- showimg: '',
- gouwucimg: '',
- gaoliao: 0,
- fenxiangljimg: '',
- shareType: '' // 用于区分是老师还是家长
- },
- onLoad(options) {
- const from = options.from || '';
- console.log('进了');
- const itemData = decodeURIComponent(options.data);
- const item = JSON.parse(itemData);
- console.log(item, 'itemitemitemitemitemitemitem');
- this.setData({
- item: item,
- from
- }, () => {
- this.getbrowse()
- });
- const fileIDs = [
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show.png',
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/fenxianglj.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],
- fenxiangljimg: tempFilePaths[1]
- // gouwucimg: tempFilePaths[1]
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
- // 新增浏览量
- async getbrowse() {
- const { data } = await models.wx_merchandise.update({
- data: {
- browse: this.data.item.browse + 1, // 浏览数
- },
- filter: {
- where: {
- $and: [
- {
- _id: {
- $eq: this.data.item._id, // 推荐传入_id数据标识进行操作
- },
- },
- ]
- }
- },
- // envType: pre 体验环境, prod 正式环境
- envType: "prod",
- });
-
- // 返回更新成功的条数
- console.log(data, 'datadata');
- this.setData({
- 'item.browse': this.data.item.browse + 1
- })
- },
- previewImage(e) {
- const index = e.currentTarget.dataset.index;
- const images = this.data.item.detail_images;
- wx.previewImage({
- current: images[index], // 当前预览的图片
- urls: images // 所有可预览的图片列表
- });
- },
- // 点击分享图标
- onShareTap() {
- wx.showActionSheet({
- itemList: ['分享给老师', '分享给家长'],
- success: (res) => {
- const shareType = res.tapIndex === 0 ? 'teacher' : 'parent';
- this.setData({ shareType });
- wx.showModal({
- title: '提示',
- content: '请点击右上角“···”按钮,选择“发送给朋友”进行分享',
- showCancel: false
- });
- },
- fail: (err) => {
- console.log('取消选择', err);
- }
- });
- },
- // 配置微信分享信息
- onShareAppMessage() {
- const { item, shareType } = this.data;
- let title = '';
- let path = '';
- if (shareType === 'teacher') {
- title = '老师推荐的优质商品,快来看!';
- path = `/subpackages/productdetails/productdetails?data=${encodeURIComponent(JSON.stringify(item))}&from=teacher`;
- } else {
- title = '家长推荐的宝藏商品,别错过!';
- path = `/subpackages/productdetails/productdetails?data=${encodeURIComponent(JSON.stringify(item))}&from=parent`;
- }
- return {
- title,
- path,
- imageUrl: item.detail_images?.[0] || ''
- };
- },
- // 点击切换规格
- selectSpec(e) {
- const specIndex = e.currentTarget.dataset.specindex;
- this.setData({
- gaoliao: specIndex
- })
- }
- // 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('立即购买');
- // }
- });
|