index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // pages/tabber/home/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. menuList: [
  9. // {
  10. // url: '/image/home/ruhexiadan.png',
  11. // text: '如何下单'
  12. // },
  13. // {
  14. // url: '/image/home/changjianwenti.png',
  15. // text: '常见问题'
  16. // }
  17. // ,
  18. // {
  19. // url: '/image/home/xidifanwei.png',
  20. // text: '洗涤范围'
  21. // }
  22. ],
  23. current: 3,
  24. btnInfo: app.globalData.btnInfo,
  25. topShow: true,
  26. worke: [],
  27. status: "",
  28. islocation: "",
  29. hasUserInfo: false,
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. var topShow=wx.getStorageSync("topShow");
  36. console.log(topShow);
  37. if(topShow===""){
  38. wx.setStorageSync('topShow',true);
  39. }
  40. // this.getUser()
  41. },
  42. onShow: function (options) {
  43. var topShow=wx.getStorageSync('topShow');
  44. console.log(topShow);
  45. this.setData({
  46. islocation: wx.getStorageSync('islocation'),
  47. status: app.globalData.status,
  48. topShow:topShow
  49. })
  50. var nid =wx.getStorageSync('nid');
  51. var token =wx.getStorageSync('token');
  52. if(!nid || !token){
  53. app.login().then(res => {
  54. console.log(res)
  55. this.setData({
  56. token: res.message.token,
  57. nid: res.message.network_id
  58. })
  59. this.workDesc(res.message.network_id);
  60. })
  61. }else{
  62. this.workDesc(nid);
  63. }
  64. },
  65. onReady: function () {
  66. },
  67. /**
  68. * 获取用户信息
  69. */
  70. getUser(){
  71. var that=this;
  72. app.api.useApi(app.globalData.baseAppUrl+"api/user/getUser","","get").then((res)=>{
  73. if(res.code==200){
  74. wx.hideLoading();
  75. that.setData({
  76. hasUserInfo:res.message.data.avatar!=""?true:false
  77. })
  78. }else{
  79. that.getUser()
  80. }
  81. }).catch((err)=>{
  82. that.getUser()
  83. })
  84. },
  85. getUserProfile(e) {
  86. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  87. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  88. wx.getUserProfile({
  89. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  90. success: (res) => {
  91. this.setData({
  92. hasUserInfo: true
  93. })
  94. this.placeOrder()
  95. }
  96. })
  97. },
  98. //网点详情
  99. workDesc: function (nid="") {
  100. var that = this;
  101. if (nid<1) {
  102. that.setData({
  103. worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': 3, 'distance': 0 }
  104. })
  105. return false;
  106. }
  107. app.api.useApi(app.globalData.baseAppUrl + "api/network/desc", {
  108. network_id: nid,
  109. lat:wx.getStorageSync('latitude'),
  110. lng:wx.getStorageSync('longitude')
  111. }, "get").then(function (res) {
  112. console.log(res);
  113. if (res.code != 200) {
  114. wx.showLoading({
  115. title: '重新选择网点' + res.status,
  116. })
  117. setTimeout(function () {
  118. wx.hideLoading();
  119. wx.navigateTo({
  120. url: '/pages/home/map/map',
  121. })
  122. }, 1000)
  123. } else {
  124. that.setData({
  125. worke: res.message.data
  126. })
  127. }
  128. }).catch(function (err) {
  129. console.log(err);
  130. })
  131. },
  132. toMap() {
  133. wx.navigateTo({
  134. url: '/pages/home/map/map',
  135. })
  136. },
  137. placeOrder() {
  138. if (this.data.islocation) {
  139. this.getLocation()
  140. }
  141. var parmise=this.data.worke;
  142. if(wx.getStorageSync('nid')&&wx.getStorageSync('nid')!=0){
  143. wx.navigateTo({
  144. url: '/pages/order/placeOrder/placeOrder?parmise='+JSON.stringify(parmise),
  145. })
  146. }else{
  147. wx.showToast({
  148. title: '请先选择网点',
  149. icon: 'none',
  150. duration: 2000
  151. })
  152. }
  153. },
  154. close() {
  155. wx.setStorageSync('topShow', false);
  156. this.setData({
  157. topShow: false
  158. })
  159. },
  160. onReady: function () {
  161. this.toast = this.selectComponent("#toast");
  162. },
  163. listenerLogin: function () {
  164. this.toast.showToast('领取成功');
  165. },
  166. rightClick(e) {
  167. console.log(1);
  168. },
  169. getLocation(e) {
  170. var that = this;
  171. wx.getLocation({
  172. success(res) {
  173. console.log('开启后台定位', res)
  174. console.log('location change', res)
  175. that.setData({
  176. location: res,
  177. islocation: true,
  178. })
  179. app.api.useApi(app.globalData.baseAppUrl + "api").then(function (res) {
  180. console.log(res)
  181. }, function (error) {
  182. console.log(error);
  183. })
  184. },
  185. fail(res) {
  186. console.log('开启后台定位失败', res);
  187. that.setData({
  188. islocation: true
  189. })
  190. wx.showLoading({
  191. title: '开启后台定位失败,请重试。',
  192. })
  193. return false;
  194. }
  195. })
  196. }
  197. })