order.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view class="container">
  3. <view class="topNav flex">
  4. <!-- <image @click="backIndex" class="back" src="../../static/icon/back.png" mode="widthFix"></image> -->
  5. <view class="inputbox flex">
  6. <image class="search" src="../../static/icon/search.png" mode="widthFix"></image>
  7. <input class="input" confirm-type='搜索' @confirm='searchData' placeholder="请输入城市或者门店" type="text"
  8. v-model="search" />
  9. </view>
  10. </view>
  11. <!-- <pickerAddress class="" @change="onCityClick">
  12. <view class="address flex">
  13. <view class="flex">
  14. <text class="text">{{province}}</text>
  15. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  16. </view>
  17. <view class="flex">
  18. <text class="text">{{city}}</text>
  19. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  20. </view>
  21. <view class="flex">
  22. <text class="text">{{district}}</text>
  23. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  24. </view>
  25. </view>
  26. </pickerAddress> -->
  27. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="storeList">
  28. <!-- 空白页 -->
  29. <!-- <empty v-if="loaded === true && orderList.length === 0"></empty> -->
  30. <!-- 订单列表 -->
  31. <view class="itemList">
  32. <view class="item flex" v-for="(item,index) in orderList" :key='index' @click="onChecked(item)">
  33. <view class="imgBox">
  34. <image class="logo" :src="item.image" mode="aspectFit"></image>
  35. </view>
  36. <view class="padding-l-20 flex-grow-true" style="max-width: 75%;">
  37. <view class="title clamp flex">
  38. <view class="name clamp">
  39. {{item.name}}
  40. </view>
  41. <view class="km">
  42. {{item.range<1?item.distance+'m':item.range+'km'}}
  43. </view>
  44. </view>
  45. <view class="list">
  46. <image src="../../static/store/store1.png" mode=""></image>{{item.detailed_address}}
  47. </view>
  48. <view class="list">
  49. <image src="../../static/store/phone1.png" mode=""></image>{{item.phone}}
  50. </view>
  51. <view class="flex addressBox ">
  52. <!-- <image class="iconA margin-r-10" src="../../static/icon/shopAddress.png" mode="heightFix">
  53. </image> -->
  54. <text class="clamp day-time">
  55. 营业时间:{{item.day_time | showTime}}
  56. </text>
  57. </view>
  58. <view class="opt">
  59. <view class="opt-item" @click.stop="toCall(item.phone + '')">
  60. <image src="../../static/store/call.png" mode=""></image>
  61. <view class="" style="color: #909399;">
  62. 电话
  63. </view>
  64. </view>
  65. <view class="opt-item" @click.stop="goWhere(item)">
  66. <image src="../../static/store/dh.png" mode=""></image>
  67. <view class="" style="color: #909399;">
  68. 导航
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <uni-load-more :status="loadingType"></uni-load-more>
  76. </scroll-view>
  77. </view>
  78. </template>
  79. <script>
  80. // #ifdef H5
  81. import weixinObj from "@/plugin/jweixin-module/index.js";
  82. // #endif
  83. import {
  84. storeList,
  85. } from '@/api/order.js';
  86. import {
  87. mapMutations,
  88. mapState
  89. } from 'vuex';
  90. export default {
  91. computed: {
  92. ...mapState('user', ['address'])
  93. },
  94. data() {
  95. return {
  96. select: 0,
  97. search: '', //查询内容
  98. loadingType: 'more',
  99. orderList: [],
  100. page: 1, //当前页数
  101. limit: 10, //每次信息条数
  102. province: '请选择', //省
  103. city: '请选择', //市
  104. district: '请选择', //区
  105. loaded: false,
  106. type: 0 //默认为切换商店,1为不切换
  107. };
  108. },
  109. onLoad: function(option) {
  110. console.log(option.type);
  111. if (option.type) {
  112. this.type = option.type;
  113. }
  114. if (option.select) {
  115. this.select = option.select;
  116. }
  117. // #ifdef H5
  118. if(this.address.latitude == '0') {
  119. this.getAddress()
  120. this.storeList();
  121. }else {
  122. this.storeList();
  123. }
  124. // #endif
  125. },
  126. filters: {
  127. showTime(val) {
  128. let str = ''
  129. if(val) {
  130. let arr = val.split(' - ')
  131. let arr1 = arr[0].split(':')
  132. let arr2 = arr[1].split(':')
  133. str = arr1[0] + ':' + arr1[1] + ' - ' + arr2[0] + ':' + arr2[1]
  134. }
  135. return str
  136. }
  137. },
  138. methods: {
  139. ...mapMutations('user', ['setAddress','setStore']),
  140. toCall(phone) {
  141. uni.makePhoneCall({
  142. phoneNumber:phone
  143. })
  144. },
  145. goWhere(item) {
  146. let latitude = item.latitude;
  147. let longitude = item.longitude;
  148. let address = item.name;
  149. // #ifdef H5
  150. window.open(`http://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};title:${address}`)
  151. // #endif
  152. },
  153. getAddress() {
  154. let that = this
  155. try{
  156. weixinObj.ready(() => {
  157. console.log('加载完毕注册事件');
  158. weixinObj.getLocation({
  159. type: 'gcj02',
  160. success: function(res) {
  161. that.setAddress({
  162. latitude: res.latitude,
  163. longitude: res.longitude
  164. })
  165. that.storeList();
  166. },
  167. fail(e) {
  168. console.log('失败', e);
  169. }
  170. });
  171. });
  172. }catch(e){
  173. that.storeList();
  174. }
  175. },
  176. toJSON() {
  177. return this;
  178. },
  179. backIndex() {
  180. uni.switchTab({
  181. url: '/pages/index/index'
  182. })
  183. },
  184. // 查询方法
  185. searchData() {
  186. // 初始化数据重新搜索
  187. this.loaded = false;
  188. this.page = 1;
  189. this.orderList = [];
  190. this.loadingType = 'more';
  191. this.storeList()
  192. },
  193. // 存储当前的门店
  194. onChecked(item) {
  195. let that = this
  196. if(that.type == 0) {
  197. let prepage = that.$api.prePage();
  198. prepage.checkedPoint = item
  199. that.setStore(item)
  200. uni.navigateBack()
  201. }else {
  202. that.setStore(item)
  203. }
  204. },
  205. storeList(source) {
  206. //这里是将订单挂载到tab列表下
  207. let navItem = this;
  208. if (source === 'tabChange' && navItem.loaded === true) {
  209. //tab切换只有第一次需要加载数据
  210. return;
  211. }
  212. if (navItem.loadingType === 'loading') {
  213. //防止重复加载
  214. return;
  215. }
  216. if (navItem.loadingType === 'noMore') {
  217. //防止重复加载
  218. return;
  219. }
  220. // 修改当前对象状态为加载中
  221. navItem.loadingType = 'loading';
  222. let city = `${this.province},${this.city},${this.district}`;
  223. if (this.province == '请选择') {
  224. city = '';
  225. }
  226. storeList({
  227. city,
  228. page: navItem.page,
  229. limit: navItem.limit,
  230. key: this.search,
  231. latitude: this.address.latitude,
  232. longitude: this.address.longitude,
  233. })
  234. .then(({
  235. data
  236. }) => {
  237. let arr = data.list.map(e => {
  238. return e;
  239. });
  240. navItem.orderList = navItem.orderList.concat(arr);
  241. // console.log(navItem.orderList);
  242. navItem.page++;
  243. if (navItem.limit == arr.length) {
  244. //判断是否还有数据, 有改为 more, 没有改为noMore
  245. navItem.loadingType = 'more';
  246. return;
  247. } else {
  248. //判断是否还有数据, 有改为 more, 没有改为noMore
  249. navItem.loadingType = 'noMore';
  250. }
  251. uni.hideLoading();
  252. this.$set(navItem, 'loaded', true);
  253. console.log(this, '结果');
  254. })
  255. .catch(e => {
  256. console.log(e);
  257. });
  258. },
  259. // 内容改变事件
  260. onCityClick(item) {
  261. const arr = item.data;
  262. this.province = arr[0];
  263. this.city = arr[1];
  264. this.district = arr[2];
  265. // 开始查询
  266. console.log(this.province, this.city, this.district);
  267. console.log(arr);
  268. this.searchData()
  269. }
  270. },
  271. };
  272. </script>
  273. <style lang="scss">
  274. page,
  275. .container {
  276. height: 100%;
  277. }
  278. /* #ifdef APP */
  279. .container {
  280. padding-top: var(--status-bar-height);
  281. }
  282. /* #endif */
  283. .list-scroll-content {
  284. height: calc(100% - 44px);
  285. position: relative;
  286. overflow: hidden;
  287. z-index: 100;
  288. }
  289. .itemList {
  290. padding: 30rpx 0;
  291. .item {
  292. background-color: #FFFFFF;
  293. margin-bottom: 30rpx;
  294. padding: 20rpx;
  295. border-radius: 20rpx;
  296. position: relative;
  297. .day-time {
  298. background-color: #fef4eb;
  299. color: #fe7019;
  300. padding: 5rpx 10rpx;
  301. margin-top: 15rpx;
  302. }
  303. .opt {
  304. display: flex;
  305. width: 120rpx;
  306. justify-content: space-between;
  307. position: absolute;
  308. bottom: 20rpx;
  309. right: 20rpx;
  310. .opt-item {
  311. font-size: $font-sm;
  312. color: $font-color-light;
  313. }
  314. image {
  315. width: 45rpx;
  316. height: 45rpx;
  317. }
  318. }
  319. .list,
  320. .km {
  321. color: $font-color-light;
  322. font-size: $font-sm;
  323. }
  324. .list {
  325. padding-top: 10rpx;
  326. image {
  327. width: 28rpx;
  328. height: 28rpx;
  329. vertical-align: bottom;
  330. margin-right: 10rpx;
  331. }
  332. }
  333. .logo {
  334. height: 180rpx;
  335. width: 180rpx;
  336. border-radius: 20rpx;
  337. }
  338. .title {
  339. font-size: 36rpx;
  340. color: $font-color-dark;
  341. }
  342. .iconR {
  343. height: 24rpx;
  344. }
  345. .iconA {
  346. width: 24rpx;
  347. height: 24rpx;
  348. }
  349. .addressBox {
  350. font-size: 24rpx;
  351. color: $font-color-light;
  352. justify-content: flex-start;
  353. }
  354. }
  355. }
  356. .address {
  357. background-color: #FFFFFF;
  358. justify-content: space-around;
  359. height: 40px;
  360. .text {
  361. font-size: 22rpx;
  362. color: $font-color-dark;
  363. margin-right: 5px;
  364. }
  365. .tipButtom {
  366. width: 11px;
  367. }
  368. }
  369. .topNav {
  370. height: 44px;
  371. background-color: #FFFFFF;
  372. padding: 0 15px;
  373. /* #ifdef MP */
  374. height: calc(44px + var(--status-bar-height));
  375. padding-top: calc(var(--status-bar-height) - 15px);
  376. /* #endif */
  377. .back {
  378. width: 13px;
  379. }
  380. .inputbox {
  381. background-color: $page-color-base;
  382. height: 15px;
  383. flex-grow: 1;
  384. margin-left: 15px;
  385. border-radius: 50px;
  386. height: 30px;
  387. padding-left: 20px;
  388. /* #ifdef MP */
  389. margin-right: 200rpx;
  390. /* #endif */
  391. font-size: $font-base;
  392. .search {
  393. width: 18px;
  394. }
  395. .input {
  396. height: 100%;
  397. width: 100%;
  398. text-align: left;
  399. padding-left: 10px;
  400. }
  401. }
  402. }
  403. </style>