index.js 6.0 KB

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