nearby.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <template>
  2. <view>
  3. <block v-if="true||config.Many_Store == 1">
  4. <!--pages/nearby/nearby.wxml-->
  5. <view class="ssbox bgfff dflex">
  6. <view class="search dflex">
  7. <view class="section" v-if="true||layerModel!=1">
  8. <picker mode="region" @change="bindRegionChange" :value="region" :custom-item="customItem">
  9. <view class="picker dflex">
  10. <!-- {{region[2]?region[2]:''}} -->
  11. {{regions}}
  12. <image src="/static/pages/images/bico.png"></image>
  13. </view>
  14. </picker>
  15. <!-- <template>
  16. <view class="container">
  17. <uni-data-picker placeholder="请选择班级" popup-title="请选择所在地区" :localdata="dataTree"
  18. v-model="classes" @change="onchange" @nodeclick="onnodeclick"
  19. @popupopened="onpopupopened" @popupclosed="onpopupclosed">
  20. </uni-data-picker>
  21. </view>
  22. </template> -->
  23. </view>
  24. <image src="/static/pages/images/ssico.png"></image>
  25. <input placeholder="搜索您想要找的网点" class="flex" :value="searchTitle" @input="search" @confirm="confirm"
  26. confirm-type="search"></input>
  27. <image src="/static/pages/images/clear.png" @tap="clearInput" v-if="searchTitle!=''"></image>
  28. </view>
  29. <view class="sousuo" @tap="confirmSearch">搜索</view>
  30. </view>
  31. <!-- <map id="myMap" class="map" latitude="{{point.latitude}}" longitude="{{point.longitude}}" markers="{{markers}}" show-location></map> -->
  32. <view class="tit">当前地址</view>
  33. <view class="pdlr20">
  34. <view class="location bgfff dflex r10">
  35. <view class="title">{{address}}</view>
  36. <view class="loca dflex" @tap="initLocation" v-if="layerModel!=1">
  37. <image src="/static/pages/images/wzico.png"></image>获取定位
  38. </view>
  39. <block v-if="layerModel==1">
  40. <view class="dflex dwsb">
  41. <view class="shibai">!</view><text>定位失败</text>
  42. </view>
  43. </block>
  44. </view>
  45. </view>
  46. </block>
  47. <view class="tit">附近网点</view>
  48. <view class="list pdlr20">
  49. <block v-for="(item, index) in pageList" :key="index">
  50. <view class="li r10">
  51. <image src="/static/pages/images/dangqian.png" class="dangqian" v-if="merchant.id==item.id"></image>
  52. <view class="cont" @tap="chooseMerchant(item.id,index)" :data-index="index">
  53. <view class="dizhi dflex">
  54. <view class="ddflex name flex" :style="'color:' + (item.isChoose ? '#999' : '#333')">
  55. <image
  56. :src="item.type==1?'/static/pages/images/store.png':'/static/pages/images/self.png'">
  57. </image>{{item.title}}
  58. </view>
  59. <view class="d-type" v-if="item.type != 4">{{item.type == 1 ? '归属门店' : item.type == 2 ? '上次下单' : item.type == 3 ? '总店' : item.type == 5 ? '小店' : ''}}</view>
  60. </view>
  61. <view class="ddflex">
  62. <view class="dizhi fflex">
  63. <view class="time dflex" v-if="item.businessTime">
  64. <image src="/static/pages/images/nearbytime.png"></image>
  65. <text>{{item.businessTime}}</text>
  66. </view>
  67. <view class="weizhi dflex">
  68. <image src="/static/pages/images/dwico1.png"></image><text>{{item.address}}</text>
  69. </view>
  70. </view>
  71. <view class="yue" v-if="item.range > 0">
  72. <image src="/static/pages/images/position_a_icon.png"></image>
  73. <text
  74. v-if="item.range!=50000">{{item.range > 1 ? item.range +'km' : item.mDistance+'m'}}</text>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="bottom dflex">
  79. <view class="bottom_left dflex">
  80. <image src="/static/pages/images/nearby_icon.png" class="mr20" @tap="goNavigation"
  81. :data-index="index"></image>
  82. <image src="/static/pages/images/nearby_icon1.png" @tap="makePhoneCall" :data-index="index">
  83. </image>
  84. </view>
  85. <view class="dflex bottom_right" @tap="tonearbyDet" :data-index="index">查看详情<image
  86. src="/static/pages/images/nearby_icon_left.png"></image>
  87. </view>
  88. </view>
  89. </view>
  90. </block>
  91. <block>
  92. <view class="nodata" v-if="pageList.length < 1">
  93. <image :src="picUrlss+'empty_dd.png'"></image>
  94. <text>该地区暂无网点</text>
  95. </view>
  96. </block>
  97. <view class="mask" @tap="closeLayer" :hidden="isShow" v-if="!isChoose"></view>
  98. <view class="kjpop" :hidden="isShow" v-if="!isChoose">
  99. <view class="top">
  100. <image src="/static/pages/images/mengdianxuanze.png"></image>
  101. </view>
  102. <view class="cont">
  103. <text>已切换至:</text>
  104. <view class="title">{{title}}</view>
  105. <view class="btn" @tap="closeLayer">我知道了</view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. const app = getApp();
  113. const req = require("../../utils/request.js");
  114. var QQMapWX = require("../../utils/qqmap.js");
  115. const api = require("../../utils/api.js");
  116. // import uniDataPicker from "../../uni_modules/uni-data-picker/components/uni-data-picker/uni-data-picker";
  117. export default {
  118. data() {
  119. return {
  120. picUrlss: req.public.picUrls,
  121. form: {
  122. page: 1,
  123. limit: 10,
  124. province: '',
  125. city: '',
  126. country: '',
  127. },
  128. pageList: [],
  129. isLoad: true,
  130. address: '',
  131. point: {},
  132. region: [],
  133. regions: '',
  134. searchTitle: '',
  135. history: [],
  136. isShow: true,
  137. addressIshow: false,
  138. isChoose: false,
  139. type: "",
  140. layerModel: "",
  141. location: "",
  142. merchant: "",
  143. merchantId: "",
  144. freshen: false,
  145. title: "",
  146. customItem: '全部',
  147. config: {}
  148. };
  149. },
  150. components: {
  151. // uniDataPicker
  152. },
  153. props: {},
  154. onLoad: function(options) {
  155. // 实例化API核心类
  156. QQMapWX.initMap();
  157. // console.log(options);
  158. let _ts = this;
  159. this.query = options;
  160. if (options.isChoose) {
  161. this.setData({
  162. isChoose: true
  163. });
  164. }
  165. if (options.type) {
  166. this.setData({
  167. type: options.type
  168. });
  169. }
  170. this.getstore();
  171. },
  172. onReachBottom() {
  173. this.form.page++;
  174. this.getList();
  175. },
  176. onShow: function() {
  177. let _ts = this;
  178. let config = JSON.parse(req.getStorage('configRes'))
  179. this.config = config
  180. if(config.Many_Store == 1){
  181. this.initLocation(() => {
  182. if (_ts.point) {
  183. _ts.form.lat = _ts.point.latitude;
  184. _ts.form.lng = _ts.point.longitude;
  185. // _ts.form.regionCode = _ts.point.regionCode;
  186. // console.log(_ts.point, _ts.point.latitude, _ts.point.regionCode);
  187. _ts.getList();
  188. } else {
  189. _ts.getList();
  190. }
  191. }); // this.showMap()
  192. }else{
  193. _ts.getList();
  194. }
  195. let history = req.getStorage('HISTORYS');
  196. this.setData({
  197. history: history
  198. });
  199. },
  200. methods: {
  201. async initLocation(success) {
  202. let _ts = this;
  203. await req.getLocation(res => {
  204. // console.log(res);
  205. if (res == 1) {
  206. _ts.setData({
  207. layerModel: res
  208. });
  209. uni.showModal({
  210. title: '温馨提示',
  211. content: '获取定位失败,请前往设置打开定位权限',
  212. showCancel: false,
  213. success(res) {
  214. if (res.confirm) {
  215. // console.log('用户点击确定');
  216. uni.openSetting({
  217. success(res) {
  218. // console.log(res
  219. // .authSetting); // res.authSetting = {
  220. }
  221. });
  222. }
  223. }
  224. });
  225. } else {
  226. _ts.setData({
  227. layerModel: 0
  228. });
  229. }
  230. QQMapWX.reverseGeocoder(res, data => {
  231. console.log('QQMapWX==' + JSON.stringify(data));
  232. if (data) {
  233. res.regionCode = data.ad_info.adcode;
  234. _ts.setData({
  235. address: data.address,
  236. 'region[0]': data.address_component.province,
  237. 'region[1]': data.address_component.city,
  238. 'region[2]': data.address_component.district,
  239. regions: data.address_component.district,
  240. location: data.location
  241. });
  242. _ts.setData({
  243. point: res
  244. });
  245. if (success && typeof success === 'function') {
  246. success.call(this);
  247. }
  248. } else {
  249. _ts.setData({
  250. layerModel: 1
  251. });
  252. _ts.confirmSearch();
  253. }
  254. });
  255. });
  256. },
  257. /**
  258. * @param {Object} regionCode
  259. */
  260. getList() {
  261. // console.log("执行", this.isLoad);
  262. if (!this.isLoad) return false;
  263. this.isLoad = false;
  264. let that = this;
  265. if(!that.form.province){
  266. delete that.form.province
  267. }
  268. if(!that.form.city){
  269. delete that.form.city
  270. }
  271. if(!that.form.country){
  272. delete that.form.country
  273. }
  274. // if (regionCode != undefined) {
  275. // this.form.regionCode = regionCode;
  276. // this.form.page = 1;
  277. // }
  278. this.form.isBusiness = 1; // this.data.form.regionCode=this.data.regionCode
  279. req.getRequest('/api/merchant/listV2', this.form, data => {
  280. if (data && data.length >= 10) this.isLoad = true;
  281. // console.log("执行", this.isLoad);
  282. let res;
  283. console.log('门店列表==',data)
  284. res = data.map(it => {
  285. it.isChoose = false;
  286. if (it.range > 0) it.range = parseFloat(it.range).toFixed(2), it.mDistance =
  287. parseFloat(it.mDistance).toFixed(0);
  288. if (this.isChoose && it.isGoods == 0 && JSON.parse(req.getStorage('configRes'))
  289. .Is_Store_Price_Stock == 0) it.isChoose = true;
  290. return it;
  291. });
  292. res = data.filter(it => it.isGoods != 0);
  293. console.log('门店列表1==',res)
  294. if (that.form.page > 1) {
  295. res = that.pageList.concat(data);
  296. } // if(!this.query.Timely_delivery_open){
  297. // }else{
  298. // res=res.filter(it=>it.isDefault!=1)
  299. // }
  300. // if(JSON.parse(req.getStorage('configRes')).Is_Store_Price_Stock==1&&res){
  301. // res=res.filter(it=>it.isDefault!=1)
  302. // }
  303. if (!req.getStorage('defaultMerchant')) {
  304. api.defaultMerchant(req, "", data => {
  305. // console.log(data);
  306. });
  307. }
  308. that.setData({
  309. pageList: res
  310. });
  311. if (res.length <= 0) {
  312. this.setData({
  313. addressIshow: true
  314. });
  315. } else {
  316. this.setData({
  317. addressIshow: false
  318. });
  319. }
  320. // console.log(res);
  321. });
  322. },
  323. chooseMerchant(id, index) {
  324. // if(id==this.merchant.id) return false
  325. let page = this.pageList[index];
  326. if (this.isChoose) {
  327. if (page.isGoods == 0) return req.msg('该门店不能自提');
  328. let pages = getCurrentPages();
  329. var prevPage = pages[pages.length - 2];
  330. if (page.type == 5) {
  331. prevPage.$vm.setData({
  332. merchant: page,
  333. merchantId: page.merchantDTO.id,
  334. ['query.merchantId']: page.merchantDTO.id,
  335. ['query.shopId']: page.id,
  336. freshen: true
  337. });
  338. } else {
  339. prevPage.$vm.setData({
  340. merchant: page,
  341. merchantId: page.id,
  342. ['query.merchantId']: page.id,
  343. ['query.shopId']: '',
  344. freshen: true
  345. });
  346. }
  347. // 海报分享切换
  348. if (prevPage.$vm.scene) {
  349. prevPage.$vm.setData({
  350. switch: false
  351. });
  352. }
  353. // 切换门店
  354. if (this.type == 1) {
  355. prevPage.setData({
  356. ['query.merchantId']: page.id
  357. });
  358. }
  359. // console.log(prevPage.$vm)
  360. uni.navigateBack();
  361. }
  362. var timestamp = Date.parse(new Date());
  363. if (page.type == 5) {
  364. page.time = timestamp + 1 * 60 * 1000
  365. page.merchantDTO.time = timestamp + 1 * 60 * 1000
  366. req.setStorage('smallShop', page);
  367. req.setStorage('MERCHANT', page.merchantDTO);
  368. } else {
  369. page.time = timestamp + 1 * 60 * 1000
  370. req.setStorage('MERCHANT', page);
  371. req.removeStorage('smallShop');
  372. }
  373. this.setData({
  374. title: page.title,
  375. isShow: false
  376. });
  377. this.getstore(); // wx.navigateBack();
  378. },
  379. // showMap() {
  380. // req.getRequest('/api/merchant/list', { page: 1, limit: 100 }, data => {
  381. // // console.log(data)
  382. // data.forEach(res => {
  383. // this.setData({
  384. // 'markers[0].latitude': res.lat,
  385. // 'markers[0].longitude': res.lng,
  386. // 'markers[0].iconPath': '/pages/images/location.png'
  387. // })
  388. // })
  389. // })
  390. // },
  391. bindRegionChange: function(e) {
  392. let that = this;
  393. console.log('picker发送选择改变,携带值为', e.detail);
  394. let code = e.detail.code;
  395. that.isLoad = true;
  396. that.form.page = 1;
  397. // that.getList(e.detail.code[2]);
  398. if(code.length == 1){
  399. that.form.province = code[0];
  400. that.form.city = '';
  401. that.form.country = '';
  402. that.region = e.detail.value[0];
  403. that.regions = that.region.toString('');
  404. }else if(code.length == 2){
  405. that.form.province = code[0];
  406. that.form.city = code[1];
  407. that.form.country = '';
  408. that.region = [e.detail.value[0],e.detail.value[1]];
  409. that.regions = that.region[1].toString('');
  410. }else{
  411. that.form.province = code[0];
  412. that.form.city = code[1];
  413. that.form.country = code[2];
  414. that.region = [e.detail.value[0],e.detail.value[1],e.detail.value[2]];
  415. that.regions = that.region[2].toString('');
  416. }
  417. that.getList();
  418. // this.setData({
  419. // region: e.detail.value
  420. // 'form.regionCode': e.detail.code[2]
  421. // });
  422. },
  423. getstore() {
  424. if (this.isChoose) return false;
  425. let merchant;
  426. if (req.getStorage('smallShop')) {
  427. merchant = req.getStorage('smallShop');
  428. } else {
  429. merchant = req.getStorage('MERCHANT');
  430. }
  431. let pages = getCurrentPages();
  432. var prevPage = pages[pages.length - 2];
  433. prevPage.$vm.setData({
  434. freshen: true
  435. });
  436. this.setData({
  437. merchant: merchant
  438. });
  439. },
  440. // 查看详情
  441. tonearbyDet(event) {
  442. let index = event.currentTarget.dataset.index;
  443. let page = this.pageList[index];
  444. uni.navigateTo({
  445. url: '/pages/nearbyDetails/nearbyDetails?id=' + page.id
  446. });
  447. },
  448. //拨打电话
  449. makePhoneCall(event) {
  450. let index = event.currentTarget.dataset.index;
  451. let page = this.pageList[index];
  452. uni.makePhoneCall({
  453. phoneNumber: page.phone
  454. });
  455. },
  456. //搜索
  457. search(e) {
  458. // console.log(e.detail.value);
  459. this.searchTitle = e.detail.value;
  460. this.setData({
  461. searchTitle: e.detail.value
  462. }); // return e.detail.value.replace(/\s+/g, '').replace(/[^\u4e00-\u9fa5a-zA-Z0-9\w]/g, '');
  463. },
  464. //清除输入框
  465. clearInput() {
  466. this.setData({
  467. searchTitle: ''
  468. });
  469. },
  470. confirmSearch() {
  471. let value = this.searchTitle;
  472. this.toSearch(value, true);
  473. },
  474. confirm() {
  475. let value = this.searchTitle;
  476. this.toSearch(value, true);
  477. },
  478. toSearch(value, isSave) {
  479. this.isLoad = isSave;
  480. let form = this.form;
  481. form.page = 1;
  482. form.title = value;
  483. form.isBusiness = 1; // form.regionCode=''
  484. req.getRequest('/api/merchant/listV2', form, res => {
  485. // console.log("1")
  486. let data;
  487. data = res.map(it => {
  488. it.isChoose = false;
  489. if (it.range > 0) it.range = parseFloat(it.range).toFixed(1);
  490. if (this.isChoose && it.isGoods == 0) it.isChoose = true;
  491. return it;
  492. });
  493. data = data.filter(it => it.isGoods != 0);
  494. if (!req.getStorage('defaultMerchant')) {
  495. api.defaultMerchant(req, "", data => {
  496. // console.log(data);
  497. });
  498. } // req.setStorage('defaultMerchant',data.filter(it=>it.isDefault==1))
  499. // if(JSON.parse(req.getStorage('configRes')).Is_Store_Price_Stock==1&&data){
  500. // data=data.filter(it=>it.isDefault!=1)
  501. // }
  502. this.setData({
  503. pageList: data
  504. });
  505. if (data.length <= 0) {
  506. this.setData({
  507. addressIshow: true
  508. });
  509. } else {
  510. this.setData({
  511. addressIshow: false
  512. });
  513. }
  514. });
  515. },
  516. closeLayer() {
  517. this.setData({
  518. isShow: true
  519. });
  520. uni.navigateBack();
  521. },
  522. goNavigation(event) {
  523. let index = event.currentTarget.dataset.index;
  524. let page = this.pageList[index];
  525. let plugin = requirePlugin('routePlan');
  526. let key = req.public.mapLBSKEY; //使用在腾讯位置服务申请的key
  527. let referer = req.getStorage('appName'); //调用插件的app的名称
  528. // console.log("名称====" + referer);
  529. let endPoint = JSON.stringify({
  530. //终点
  531. 'name': page.title,
  532. 'latitude': page.lat,
  533. 'longitude': page.lng
  534. });
  535. uni.navigateTo({
  536. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
  537. });
  538. }
  539. }
  540. };
  541. </script>
  542. <style>
  543. @import "./nearby.css";
  544. </style>