index.js 6.4 KB

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