nearby.vue 17 KB

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