index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="wrap_nr">
  6. <view class="store_list">
  7. <view :class="item.is_selected ? 'store_item selected' : 'store_item'" @tap="onSelectStore" :data-item="item" v-for="(item, index) in storeList" :key="index">
  8. <view class="item_l">
  9. <view class="item_name">{{ item.title }}</view>
  10. <view class="item_info">
  11. <van-icon name="location-o" color="#666666" size="22px" />
  12. <view class="wenzi">{{ item.address }}</view>
  13. </view>
  14. <view class="item_info">
  15. <van-icon name="clock-o" color="#666666" size="20px" />
  16. <view class="wenzi">{{ item.begin_at + '~' + item.end_at }}</view>
  17. </view>
  18. <view class="item_info">
  19. <van-icon name="phone-o" color="#666666" size="22px" />
  20. <view class="wenzi">{{ item.phone }}</view>
  21. </view>
  22. </view>
  23. <view class="item_r">
  24. <view class="juli">距您{{ item.distance }}km</view>
  25. <image class="store_logo" :src="imgUrl + item.thumb"></image>
  26. <view class="desc">去下单</view>
  27. </view>
  28. <!-- 推荐(距离最近的店) -->
  29. <image class="tuijian_icon" src="/static/statics/img/icon_tuijian.png" v-if="item.is_tuijian"></image>
  30. <!-- 选中 -->
  31. <image class="selected_icon" src="/static/statics/img/icon_selected.png" v-if="item.is_selected"></image>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 开启定位提示 -->
  37. <van-dialog
  38. class="custom_dialog"
  39. title="地理位置未授权"
  40. message="开启羊汤馆小程序定位授权后,可为您推荐就近门店"
  41. :show="showOpenLocation"
  42. confirm-button-text="授权定位"
  43. confirm-button-color="#D54C43"
  44. show-cancel-button
  45. @close="onCloseLocation"
  46. @confirm="onConfirmLocation"
  47. ></van-dialog>
  48. <!-- 所选门店不支持的提醒 -->
  49. <van-dialog
  50. :title="tipsTitle"
  51. :message="tipsMessage"
  52. :show="showTips"
  53. class="single_btn"
  54. confirm-button-color="#000000"
  55. confirmButtonText="我知道了"
  56. @confirm="closeShowTips"
  57. ></van-dialog>
  58. <!-- loading -->
  59. <!-- <van-overlay show="{{ loading }}" z-index="100">
  60. <van-loading custom-class="custom_loading" />
  61. </van-overlay> -->
  62. </view>
  63. </template>
  64. <script>
  65. // index.js
  66. let myPro = require('../../utils/wxRequest.js');
  67. let util = require('../../utils/util.js');
  68. export default {
  69. data() {
  70. return {
  71. imgUrl: getApp().globalData.imgUrl,
  72. loading: false,
  73. // 全局loading
  74. page: 1,
  75. size: 10,
  76. finished: false,
  77. storeList: [],
  78. // 店列表
  79. fare_type: 1,
  80. // 0外卖 1自提 默认自提
  81. showOpenLocation: false,
  82. // 开启定位提醒
  83. showTips: false,
  84. checkedAddress: null,
  85. lat: null,
  86. lng: null,
  87. store: '',
  88. tipsTitle: '',
  89. tipsMessage: '',
  90. selectStore: ''
  91. };
  92. },
  93. onLoad: function (options) {
  94. // Do some initialize when page load.
  95. let that = this; // 拒绝定位时,先提醒去开启
  96. if (getApp().globalData.location_auth == -1) {
  97. that.setData({
  98. showOpenLocation: true
  99. });
  100. }
  101. },
  102. onShow: function () {
  103. // Do something when page show.
  104. let that = this; // 已选的店
  105. if (uni.getStorageSync('store')) {
  106. that.setData({
  107. store: JSON.parse(uni.getStorageSync('store'))
  108. });
  109. } // 获取配送流程
  110. if (uni.getStorageSync('fare_type')) {
  111. that.setData({
  112. fare_type: uni.getStorageSync('fare_type')
  113. });
  114. } // 获取配送地址
  115. if (uni.getStorageSync('checkedAddress')) {
  116. that.setData({
  117. checkedAddress: JSON.parse(uni.getStorageSync('checkedAddress'))
  118. });
  119. } // 经纬度
  120. if (that.fare_type == 0 && that.checkedAddress) {
  121. // 外卖 按收货地址的经纬度
  122. that.setData({
  123. lat: that.checkedAddress.lat,
  124. lng: that.checkedAddress.lnt
  125. });
  126. } else {
  127. // 自取 按定位的经纬度
  128. that.setData({
  129. lat: getApp().globalData.lat,
  130. lng: getApp().globalData.lng
  131. });
  132. } // 已定位
  133. if (getApp().globalData.location_auth == 1) {
  134. // 已定位
  135. that.setData({
  136. page: 1,
  137. storeList: [],
  138. finished: false
  139. });
  140. that.getStoreList();
  141. }
  142. },
  143. onReady: function () {
  144. // Do something when page ready.
  145. },
  146. onHide: function () {
  147. // Do something when page hide.
  148. },
  149. onUnload: function () {
  150. // Do something when page close.
  151. },
  152. onPullDownRefresh: function () {},
  153. onReachBottom: function () {
  154. // Do something when page reach bottom.
  155. let that = this;
  156. if (!that.finished) {
  157. that.getStoreList();
  158. }
  159. },
  160. onPageScroll: function () {
  161. // Do something when page scroll
  162. },
  163. onResize: function () {
  164. // Do something when page resize
  165. },
  166. methods: {
  167. // 获取店列表
  168. getStoreList() {
  169. let that = this;
  170. let data = {
  171. lat: that.lat,
  172. lng: that.lng,
  173. page: that.page,
  174. size: that.size
  175. }; // console.log('参数的经纬度',that.data.lat,that.data.lng);
  176. myPro
  177. .wxRequest('user/store/list', 'GET', data)
  178. .then((res) => {
  179. let list = res.result; // 无数据
  180. if (that.fare_type == 0 && that.page == 1 && list.length == 0) {
  181. that.setData({
  182. finished: true,
  183. showTips: true,
  184. tipsTitle: '抱歉,您的配送地址内暂无可用门店',
  185. tipsMessage: '可前往自取或更换地址,不便之处敬请见谅'
  186. }); // 清掉所选地址
  187. uni.removeStorageSync('checkedAddress');
  188. } else if (list.length == 0) {
  189. that.setData({
  190. finished: true
  191. });
  192. uni.showToast({
  193. title: '暂无更多数据',
  194. icon: 'none'
  195. });
  196. } else {
  197. // 有数据
  198. for (let i in list) {
  199. if (i == 0 && that.page == 1) {
  200. list[i].is_tuijian = 1; // 推荐距离最近的店
  201. }
  202. if (that.store) {
  203. if (that.store.id == list[i].id) {
  204. list[i].is_selected = 1;
  205. }
  206. } else {
  207. // if(i == 0){
  208. // list[i].is_selected = 1;
  209. // }else{
  210. // list[i].is_selected = 0;
  211. // }
  212. list[i].is_selected = 0;
  213. }
  214. }
  215. that.setData({
  216. storeList: that.storeList.concat(list),
  217. page: that.page + 1
  218. });
  219. }
  220. })
  221. .catch((err) => {
  222. console.log('报错信息', err);
  223. uni.showToast({
  224. title: err,
  225. icon: 'none'
  226. });
  227. });
  228. },
  229. // 主动切换门店
  230. onSelectStore(event) {
  231. let that = this;
  232. let item = event.currentTarget.dataset.item;
  233. let list = that.storeList;
  234. let currentObj = null; // 判断点选店铺是否支持所选配送方式
  235. if (that.fare_type == 0) {
  236. if (!item.is_delivery) {
  237. that.setData({
  238. showTips: true,
  239. tipsTitle: '抱歉,此门店暂不支持外卖',
  240. tipsMessage: '可前往自取或更换地址,不便之处敬请见谅'
  241. });
  242. return;
  243. }
  244. } else {
  245. if (!item.is_ziti) {
  246. that.setData({
  247. showTips: true,
  248. tipsTitle: '抱歉,此门店暂不支持自取',
  249. tipsMessage: '可更换门店,不便之处敬请见谅'
  250. });
  251. return;
  252. }
  253. }
  254. for (let i in list) {
  255. if (list[i].id == item.id) {
  256. list[i].is_selected = 1;
  257. currentObj = list[i];
  258. } else {
  259. list[i].is_selected = 0;
  260. }
  261. }
  262. that.setData({
  263. storeList: list,
  264. selectStore: currentObj
  265. }); // 更新选中门店
  266. uni.setStorage({
  267. key: 'store',
  268. data: JSON.stringify(that.selectStore)
  269. }); // 判断是否切换门店,如有需清空购物车
  270. if (that.store && that.store.id != that.selectStore.id) {
  271. uni.removeStorage({
  272. key: 'localCart'
  273. });
  274. } // 进入商品选购
  275. uni.navigateTo({
  276. url: '/pages/goods/index'
  277. });
  278. },
  279. // 取消授权提醒
  280. onCloseLocation() {
  281. let that = this;
  282. that.setData({
  283. showOpenLocation: false
  284. }); // 当是外卖是,进首页
  285. if (that.fare_type == 0) {
  286. uni.reLaunch({
  287. url: '/pages/index/index'
  288. });
  289. } else {
  290. // 这时只能调取到默认的
  291. getApp().globalData.lat = 0;
  292. getApp().globalData.lng = 0;
  293. that.setData({
  294. page: 1,
  295. storeList: [],
  296. finished: false,
  297. lat: getApp().globalData.lat,
  298. lng: getApp().globalData.lng
  299. });
  300. that.getStoreList();
  301. }
  302. },
  303. // 同意去打开地理位置
  304. onConfirmLocation() {
  305. let that = this;
  306. uni.openSetting({
  307. success: function (res) {
  308. console.log(res);
  309. let authSetting = res.authSetting;
  310. if (authSetting['scope.userLocation']) {
  311. // 开启
  312. getApp().globalData.getLocal(function () {
  313. that.setData({
  314. page: 1,
  315. storeList: [],
  316. finished: false
  317. });
  318. that.setData({
  319. lat: getApp().globalData.lat,
  320. lng: getApp().globalData.lng
  321. });
  322. that.getStoreList();
  323. });
  324. } else {
  325. // 未开启
  326. that.setData({
  327. showOpenLocation: true
  328. });
  329. }
  330. }
  331. });
  332. },
  333. // 关闭提醒
  334. closeShowTips() {
  335. let that = this;
  336. that.setData({
  337. showTips: false
  338. });
  339. }
  340. }
  341. };
  342. </script>
  343. <style>
  344. /**index.wxss**/
  345. .wrap_nr {
  346. padding: 30rpx;
  347. }
  348. .store_item {
  349. width: 690rpx;
  350. padding: 40rpx 0;
  351. margin-top: 30rpx;
  352. background: #f9f9f9;
  353. border-radius: 15rpx;
  354. display: flex;
  355. align-items: center;
  356. position: relative;
  357. }
  358. .store_item .item_l {
  359. width: 460rpx;
  360. padding-left: 30rpx;
  361. font-size: 26rpx;
  362. color: #666666;
  363. border-right: 1rpx solid rgba(216, 169, 115, 0.2);
  364. }
  365. .store_item .item_name {
  366. font-size: 32rpx;
  367. color: #0c0c0c;
  368. }
  369. .store_item .item_info {
  370. display: flex;
  371. align-items: center;
  372. margin-top: 26rpx;
  373. }
  374. .store_item .item_info .icon {
  375. width: 24rpx;
  376. height: 24rpx;
  377. }
  378. .store_item .item_info .wenzi {
  379. padding-left: 10rpx;
  380. width: 340rpx;
  381. }
  382. .store_item .item_r {
  383. flex: 1;
  384. display: flex;
  385. flex-direction: column;
  386. align-items: center;
  387. }
  388. .store_item .item_r .juli {
  389. font-size: 24rpx;
  390. color: #666666;
  391. padding: 4rpx 10rpx;
  392. background: #ffffff;
  393. box-shadow: 0rpx 1rpx 10rpx 0rpx rgba(0, 0, 0, 0.1);
  394. border-radius: 14rpx;
  395. position: relative;
  396. }
  397. .store_item .item_r .juli::after {
  398. content: '';
  399. display: block;
  400. position: absolute;
  401. bottom: -22rpx;
  402. left: 50%;
  403. width: 0rpx;
  404. height: 0rpx;
  405. border: 12rpx solid transparent;
  406. border-top: 12rpx solid #ffffff;
  407. }
  408. .store_item .item_r .store_logo {
  409. width: 60rpx;
  410. height: 69rpx;
  411. margin-top: 20rpx;
  412. }
  413. .store_item .item_r .desc {
  414. font-size: 30rpx;
  415. color: #0c0c0c;
  416. padding-top: 12rpx;
  417. }
  418. .store_item .tuijian_icon {
  419. width: 77rpx;
  420. height: 74rpx;
  421. position: absolute;
  422. top: -5rpx;
  423. right: -5rpx;
  424. }
  425. .store_item .selected_icon {
  426. width: 61rpx;
  427. height: 61rpx;
  428. position: absolute;
  429. bottom: -1px;
  430. right: -1px;
  431. }
  432. /* 选中状态 */
  433. .store_item.selected {
  434. background: #ffffff;
  435. border: 1px solid #d54c43;
  436. }
  437. </style>