goodsManagementStore.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // pages/shopList/shopList.js
  2. const app = getApp();
  3. const user = require('../../../utils/cache.js');
  4. // import StoreApi from "../../../api/storeList.js";
  5. import staff from '../../../api/StaffApi'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. phoneIcon: 'https://dy.shpr.top//welfareGo/groupmeallist/shop_list_phone.png',
  12. page: 1,
  13. pageSize: 5,
  14. longitude: "",
  15. latitude: "",
  16. keyword: "",
  17. storeList: [],
  18. selectStoreInfo: null,
  19. id: 0,
  20. isClicked: false, //是否已经点击过了,默认没有
  21. pageSource: "",
  22. way: ''
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. let _self = this;
  29. let way = options.way
  30. console.log('way' + way)
  31. if (way == 1) {
  32. _self.setData({
  33. way: way
  34. })
  35. }
  36. console.log(options)
  37. if (options.id) {
  38. _self.setData({
  39. id: options.id
  40. })
  41. }
  42. if (options.pageSource) {
  43. _self.setData({
  44. pageSource: options.pageSource
  45. })
  46. }
  47. },
  48. /**
  49. * 生命周期函数--监听页面初次渲染完成
  50. */
  51. onReady: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. let _self = this;
  58. //获取最近的经纬度
  59. // let locationPosition = user.getNearLocation()
  60. // if (locationPosition != null) {
  61. // _self.setData({
  62. // longitude: locationPosition.longitude,
  63. // latitude: locationPosition.latitude
  64. // })
  65. // }
  66. _self.getNearbyStoreList();
  67. },
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload: function () {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh: function () {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom: function () {
  87. let _self = this;
  88. _self.setData({
  89. page: _self.data.page + 1
  90. })
  91. //获取门店列表
  92. _self.getNearbyStoreList('pull')
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage: function () {
  98. },
  99. /**
  100. * 获取门店列表
  101. */
  102. async getNearbyStoreList(step = 'init') {
  103. console.log("进入方法执行")
  104. let _self = this;
  105. let page = 0
  106. if (this.data.keyword != null && this.data.keyword != '') {
  107. page = 1
  108. } else {
  109. page = this.data.page
  110. }
  111. try {
  112. let storeRes = await staff.staffShopList({
  113. mobile:user.getMobile()
  114. });
  115. if (storeRes.code == 200 && storeRes.msg == 'success') {
  116. let list = storeRes.data;
  117. if (list.length != 0) {
  118. list.map((item, index) => {
  119. if (item.distance !== null) {
  120. let distance = parseFloat(item.distance);
  121. item.distance = distance.toFixed(2);
  122. }
  123. if (item.id == _self.data.id && _self.data.isClicked == false) {
  124. item.active = true;
  125. _self.setData({
  126. selectStoreInfo: item,
  127. })
  128. } else {
  129. item.active = false;
  130. }
  131. })
  132. }
  133. if (step == 'init') { //初始化
  134. _self.setData({
  135. storeList: list
  136. })
  137. } else {
  138. if (list.length == 0) {
  139. _self.setData({
  140. page: _self.data.page - 1
  141. })
  142. } else {
  143. //分页
  144. _self.setData({
  145. storeList: _self.data.storeList.concat(list),
  146. })
  147. }
  148. }
  149. }
  150. } catch (error) {
  151. console.log(error);
  152. }
  153. },
  154. //打电话
  155. callPhone(e) {
  156. // console.log(e);
  157. let _self = this;
  158. let phone = e.currentTarget.dataset.phone;
  159. wx.makePhoneCall({
  160. phoneNumber: phone
  161. })
  162. },
  163. /**
  164. * 选择门店
  165. */
  166. selectStore(e) {
  167. let _self = this;
  168. let idx = e.currentTarget.dataset.idx;
  169. let storeList = _self.data.storeList;
  170. _self.setData({
  171. isClicked: true,
  172. })
  173. for (let i = 0; i < storeList.length; i++) {
  174. if (idx == i) {
  175. storeList[i].active = true;
  176. _self.setData({
  177. selectStoreInfo: storeList[i]
  178. })
  179. } else {
  180. storeList[i].active = false;
  181. }
  182. }
  183. _self.setData({
  184. storeList
  185. })
  186. },
  187. /**
  188. * 选择门店
  189. */
  190. sureStore() {
  191. let _self = this;
  192. //存储选中的地址
  193. if (this.data.way == 1) {
  194. user.setChooseStore(_self.data.selectStoreInfo);
  195. wx.redirectTo({
  196. url: '../goodsManagements/goodsManagements',
  197. })
  198. }
  199. },
  200. listenInput: function (e) {
  201. console.log("进入确定")
  202. let keyword = e.detail.value;
  203. this.data.lock = false;
  204. this.setData({
  205. keyword,
  206. })
  207. this.getNearbyStoreList();
  208. },
  209. })