groupbuying.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { models, db } from '../../utils/cloudbase.js'
  2. Page({
  3. data: {
  4. categoriesindex: 1,
  5. categories: [],
  6. goods: [
  7. {
  8. image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
  9. title: '儿童大颗粒积木 安全无毒 益智玩具',
  10. price: '68.00',
  11. originalPrice: '88.00',
  12. sold: 256
  13. },
  14. {
  15. image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
  16. title: '幼儿启蒙绘本 10册套装',
  17. price: '68.00',
  18. originalPrice: '88.00',
  19. sold: 256
  20. },
  21. {
  22. image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
  23. title: '防摔儿童保温水杯 350ml',
  24. price: '68.00',
  25. originalPrice: '88.00',
  26. sold: 256
  27. },
  28. {
  29. image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
  30. title: '可水洗儿童彩笔24色套装',
  31. price: '68.00',
  32. originalPrice: '88.00',
  33. sold: 256
  34. }
  35. ],
  36. souimg: '',
  37. gouwucimg: '',
  38. },
  39. onLoad(options) {
  40. // 获取tab数据
  41. this.getTabdata();
  42. // const title = options.title ? decodeURIComponent(options.title) : '商品列表';
  43. // this.setData({ title });
  44. // wx.setNavigationBarTitle({ title });
  45. const fileIDs = [
  46. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png',
  47. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/gouwuc_img.png'
  48. ];
  49. // 并发下载多个 fileID
  50. Promise.all(
  51. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  52. ).then(results => {
  53. // 每个 result 对应一个下载结果
  54. const tempFilePaths = results.map(r => r.tempFilePath);
  55. console.log('全部下载成功:', tempFilePaths);
  56. this.setData({
  57. souimg: tempFilePaths[0],
  58. gouwucimg: tempFilePaths[1]
  59. });
  60. }).catch(err => {
  61. console.error('有文件下载失败:', err);
  62. });
  63. },
  64. // tab数据
  65. async getTabdata() {
  66. const { data } = await models.tab.list({
  67. filter: {
  68. where: {
  69. position: 4, // 显示位置
  70. // layout_type: 0, // 布局类型
  71. },
  72. },
  73. // envType: pre 体验环境, prod 正式环境
  74. envType: "prod",
  75. });
  76. // 返回查询到的数据
  77. console.log(data);
  78. const sortedRecords = data.records.sort((a, b) => {
  79. return a.sort - b.sort; // 升序排列
  80. });
  81. this.setData({
  82. categories: sortedRecords
  83. })
  84. },
  85. tabcategories(e) {
  86. const type = e.currentTarget.dataset.type;
  87. this.setData({
  88. categoriesindex: type
  89. });
  90. },
  91. navigateToDetail(e) {
  92. const index = e.currentTarget.dataset.index;
  93. const item = this.data.goods[index];
  94. wx.navigateTo({
  95. url: '/subpackages/productdetails/productdetails?data=' + encodeURIComponent(JSON.stringify(item))
  96. });
  97. console.log('走进来了');
  98. }
  99. });