index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. var app = getApp();
  2. Component({
  3. properties: {
  4. currentIdx: {
  5. type: Number,
  6. value: 0,
  7. observer: function (t) {
  8. if (t) {
  9. let tabbar = this.data.tabbar;
  10. for (let i in tabbar.list) {
  11. tabbar.list[i].selected = false;
  12. (i == t) && (tabbar.list[i].selected = true);
  13. }
  14. this.setData({ tabbar })
  15. }
  16. }
  17. },
  18. cartNum: {
  19. type: Number,
  20. value: 0
  21. },
  22. tabbarRefresh: {
  23. type: Boolean,
  24. value: false,
  25. observer: function (t) {
  26. if (t) this.getTabbar();
  27. }
  28. },
  29. needAuth: {
  30. type: Boolean,
  31. value: false
  32. }
  33. },
  34. attached() {
  35. let model = wx.getSystemInfoSync().model;
  36. let isIpx = model.indexOf("iPhone X") > -1 || model.indexOf("unknown<iPhone") > -1;
  37. isIpx && this.setData({ isIpx: true });
  38. this.getTabbar();
  39. },
  40. /**
  41. * 组件的初始数据
  42. */
  43. data: {
  44. isIpx: false,
  45. tabbar: {
  46. "backgroundColor": "#fff",
  47. "color": "#707070",
  48. "selectedColor": "#ff5344",
  49. "list": [
  50. {
  51. "pagePath": "/lionfish_comshop/pages/index/index",
  52. "text": "",
  53. "iconPath": "",
  54. "selectedIconPath": "",
  55. "selected": true
  56. },
  57. {
  58. "pagePath": "/lionfish_comshop/pages/type/index",
  59. "text": "",
  60. "iconPath": "",
  61. "selectedIconPath": "",
  62. "selected": false
  63. },
  64. {
  65. "pagePath": "",
  66. "text": "",
  67. "iconPath": "",
  68. "selectedIconPath": "",
  69. "selected": false
  70. },
  71. {
  72. "pagePath": "/lionfish_comshop/pages/order/shopCart",
  73. "text": "",
  74. "iconPath": "",
  75. "selectedIconPath": "",
  76. "selected": false
  77. },
  78. {
  79. "pagePath": "/lionfish_comshop/pages/user/me",
  80. "text": "",
  81. "iconPath": "",
  82. "selectedIconPath": "",
  83. "selected": false
  84. }
  85. ]
  86. },
  87. open_tabbar_type: 0,
  88. open_tabbar_out_weapp: 0,
  89. cartNum: 0,
  90. tabbar_out_appid: '',
  91. tabbar_out_link: '',
  92. tabbar_out_type: 0
  93. },
  94. /**
  95. * 组件的方法列表
  96. */
  97. methods: {
  98. getTabbar: function () {
  99. let that = this;
  100. app.util.request({
  101. 'url': 'entry/wxapp/index',
  102. 'data': {
  103. controller: 'index.get_tabbar'
  104. },
  105. dataType: 'json',
  106. success: function (res) {
  107. if (res.data.code == 0) {
  108. let list = res.data.data;
  109. let tabbar = that.data.tabbar;
  110. tabbar.list[0].text = list['t1'] || '首页';
  111. tabbar.list[0].iconPath = list['i1'] || '/lionfish_comshop/images/icon-tab-index.png';
  112. tabbar.list[0].selectedIconPath = list['s1'] || '/lionfish_comshop/images/icon-tab-index-active.png';
  113. tabbar.list[1].text = list['t4'] || '分类';
  114. tabbar.list[1].iconPath = list['i4'] || '/lionfish_comshop/images/icon-tab-type.png';
  115. tabbar.list[1].selectedIconPath = list['s4'] || '/lionfish_comshop/images/icon-tab-type-active.png';
  116. tabbar.list[2].text = list['t5'];
  117. tabbar.list[2].iconPath = list['i5'];
  118. tabbar.list[2].selectedIconPath = list['s5'];
  119. tabbar.list[3].text = list['t2'] || '购物车';
  120. tabbar.list[3].iconPath = list['i2'] || '/lionfish_comshop/images/icon-tab-shop.png';
  121. tabbar.list[3].selectedIconPath = list['s2'] || '/lionfish_comshop/images/icon-tab-shop-active.png';
  122. tabbar.list[4].text = list['t3'] || '我的';
  123. tabbar.list[4].iconPath = list['i3'] || '/lionfish_comshop/images/icon-tab-me.png';
  124. tabbar.list[4].selectedIconPath = list['s3'] || '/lionfish_comshop/images/icon-tab-me-active.png';
  125. let open_tabbar_type = res.data.open_tabbar_type || 0;
  126. let open_tabbar_out_weapp = res.data.open_tabbar_out_weapp || 0;
  127. let tabbar_out_appid = res.data.tabbar_out_appid;
  128. let tabbar_out_link = res.data.tabbar_out_link;
  129. let tabbar_out_type = res.data.tabbar_out_type;
  130. tabbar.selectedColor = res.data.wepro_tabbar_selectedColor || '#F75451';
  131. tabbar.backgroundColor = res.data.wepro_tabbar_bgColor || '#ffffff';
  132. // wcache.put('open_tabbar_type', open_tabbar_type, 600);
  133. // wcache.put('tabList', tabbar, 600);
  134. that.setData({ tabbar, open_tabbar_type, open_tabbar_out_weapp, tabbar_out_appid, tabbar_out_link, tabbar_out_type });
  135. } else {
  136. that.setData({ hideTabbar: true })
  137. }
  138. }
  139. })
  140. },
  141. goWeapp: function(){
  142. // 跳转小程序
  143. let appid = this.data.tabbar_out_appid;
  144. let url = this.data.tabbar_out_link;
  145. let type = this.data.tabbar_out_type;
  146. if (type == 0) {
  147. // 跳转webview
  148. wx.navigateTo({
  149. url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url),
  150. })
  151. } else if (type == 1) {
  152. let tabUrls = ['/lionfish_comshop/pages/index/index', '/lionfish_comshop/pages/order/shopCart', '/lionfish_comshop/pages/user/me', '/lionfish_comshop/pages/type/index'];
  153. let redUrls = ['/lionfish_comshop/moduleA/solitaire/index', '/lionfish_comshop/moduleA/video/index', '/lionfish_comshop/moduleA/menu/index', '/lionfish_comshop/moduleA/pin/index', '/lionfish_comshop/moduleA/seckill/list'];
  154. if (tabUrls.indexOf(url) != -1) {
  155. wx.switchTab({ url })
  156. } else if (redUrls.indexOf(url) != -1) {
  157. if(url == '/lionfish_comshop/moduleA/solitaire/index'&&this.data.needAuth) {
  158. this.triggerEvent('authModal', true);
  159. } else {
  160. wx.redirectTo({ url });
  161. }
  162. } else {
  163. wx.navigateTo({ url })
  164. }
  165. } else if (type == 2) {
  166. appid && wx.navigateToMiniProgram({
  167. appId: appid,
  168. path: url,
  169. extraData: {},
  170. envVersion: 'release',
  171. success(res) {
  172. // 打开成功
  173. console.log(res)
  174. }
  175. })
  176. } else if (type == 3) {
  177. let url = '/lionfish_comshop/moduleA/pin/index';
  178. wx.redirectTo({ url })
  179. } else if (type == 4) {
  180. let url = '/lionfish_comshop/moduleA/menu/index';
  181. wx.redirectTo({ url })
  182. } else if (type == 5) {
  183. let url = '/lionfish_comshop/moduleA/video/index';
  184. wx.redirectTo({ url })
  185. } else if (type == 6) {
  186. if(this.data.needAuth) {
  187. this.triggerEvent('authModal', true)
  188. } else {
  189. let url = '/lionfish_comshop/moduleA/solitaire/index';
  190. wx.redirectTo({ url })
  191. }
  192. } else if (type == 7) {
  193. let url = '/lionfish_comshop/moduleB/live/index';
  194. wx.redirectTo({ url })
  195. } else if(type == 8) {
  196. let url = '/lionfish_comshop/moduleB/generalmall/index';
  197. wx.redirectTo({ url })
  198. } else if(type == 9) {
  199. let url = '/lionfish_comshop/moduleB/presale/index';
  200. wx.redirectTo({ url })
  201. }
  202. }
  203. }
  204. })