business-district.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="business-district-container">
  3. <!-- 头部导航 -->
  4. <PageHead></PageHead>
  5. <!-- 菜单 -->
  6. <NavBar @view="handleToDetail"></NavBar>
  7. <!-- 福利 -->
  8. <WelfareBar></WelfareBar>
  9. <!-- bar -->
  10. <AdvertisementBar></AdvertisementBar>
  11. <!-- package -->
  12. <ActivityPackage></ActivityPackage>
  13. <!-- 商家列表 -->
  14. <view>
  15. <!-- <view style="padding-top: 20upx;">
  16. <tui-waterfall :list-data="$data._list" :type="2" :page-size="queryParam.pageSize">
  17. <template #left="{ entity }">
  18. <view style="width: 338upx;">
  19. <BrandShop :brand-info="entity"></BrandShop>
  20. </view>
  21. </template>
  22. <template #right="{ entity }">
  23. <view style="width: 338upx;">
  24. <BrandShop :brand-info="entity"></BrandShop>
  25. </view>
  26. </template>
  27. </tui-waterfall>
  28. </view> -->
  29. <view>
  30. <CommonShop
  31. v-for="shop in $data._list" :key="shop.shop_id" :shop-info="shop" margin="22upx 0"
  32. radius="20upx"
  33. pic-width="222upx" pic-height="222upx" show-sign
  34. ></CommonShop>
  35. </view>
  36. <view style="padding-bottom: 45upx;">
  37. <LoadingMore
  38. :status="!$data._isEmpty && !$data._list.length
  39. ? 'loading' : !$data._isEmpty && $data._list.length && ($data._list.length >= $data._listTotal) ? 'no-more' : ''"
  40. >
  41. </LoadingMore>
  42. <tui-no-data v-if="$data._isEmpty" :fixed="false" style="margin-top: 60upx;">暂无数据</tui-no-data>
  43. </view>
  44. </view>
  45. <tui-toast ref="toast"></tui-toast>
  46. </view>
  47. </template>
  48. <script>
  49. import { mapGetters } from 'vuex'
  50. import loadData from '../../mixin/loadData'
  51. import PageHead from './components/PageHead.vue'
  52. import NavBar from './components/NavBar.vue'
  53. import WelfareBar from './components/WelfareBar.vue'
  54. import AdvertisementBar from './components/AdvertisementBar.vue'
  55. import ActivityPackage from './components/ActivityPackage.vue'
  56. // import BrandShop from './components/BrandShop.vue'
  57. import CommonShop from './components/CommonShop.vue'
  58. import { getHomeBrandListApi } from '../../api/anotherTFInterface'
  59. import { getAdressDetailByLngLat } from '../../utils'
  60. export default {
  61. name: 'BusinessDistrict',
  62. components: {
  63. PageHead,
  64. NavBar,
  65. WelfareBar,
  66. AdvertisementBar,
  67. ActivityPackage,
  68. // BrandShop,
  69. CommonShop
  70. },
  71. data() {
  72. return {
  73. isPositioning: true,
  74. queryParam: {
  75. search: '',
  76. classifyId: ''
  77. }
  78. }
  79. },
  80. mixins: [
  81. loadData({
  82. api: getHomeBrandListApi,
  83. mapKey: {
  84. list: 'list',
  85. listTotal: 'total',
  86. pageSize: 'pageSize'
  87. },
  88. callingcb: true,
  89. dataFn(data) {
  90. const ignoreBrandList = [ 'xxx' ]
  91. return data.filter((item) => !ignoreBrandList.includes(item.name))
  92. }
  93. })
  94. ],
  95. async onShow() {
  96. // if (this.$data._list.length && (this.$data._list.length <= this.queryParam.pageSize)) { // 针对初次渲染完成前切换到其它页面导致瀑布流只有单列的问题
  97. // const currentAddress = await getCurrentLocation()
  98. // const res = await getHomeBrandListApi({ pageNo: 1, pageSize: this.queryParam.pageNo * this.queryParam.pageSize, address: currentAddress + '' })
  99. // if (res.statusCode === 20000) {
  100. // if (res.data) {
  101. // this.$data._list = res.data.data
  102. // }
  103. // }
  104. // }
  105. },
  106. onLoad() {
  107. this.getBrandList()
  108. uni.$on('sendStoreDetailMsg', (data) => {
  109. if (data.data.meaning === 'refreshCurrentData') {
  110. if (!this.isPositioning) {
  111. // uni.showLoading()
  112. getHomeBrandListApi({
  113. page: 1,
  114. pageSize: this.$data._query.page * this.$data._query.pageSize,
  115. ...this.queryParam,
  116. areaId: this.$store.state.location.locationInfo.adcode,
  117. longitude: this.$store.state.location.locationInfo.streetNumber.location.split(',')[0],
  118. latitude: this.$store.state.location.locationInfo.streetNumber.location.split(',')[1]
  119. })
  120. .then(({ data }) => {
  121. console.log(data)
  122. this.$data._list = data.list || []
  123. // uni.hideLoading()
  124. })
  125. .catch(() => {
  126. // uni.hideLoading()
  127. })
  128. }
  129. }
  130. })
  131. uni.$on('sendChooseAddressSuccessMsg', (data) => {
  132. this.getBrandList()
  133. })
  134. },
  135. computed: {
  136. ...mapGetters([ 'obtainLocationCount' ])
  137. },
  138. watch: {
  139. obtainLocationCount(val, oldVal) {
  140. const pages = getCurrentPages()
  141. if (pages[pages.length - 1].route === 'pages/business-district/business-district') this.getBrandList()
  142. }
  143. },
  144. methods: {
  145. getBrandList() {
  146. if (!this.$store.getters.obtainLocationCount) {
  147. const tempTime = Date.now()
  148. const queryLocation = { longitude: '', latitude: '' }
  149. uni.getLocation({
  150. type: 'gcj02',
  151. highAccuracyExpireTime: 1000,
  152. success: (result) => {
  153. queryLocation.longitude = result.longitude
  154. queryLocation.latitude = result.latitude
  155. console.log(result)
  156. getAdressDetailByLngLat(queryLocation.latitude, queryLocation.longitude)
  157. .then((res) => {
  158. if (res.status === '1') {
  159. this.$data._query = { ...this.$data._query, ...this.queryParam, ...queryLocation, areaId: typeof res.regeocode.addressComponent.adcode === 'object' ? '' : res.regeocode.addressComponent.adcode }
  160. if ((Date.now() - tempTime) >= 1000) {
  161. this._loadData(null, () => this.isPositioning = true)
  162. } else {
  163. this._loadData(null, () => this.isPositioning = false)
  164. }
  165. } else {
  166. this.$showToast('查询失败')
  167. }
  168. })
  169. .catch(() => {
  170. this.$showToast('查询失败')
  171. })
  172. },
  173. fail: () => {
  174. this.$data._query = {
  175. ...this.$data._query,
  176. ...this.queryParam,
  177. areaId: this.$store.state.location.locationInfo.adcode,
  178. longitude: this.$store.state.location.locationInfo.streetNumber.location.split(',')[0],
  179. latitude: this.$store.state.location.locationInfo.streetNumber.location.split(',')[1]
  180. }
  181. this._loadData()
  182. }
  183. })
  184. } else {
  185. this.$data._query = {
  186. ...this.$data._query,
  187. ...this.queryParam,
  188. areaId: this.$store.state.location.locationInfo.adcode,
  189. longitude: this.$store.state.location.locationInfo.streetNumber.location.split(',')[0],
  190. latitude: this.$store.state.location.locationInfo.streetNumber.location.split(',')[1]
  191. // areaId: 440606,
  192. // longitude: 113.293719,
  193. // latitude: 22.803751
  194. }
  195. this._loadData(null, () => this.isPositioning = false)
  196. }
  197. },
  198. // 点击常看详情
  199. handleToDetail(item) {
  200. const { type } = item
  201. if (!type) return this.empty() // 特殊图标或图标名称对应不上就跳不了页面
  202. uni.navigateTo({ url: `/another-tf/another-user/shop/shop-enter?type=${item.type}&id=${item.id}` })
  203. }
  204. },
  205. onPullDownRefresh() {
  206. this.$data._query.page = 1
  207. this.$data._list = []
  208. this.$data._listTotal = 0
  209. this.$data._isEmpty = false
  210. this._loadData()
  211. uni.stopPullDownRefresh()
  212. }
  213. }
  214. </script>
  215. <style lang="less" scoped>
  216. .business-district-container {
  217. min-height: 100vh;
  218. background-color: #f6f6f6;
  219. padding: 40upx 26upx 140upx;
  220. box-sizing: border-box;
  221. }
  222. </style>