index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. },
  35. onShow: function (options) {
  36. this.setData({
  37. islocation: wx.getStorageSync('islocation'),
  38. status: app.globalData.status,
  39. })
  40. var nid =wx.getStorageSync('nid');
  41. var token =wx.getStorageSync('token');
  42. if(!nid || !token){
  43. app.login().then(res => {
  44. console.log(res)
  45. this.setData({
  46. token: res.message.token,
  47. nid: res.message.network_id
  48. })
  49. this.workDesc(res.message.network_id);
  50. })
  51. }else{
  52. this.workDesc(nid);
  53. }
  54. },
  55. onReady: function () {
  56. },
  57. //网点详情
  58. workDesc: function (nid="") {
  59. var that = this;
  60. if (!nid) {
  61. that.setData({
  62. worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': 3, 'distance': 0 }
  63. })
  64. return false;
  65. }
  66. app.api.useApi(app.globalData.baseAppUrl + "api/network/desc", {
  67. network_id: nid,
  68. }, "get").then(function (res) {
  69. if (res.code != 200) {
  70. wx.showLoading({
  71. title: '网点加载失败' + res.status,
  72. })
  73. } else {
  74. that.setData({
  75. worke: res.message.data
  76. })
  77. }
  78. wx.hideLoading();
  79. }).catch(function (err) {
  80. console.log(222);
  81. })
  82. },
  83. toMap() {
  84. wx.navigateTo({
  85. url: '/pages/home/map/map',
  86. })
  87. },
  88. placeOrder() {
  89. if (this.data.islocation) {
  90. this.getLocation()
  91. }
  92. var parmise=this.data.worke;
  93. wx.navigateTo({
  94. url: '/pages/order/placeOrder/placeOrder?parmise='+JSON.stringify(parmise),
  95. })
  96. },
  97. close() {
  98. this.setData({
  99. topShow: false
  100. })
  101. },
  102. onReady: function () {
  103. this.toast = this.selectComponent("#toast");
  104. },
  105. listenerLogin: function () {
  106. this.toast.showToast('领取成功');
  107. },
  108. rightClick(e) {
  109. console.log(1);
  110. },
  111. getLocation(e) {
  112. var that = this;
  113. wx.getLocation({
  114. success(res) {
  115. console.log('开启后台定位', res)
  116. console.log('location change', res)
  117. that.setData({
  118. location: res,
  119. islocation: true,
  120. })
  121. app.api.useApi(app.globalData.baseAppUrl + "api").then(function (res) {
  122. console.log(res)
  123. }, function (error) {
  124. console.log(error);
  125. })
  126. },
  127. fail(res) {
  128. console.log('开启后台定位失败', res);
  129. that.setData({
  130. islocation: true
  131. })
  132. wx.showLoading({
  133. title: '开启后台定位失败,请重试。',
  134. })
  135. return false;
  136. }
  137. })
  138. }
  139. })