1+ // pages/cart/index.js
2+ Page ( {
3+
4+ /**
5+ * 页面的初始数据
6+ */
7+ data : {
8+ list : [ {
9+ name : 'pupu' ,
10+ logo : 'pupu.webp' ,
11+ title : '朴朴' ,
12+ desc : '朴朴一下,又快又好' ,
13+ appid : 'wx122ef876a7132eb4' ,
14+ tag : '生鲜电商'
15+ } , {
16+ name : 'dingdong' ,
17+ logo : 'dingdong.jpeg' ,
18+ title : '叮咚买菜' ,
19+ desc : '让美好的食材像自来水一样' ,
20+ appid : 'wx1e113254eda17715' ,
21+ tag : '生鲜电商'
22+ } , {
23+ name : 'qixian' ,
24+ logo : 'qixian.jpeg' ,
25+ title : '京东七鲜' ,
26+ desc : '好生活,七鲜' ,
27+ appid : 'wxb8c24a764d1e1e6d' ,
28+ tag : '生鲜电商'
29+ } , {
30+ name : 'baiguoyuan' ,
31+ logo : 'baiguoyuan.jpeg' ,
32+ title : '百果园+' ,
33+ desc : '🐼 熊猫大鲜,品质生鲜超市' ,
34+ appid : 'wx1f9ea355b47256dd' ,
35+ tag : '生鲜电商'
36+ } , {
37+ name : 'meituan' ,
38+ logo : 'meituan.jpeg' ,
39+ title : '美团' ,
40+ desc : '帮大家吃得更好,生活更好' ,
41+ appid : 'wxde8ac0a21135c07d' ,
42+ tag : '生鲜电商'
43+ } , {
44+ name : 'meiriyouxian' ,
45+ logo : 'meiriyouxian.jpeg' ,
46+ title : '每日优鲜' ,
47+ desc : '每日供应优质新鲜食材' ,
48+ appid : 'wxebf773691904eee9' ,
49+ tag : '生鲜电商'
50+ } , {
51+ name : 'qiandama' ,
52+ logo : 'qiandama.jpeg' ,
53+ title : '钱大妈' ,
54+ desc : '新鲜不隔夜,天亮即出发' ,
55+ appid : 'wx94679e209a2b069d' ,
56+ tag : '生鲜电商'
57+ } , {
58+ name : 'tianhong' ,
59+ logo : 'tianhong.jpeg' ,
60+ title : '天虹' ,
61+ desc : '综合超市' ,
62+ appid : 'wx83b25ac313aea733' ,
63+ tag : '综合商超'
64+ } , {
65+ name : 'baijiahua' ,
66+ logo : 'baijiahua.jpeg' ,
67+ title : '百佳华' ,
68+ desc : '精选50多个国家和地区优质商品' ,
69+ appid : 'wx3cdd1f26cc0c7b25' ,
70+ tag : '综合商超'
71+ } , {
72+ name : 'jialefu' ,
73+ logo : 'jialefu.jpeg' ,
74+ title : '家乐福' ,
75+ desc : '苏宁易购旗下综合超市' ,
76+ appid : 'wxbff87cc25bc11305' ,
77+ tag : '综合商超'
78+ } , {
79+ name : 'yonghui' ,
80+ logo : 'yonghui.jpeg' ,
81+ title : '永辉生活' ,
82+ desc : '新鲜蔬果肉禽,食品百货,应用尽有' ,
83+ appid : 'wxc9cf7c95499ee604' ,
84+ tag : '综合商超'
85+ } , {
86+ name : 'woerma' ,
87+ logo : 'woerma.jpeg' ,
88+ title : '沃尔玛' ,
89+ desc : '一家美国的世界性连锁企业' ,
90+ appid : 'wx83231ee9993066b7' ,
91+ tag : '综合商超'
92+ } , {
93+ name : 'yongwang' ,
94+ logo : 'yongwang.jpeg' ,
95+ title : '永旺' ,
96+ desc : '日本著名零售集团公司' ,
97+ appid : 'wx55996449c48dd8c7' ,
98+ tag : '综合商超'
99+ } , {
100+ name : 'shanmu' ,
101+ logo : 'shanmu.jpeg' ,
102+ title : '山姆' ,
103+ desc : '美国沃尔玛旗下高端会员制商店' ,
104+ appid : 'wxb344a8513eaaf849' ,
105+ tag : '综合商超'
106+ } , {
107+ name : 'jingxi' ,
108+ logo : 'jingxi.jpeg' ,
109+ title : '京喜拼拼' ,
110+ desc : '京东旗下生活消费商城' ,
111+ appid : 'wxf95d0d80e9d5bfc0' ,
112+ tag : '社区电商'
113+ } , {
114+ name : 'xingsheng' ,
115+ logo : 'xingsheng.jpeg' ,
116+ title : '兴盛优选' ,
117+ desc : '一家有温度的社区电商' ,
118+ appid : 'wx6025c5470c3cb50c' ,
119+ tag : '社区电商'
120+ } , {
121+ name : 'tudigong' ,
122+ logo : 'tudigong.jpeg' ,
123+ title : '土地公' ,
124+ desc : '花更少的钱 享美好生活' ,
125+ appid : 'wx264657535896c762' ,
126+ tag : '社区电商'
127+ } ] ,
128+ value : 'cart' ,
129+ tabbars : [ {
130+ text : '首页' ,
131+ value : 'index' ,
132+ icon : 'home'
133+ } , {
134+ text : '买菜' ,
135+ value : 'cart' ,
136+ icon : 'cart'
137+ } , {
138+ text : '技巧' ,
139+ value : 'learn' ,
140+ icon : 'tips'
141+ } , {
142+ text : '个人中心' ,
143+ value : 'my' ,
144+ icon : 'user'
145+ } ]
146+ } ,
147+
148+ onShow : function ( options ) {
149+ const arr = wx . getStorageSync ( 'miniprogram_clicked' ) || [ ]
150+ const { list } = this . data ;
151+
152+ if ( arr . length > 0 ) {
153+ arr . forEach ( appid => {
154+ const target = list . find ( item => item . appid == appid )
155+ if ( target ) {
156+ target . clicked = true
157+ }
158+ } )
159+ list . sort ( item => item . clicked ? - 1 : 1 )
160+ }
161+
162+ this . setData ( { list } )
163+ } ,
164+
165+ handleRedirect ( { currentTarget } ) {
166+ const { appid } = currentTarget . dataset ;
167+
168+ wx . navigateToMiniProgram ( {
169+ appId : appid
170+ } ) . then ( ( ) => {
171+ this . updateViews ( appid )
172+ this . storageAction ( appid )
173+ } ) . catch ( err => {
174+ console . log ( err ) ;
175+ } )
176+ } ,
177+
178+ storageAction ( appid ) {
179+ const arr = wx . getStorageSync ( 'miniprogram_clicked' ) || [ ]
180+
181+ if ( arr . indexOf ( appid ) > - 1 ) return ;
182+
183+ arr . push ( appid )
184+ wx . setStorageSync ( 'miniprogram_clicked' , arr )
185+ } ,
186+
187+ handleTabbarChange ( { detail } ) {
188+ const { value } = detail ;
189+
190+ wx . redirectTo ( {
191+ url : `../${ value } /index`
192+ } )
193+ } ,
194+
195+ updateViews ( appid ) {
196+ wx . cloud . callFunction ( {
197+ name : 'updateViews' ,
198+ data : {
199+ id : appid ,
200+ type : 'miniprogram'
201+ } ,
202+ } )
203+ } ,
204+
205+ onShareAppMessage ( ) {
206+ return {
207+ title : '所有的买菜 APP 尽在这里' ,
208+ path : '/pages/cart/index'
209+ }
210+ } ,
211+ } )
0 commit comments