index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class="container store-page">
  3. <div class="store-toolbar">
  4. <div class="toolbar">
  5. <div class="item item1" >
  6. <van-search
  7. value="{{ value }}"
  8. placeholder="请输入搜索关键词"
  9. show-action
  10. shape="round"
  11. focus
  12. @change="onChange"
  13. @cancel="onCancel"
  14. />
  15. </div>
  16. </div>
  17. </div>
  18. <scroll-view scroll-y class="store-content">
  19. <v-card style="height:auto" :thumb="item.icon" v-for="(item, index) in storeList" :key="item.id">
  20. <div class="store-info">
  21. <div class="title txt-clip">{{item.name}}</div>
  22. <div class="content">
  23. <div class="left">
  24. <div class="desc">
  25. <van-rate :value="item.star" size="10" color="#f44" allow-half void-color="#eee" void-icon="star" />
  26. <span class="rate-num">{{item.star}}</span>
  27. </div>
  28. <div class="phone">
  29. <van-icon name="phone" class="phone-icon" />
  30. <div @click="callPhone(item.managerMobile)"> {{item.managerMobile}} </div>
  31. </div>
  32. </div>
  33. <div class="right" v-if="item.distance" @click="openLocation(item)">
  34. <div class="navigation">
  35. <van-icon name="location" />
  36. 导航
  37. </div>
  38. <div>
  39. 距您{{item.distance}}KM
  40. </div>
  41. </div>
  42. </div>
  43. <div>
  44. <div class="">
  45. {{item.addrProvinceName + item.addrCityName + item.addrDistrictName}}
  46. </div>
  47. <div class="tags">
  48. <div class="tag" v-for="(tag, index2) in item.storeBizList" :key="tag.id">{{tag.bizTypeName}}</div>
  49. </div>
  50. </div>
  51. </div>
  52. </v-card>
  53. <no-data :options="list"/>
  54. </scroll-view>
  55. </div>
  56. </template>
  57. <script>
  58. import { getListStore } from '@/api/store.js'
  59. import NoData from '@/components/NoData';
  60. import storage from '@/utils/storage.js'
  61. export default {
  62. name: 'storeSearch',
  63. components: { 'no-data': NoData },
  64. data() {
  65. return {
  66. storeList: [],
  67. isSearched: false,
  68. searchVal: '',
  69. isfocus: true,
  70. pageNo: 1,
  71. pageSize: 10,
  72. isLastPage: false,
  73. areaCode: '',
  74. currentPosition: {
  75. lat: '',
  76. lng: ''
  77. },
  78. };
  79. },
  80. computed: {
  81. },
  82. methods: {
  83. onChange (e) {
  84. this.isSearched = false
  85. this.isLastPage = false
  86. this.searchVal = e.mp.detail
  87. this.pageNo = 1
  88. this.storeList = []
  89. this.getStoreList()
  90. console.log(e, "e.detail")
  91. console.log(this.searchVal, "this.searchVal")
  92. },
  93. onCancel () {
  94. wx.navigateBack({
  95. delta: 1
  96. })
  97. },
  98. callPhone(phone) {
  99. wx.makePhoneCall({
  100. phoneNumber: phone
  101. });
  102. },
  103. getStarNum(level) {
  104. const star = (5 - 0.5 * (level - 1)).toString();
  105. return star.indexOf('.') > -1 ? star : star + '.0';
  106. },
  107. openLocation(item) {
  108. wx.openLocation({
  109. latitude: item.lat - 0,
  110. longitude: item.lng - 0,
  111. name: item.name,
  112. address: item.addrProvinceName + item.addrCityName + item.addrDistrictName + item.addrDetail
  113. });
  114. },
  115. // 格式化数据
  116. formatList(list) {
  117. const _this = this;
  118. if (list.length) {
  119. list.forEach(item => {
  120. item.distance = item.distance ? (item.distance/1000).toFixed(2) : '';
  121. item.star = this.getStarNum(item.level);
  122. });
  123. return list;
  124. } else {
  125. return [];
  126. }
  127. return [];
  128. },
  129. getStoreList() {
  130. const val = this.searchVal
  131. if(val==''||val.length==0){
  132. return false
  133. }
  134. const _this = this;
  135. wx.showLoading({
  136. mask: true,
  137. title: '加载中'
  138. });
  139. let params={
  140. name: val,
  141. enableFlag: 1,
  142. pageNo: this.pageNo,
  143. pageSize: this.pageSize,
  144. lat: this.currentPosition.lat,
  145. lng: this.currentPosition.lng
  146. }
  147. if (this.areaCode.length == 4){ // 查询市的门店
  148. params.addrCity = this.areaCode
  149. } else { // 查询区的门店
  150. params.addrDistrict = this.areaCode
  151. }
  152. if (!params.lat && !params.lng){
  153. delete params.lat
  154. delete params.lng
  155. }
  156. getListStore(params).then(res => {
  157. if (res.status === '200') {
  158. _this.isSearched = true
  159. if (res.data.list && res.data.list.length) {
  160. if(this.pageNo>1){
  161. _this.storeList = _this.storeList.concat(_this.formatList(res.data.list))
  162. }else{
  163. _this.storeList = _this.formatList(res.data.list)
  164. }
  165. let len = _this.storeList.length
  166. console.log(len)
  167. console.log(res.data.count)
  168. if(len>=res.data.count){
  169. if(this.pageNo>1){
  170. wx.showToast({
  171. title: '已经是最后一页'
  172. })
  173. }
  174. _this.isLastPage = true
  175. }else{
  176. _this.isLastPage = false
  177. }
  178. } else {
  179. _this.storeList = []
  180. }
  181. } else {
  182. wx.showToast({
  183. title: res.message,
  184. icon: 'none',
  185. duration: 2500
  186. });
  187. }
  188. setTimeout(function(){
  189. wx.hideLoading();
  190. },500)
  191. })
  192. },
  193. },
  194. // 监听用户上拉触底事件
  195. onReachBottom() {
  196. if(!this.isLastPage){
  197. this.pageNo = this.pageNo + 1
  198. this.getStoreList()
  199. }
  200. },
  201. onShow() {
  202. this.searchVal = '';
  203. this.isfocus = true
  204. this.isSearched = false
  205. this.isLastPage = false
  206. },
  207. onLoad(options) {
  208. console.log(options)
  209. this.currentPosition.lat = options.lat
  210. this.currentPosition.lng = options.lng
  211. this.areaCode = options.areaCode
  212. }
  213. };
  214. </script>
  215. <style lang="stylus">
  216. ._v-card .v-card{
  217. border-bottom: 1px solid #eee;
  218. height:auto;
  219. }
  220. .vcard .van-card__img{
  221. border-radius:5px;
  222. }
  223. .container {
  224. height: 100%;
  225. overflow: hidden;
  226. box-sizing: border-box;
  227. padding-top: 70rpx;
  228. }
  229. .store-content {
  230. height: 100%;
  231. box-sizing: border-box;
  232. margin-top :10px;
  233. }
  234. .store-toolbar {
  235. position: fixed;
  236. top: 0;
  237. width: 100%;
  238. box-sizing: border-box;
  239. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  240. background-color: #fff;
  241. z-index: 9;
  242. .toolbar {
  243. display: flex;
  244. justify-content: space-around;
  245. height: 70rpx;
  246. .item {
  247. width: 100%;
  248. }
  249. .item1 {
  250. text-align: right;
  251. }
  252. }
  253. .toolbar-detail {
  254. background-color: #fff;
  255. position: absolute;
  256. top: 73rpx;
  257. left: 0;
  258. right: 0;
  259. opacity: 0;
  260. &.show {
  261. opacity: 1;
  262. }
  263. }
  264. }
  265. .icon {
  266. position: relative;
  267. top: 4rpx;
  268. }
  269. .store-info {
  270. box-sizing: border-box;
  271. font-size: 25rpx;
  272. height: 100%;
  273. flex: 1;
  274. display: flex;
  275. flex-direction: column;
  276. justify-content: space-between;
  277. .content {
  278. display: flex;
  279. flex: 1;
  280. .left {
  281. flex: 1;
  282. }
  283. .navigation {
  284. font-size: 1em;
  285. text-align: right;
  286. }
  287. }
  288. .title {
  289. font-size: 1em;
  290. padding: 10rpx 0;
  291. font-weight:bold;
  292. }
  293. .desc {
  294. color: #80848f;
  295. display: flex;
  296. }
  297. .rate-num {
  298. padding: 0 15rpx;
  299. }
  300. .phone {
  301. display: flex;
  302. align-items: center;
  303. padding: 12rpx 0;
  304. color:#57a3f3;
  305. }
  306. .tags {
  307. margin-top: 5rpx;
  308. display: flex;
  309. font-size: 0.8em;
  310. .tag {
  311. color: #808695;
  312. border: 1rpx solid rgba(255, 0, 0, 0.3);
  313. padding: 5rpx 10rpx;
  314. }
  315. .tag + .tag {
  316. margin-left: 10rpx;
  317. }
  318. }
  319. }
  320. .checkbox-group {
  321. padding: 5px 20px 5px 40px;
  322. display: flex;
  323. flex-wrap: wrap;
  324. justify-content: space-between;
  325. }
  326. .checkbox-item {
  327. width: 40vw;
  328. padding: 15rpx 0;
  329. }
  330. .toolbar-detail-control {
  331. display: flex;
  332. .btn {
  333. flex: 1;
  334. }
  335. }
  336. </style>