groupbuying.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. sou: '',
  37. // show_1: '',
  38. // xiazi: '',
  39. },
  40. onLoad(options) {
  41. // 获取tab数据
  42. this.getTabdata();
  43. // const title = options.title ? decodeURIComponent(options.title) : '商品列表';
  44. // this.setData({ title });
  45. // wx.setNavigationBarTitle({ title });
  46. const fileIDs = [
  47. 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png',
  48. // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show_1.png',
  49. // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/xiazi.png',
  50. ];
  51. // 并发下载多个 fileID
  52. Promise.all(
  53. fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
  54. ).then(results => {
  55. // 每个 result 对应一个下载结果
  56. const tempFilePaths = results.map(r => r.tempFilePath);
  57. console.log('全部下载成功:', tempFilePaths);
  58. this.setData({
  59. sou: tempFilePaths[0],
  60. // show_1: tempFilePaths[1],
  61. // xiazi: tempFilePaths[2],
  62. });
  63. }).catch(err => {
  64. console.error('有文件下载失败:', err);
  65. });
  66. },
  67. // tab数据
  68. async getTabdata() {
  69. const { data } = await models.tab.list({
  70. filter: {
  71. where: {
  72. position: 4, // 显示位置
  73. // layout_type: 0, // 布局类型
  74. },
  75. },
  76. // envType: pre 体验环境, prod 正式环境
  77. envType: "prod",
  78. });
  79. // 返回查询到的数据
  80. console.log(data);
  81. const sortedRecords = data.records.sort((a, b) => {
  82. return a.sort - b.sort; // 升序排列
  83. });
  84. this.setData({
  85. categories: sortedRecords
  86. })
  87. },
  88. tabcategories(e) {
  89. const type = e.currentTarget.dataset.type;
  90. this.setData({
  91. categoriesindex: type
  92. });
  93. },
  94. navigateToDetail(e) {
  95. const index = e.currentTarget.dataset.index;
  96. const item = this.data.goods[index];
  97. wx.navigateTo({
  98. url: '/subpackages/productdetails/productdetails?data=' + encodeURIComponent(JSON.stringify(item))
  99. });
  100. console.log('走进来了');
  101. }
  102. });