123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- Page({
- data: {
- cartItems: [
- {
- id: '1',
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- title: '幼儿启蒙绘本 10册套装',
- description: '适合3-6岁儿童,培养创造力',
- price: 134.00,
- quantity: 1,
- checked: true
- },
- {
- id: '2',
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- title: '幼儿启蒙绘本 10册套装',
- description: '适合3-6岁儿童,培养创造力',
- price: 134.00,
- quantity: 1,
- checked: true
- }
- ],
- souimg: '',
- },
- onLoad() {
- this.updateTotalPrice();
- const fileIDs = [
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.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({
- souimg: tempFilePaths[0],
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
- handleCheckboxChange(e) {
- const { value } = e.detail;
- const cartItems = this.data.cartItems.map(item => ({
- ...item,
- checked: value.includes(item.id)
- }));
- this.setData({ cartItems });
- this.updateTotalPrice();
- },
- handleAllCheckboxChange(e) {
- const { value } = e.detail;
- const allChecked = value.includes('all');
- const cartItems = this.data.cartItems.map(item => ({
- ...item,
- checked: allChecked
- }));
- this.setData({ cartItems, allChecked });
- this.updateTotalPrice();
- },
- updateTotalPrice() {
- const totalPrice = this.data.cartItems.reduce((total, item) => {
- if (item.checked) {
- return total + item.price * item.quantity;
- }
- return total;
- }, 0);
- this.setData({ totalPrice });
- },
- handleCheckout() {
- // 处理结算逻辑
- console.log('结算');
- wx.navigateTo({
- url: '/subpackages/submitorder/submitorder'
- });
- },
-
- onChange(e) {
- const { id } = e.currentTarget.dataset;
- const { detail } = e;
- const cartItems = this.data.cartItems.map(item => {
- if (item.id === id) {
- return { ...item, quantity: detail };
- }
- return item;
- });
-
- this.setData({ cartItems }, () => {
- this.updateTotalPrice();
- });
- }
- });
|