index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. Page({
  2. data: {
  3. shopList: [{
  4. id: 1,
  5. imgurl: "../../images/shop.jpg",
  6. shopname: "大华店",
  7. stars: 4,
  8. mark: true,
  9. new: true,
  10. discount: false,
  11. marktext: "新店促销",
  12. shop_address: "上海市宝山区大华虎城A座10L",
  13. shop_distance: "6.5KM"
  14. }],
  15. tabs: [],
  16. activeTab: 0,
  17. productHeight: 0,
  18. productList: [{
  19. id: "1",
  20. title: "葛优躺(北京躺)电影足疗",
  21. price: "299",
  22. desc: "全店通用",
  23. open: true,
  24. imgurl: "../../images/product01.jpg"
  25. },
  26. {
  27. id: "2",
  28. title: "中式古法推拿",
  29. price: "299",
  30. desc: "暂未开放",
  31. open: false,
  32. imgurl: "../../images/product02.jpg"
  33. },
  34. {
  35. id: "3",
  36. title: "中式古法推拿",
  37. price: "299",
  38. desc: "暂未开放",
  39. open: false,
  40. imgurl: "../../images/product02.jpg"
  41. },
  42. {
  43. id: "4",
  44. title: "葛优躺(北京躺)电影足疗",
  45. price: "299",
  46. desc: "暂未开放",
  47. open: false,
  48. imgurl: "../../images/product01.jpg"
  49. }
  50. ],
  51. locationFlag:false
  52. },
  53. onLoad: async function () {
  54. wx.getSetting({
  55. success: (res) => {
  56. let authSetting = res.authSetting
  57. if (authSetting['scope.userLocation']) {
  58. console.log('已授权地理位置')
  59. // 已授权
  60. } else {
  61. // 未授权
  62. console.log('未授权');
  63. }
  64. }
  65. })
  66. var tabs = await this.getProductList();
  67. this.setData({
  68. tabs
  69. });
  70. this.getProductHeight()
  71. },
  72. //动态生成产品的父盒子高度
  73. getProductHeight: function () {
  74. var h = wx.getSystemInfoSync().windowHeight * (750 / wx.getSystemInfoSync().windowWidth);
  75. var productHeight = h - 430;
  76. this.setData({
  77. productHeight
  78. })
  79. },
  80. getProductList: async function () {
  81. const self = this
  82. var titles = ["全部项目", "SPA", "泡浴", "推拿", "足浴"];
  83. const tabs = [];
  84. var list = [{
  85. id: "1",
  86. title: "葛优躺(北京躺)电影足疗",
  87. price: "299",
  88. desc: "全店通用",
  89. open: true,
  90. imgurl: "../../images/product01.jpg"
  91. },
  92. {
  93. id: "2",
  94. title: "中式古法推拿",
  95. price: "299",
  96. desc: "暂未开放",
  97. open: false,
  98. imgurl: "../../images/product02.jpg"
  99. },
  100. {
  101. id: "3",
  102. title: "中式古法推拿",
  103. price: "299",
  104. desc: "暂未开放",
  105. open: false,
  106. imgurl: "../../images/product02.jpg"
  107. },
  108. {
  109. id: "4",
  110. title: "葛优躺(北京躺)电影足疗",
  111. price: "299",
  112. desc: "暂未开放",
  113. open: false,
  114. imgurl: "../../images/product01.jpg"
  115. }
  116. ]
  117. /* for (let i = 0; i < titles.length; i++) {
  118. let title = titles[i]
  119. let rs = await self.requestAll('https://example.com/ajax?index=0', { // \
  120. mock: true // - 添加这三行
  121. }, {}, 'get')
  122. tabs.push({
  123. title,
  124. productList: rs.list
  125. })
  126. } */
  127. for (let i = 0; i < titles.length; i++) {
  128. let title = titles[i];
  129. tabs.push({
  130. title,
  131. list
  132. })
  133. }
  134. tabs[2].list = [{
  135. id: "1",
  136. title: "葛优躺(北京躺)电影足疗",
  137. price: "299",
  138. desc: "全店通用",
  139. open: true,
  140. imgurl: "../../images/product01.jpg"
  141. }]
  142. return tabs;
  143. },
  144. requestAll(url, data, header = {}, method) {
  145. const _self = this
  146. wx.showLoading()
  147. return new Promise((resolve, reject) => {
  148. wx.request({
  149. url: url,
  150. data: data,
  151. header: header,
  152. dataType: 'json',
  153. method: method,
  154. success: (res => {
  155. wx.hideLoading()
  156. if (res.data.code === 1) {
  157. //200: 服务端业务处理正常结束
  158. resolve(res.data)
  159. } else {
  160. if (res.data.code === 0) {
  161. wx.showToast({
  162. title: res.data.message,
  163. })
  164. }
  165. if (res.data.code === 901) {
  166. console.log(res.data)
  167. }
  168. //其它错误,提示用户错误信息
  169. if (this._errorHandler != null) {
  170. //如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理
  171. this._errorHandler(res)
  172. }
  173. reject(res)
  174. }
  175. }),
  176. fail: (res => {
  177. if (this._errorHandler != null) {
  178. this._errorHandler(res)
  179. }
  180. wx.showToast({
  181. title: '网络异常请,稍后再试~',
  182. })
  183. reject(res)
  184. })
  185. })
  186. })
  187. },
  188. onTabClick(e) {
  189. const index = e.detail.index
  190. this.setData({
  191. activeTab: index
  192. })
  193. },
  194. onChange(e) {
  195. const index = e.detail.index
  196. this.setData({
  197. activeTab: index
  198. })
  199. },
  200. handleClick(e) {
  201. wx.navigateTo({
  202. url: './webview',
  203. })
  204. },
  205. getLocation: function(){
  206. const self = this
  207. console.log('sss')
  208. wx.getLocation({
  209. type: 'wgs84',
  210. success (res) {
  211. console.log(res)
  212. const latitude = res.latitude
  213. const longitude = res.longitude
  214. const speed = res.speed
  215. const accuracy = res.accuracy
  216. self.setData({
  217. isLocation: true
  218. })
  219. }
  220. })
  221. }
  222. })