shopIndex.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <view class="content">
  3. <view class="shopBg">
  4. <image class="shopBgImg" src="../../static/image/shopBg.png" mode="widthFix"></image>
  5. <view class="mask">
  6. </view>
  7. </view>
  8. <view class="shopIndex">
  9. <view class="shopName">
  10. {{shopDetail.name}}
  11. </view>
  12. <view class="shopitem flex" @click="shopLi">
  13. <image class="iconShop" src="../../static/icon/shopPhone.png" mode="widthFix"></image>
  14. <text>
  15. {{shopDetail.phone}}
  16. </text>
  17. </view>
  18. <view class="shopitem flex" @click="openAddress">
  19. <image class="iconShop" src="../../static/icon/shopAddress.png" mode="widthFix"></image>
  20. <text>
  21. {{shopDetail.address+shopDetail.detailed_address}}
  22. </text>
  23. </view>
  24. <image class="shopLogo" :src="shopDetail.image" mode="widthFix"></image>
  25. </view>
  26. <view class="tab flex">
  27. <view class="tabItem" v-for="(item,index) in tagArray" :class="{action:tabCurrentIndex==index}"
  28. @click="tabGoods(index)">
  29. {{item.text}}
  30. <view v-if='tabCurrentIndex==index' class="iconAction">
  31. </view>
  32. </view>
  33. </view>
  34. <view class="listItem">
  35. <view class="item flex" v-for="(item,index) in tagArray[tabCurrentIndex].orderList" @click="navTo('/pages/product/product?id='+item.id+'&shopId='+shopId)">
  36. <view class="imgBox">
  37. <image class="imgBox" :src="item.image" mode="scaleToFill"></image>
  38. </view>
  39. <view class="contentDetail">
  40. <view class="cartName clamp2">
  41. {{item.store_name}}
  42. </view>
  43. <view class="tip clamp2" >
  44. {{item.store_info}}
  45. </view>
  46. <view class="moneyBox flex">
  47. <view class="money">
  48. <text class="font-size-base">¥</text>
  49. <text>{{item.price}}</text>
  50. </view>
  51. <view class="numPp">
  52. {{item.sales|getNum}}+付款
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <uni-load-more :status="tagArray[tabCurrentIndex].loadingType"></uni-load-more>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. loadIndexs,
  64. } from '@/api/index.js';
  65. import {
  66. getProducts
  67. } from '@/api/product.js';
  68. export default {
  69. data() {
  70. return {
  71. shopId: '',
  72. shopDetail: {
  73. name: '',
  74. phone: '',
  75. address: '',
  76. detailed_address: ''
  77. },
  78. tabCurrentIndex: 0, //当前选中的对象
  79. tagArray: [{
  80. state: 2,
  81. text: '国标',
  82. loadingType: 'more',
  83. orderList: [],
  84. page: 1, //当前页数
  85. limit: 10 //每次信息条数
  86. },
  87. {
  88. state: 5,
  89. text: '电摩',
  90. loadingType: 'more',
  91. orderList: [],
  92. page: 1, //当前页数
  93. limit: 10 //每次信息条数
  94. },{
  95. state: 6,
  96. text: '电轻摩',
  97. loadingType: 'more',
  98. orderList: [],
  99. page: 1, //当前页数
  100. limit: 10 //每次信息条数
  101. }
  102. ],
  103. }
  104. },
  105. filters: {
  106. getNum(num) {
  107. // 转为字符串
  108. num += '';
  109. let nu = num.slice(0, 1);
  110. for (let i = 0; i < num.length - 1; i++) {
  111. nu += 0
  112. }
  113. return nu
  114. }
  115. },
  116. onLoad(opeion) {
  117. if (opeion) {
  118. this.shopId = opeion.id
  119. }
  120. // 判断是否有选中的对象
  121. if(opeion.type){
  122. this.tabCurrentIndex = (+opeion.type)-1
  123. }
  124. this.loadIndexs();
  125. this.loadData();
  126. },
  127. methods: {
  128. navTo(url) {
  129. uni.navigateTo({
  130. url: url
  131. })
  132. },
  133. // 联系商家
  134. shopLi() {
  135. uni.makePhoneCall({
  136. phoneNumber: this.shopDetail.phone //仅为示例
  137. });
  138. },
  139. // 打开地址
  140. openAddress() {
  141. uni.openLocation({
  142. latitude: +this.shopDetail.latitude,
  143. longitude: +this.shopDetail.longitude,
  144. complete(e) {
  145. console.log(e);
  146. }
  147. })
  148. },
  149. // 加载商店数据
  150. loadIndexs() {
  151. loadIndexs({
  152. store_id: this.shopId
  153. }).then((e) => {
  154. this.shopDetail = e.data.store;
  155. }).catch((e) => {
  156. console.log(e);
  157. })
  158. },
  159. // 切换
  160. tabGoods(index) {
  161. this.tabCurrentIndex = index;
  162. this.loadData('tabChange');
  163. },
  164. // 加载商品数据
  165. loadData(source) {
  166. //这里是将订单挂载到tab列表下
  167. let index = this.tabCurrentIndex;
  168. let navItem = this.tagArray[index];
  169. let state = navItem.state;
  170. if (source === 'tabChange' && navItem.loaded === true) {
  171. //tab切换只有第一次需要加载数据
  172. return;
  173. }
  174. if (navItem.loadingType === 'loading') {
  175. //防止重复加载
  176. return;
  177. }
  178. if (navItem.loadingType === 'noMore') {
  179. //防止重复加载
  180. return;
  181. }
  182. // 修改当前对象状态为加载中
  183. navItem.loadingType = 'loading';
  184. let requestData = {
  185. page: navItem.page,
  186. limit: navItem.limit,
  187. store_id: this.shopId,
  188. is_car: 1,
  189. sid:navItem.state
  190. }
  191. // // 热门
  192. // if (index == 0) {
  193. // requestData.salesOrder = 1
  194. // }
  195. // // 新品
  196. // if (index == 1) {
  197. // requestData.news = 1
  198. // }
  199. getProducts(requestData)
  200. .then(({
  201. data
  202. }) => {
  203. let arr = data.map(e => {
  204. return e;
  205. });
  206. navItem.orderList = navItem.orderList.concat(arr);
  207. // console.log(navItem.orderList);
  208. navItem.page++;
  209. if (navItem.limit == data.length) {
  210. //判断是否还有数据, 有改为 more, 没有改为noMore
  211. navItem.loadingType = 'more';
  212. return;
  213. } else {
  214. //判断是否还有数据, 有改为 more, 没有改为noMore
  215. navItem.loadingType = 'noMore';
  216. }
  217. uni.hideLoading();
  218. this.$set(navItem, 'loaded', true);
  219. })
  220. .catch(e => {
  221. console.log(e);
  222. });
  223. },
  224. }
  225. }
  226. </script>
  227. <style lang="scss">
  228. page,
  229. .content {
  230. height: 100%;
  231. }
  232. .shopBg {
  233. position: relative;
  234. overflow: hidden;
  235. height: 300rpx;
  236. .mask {
  237. position: absolute;
  238. top: 0;
  239. bottom: 0;
  240. left: 0;
  241. right: 0;
  242. background-color: rgba($color: #000000, $alpha: 0.15);
  243. }
  244. }
  245. .shopBg {
  246. .shopBgImg {
  247. width: 750rpx;
  248. }
  249. }
  250. .tab {
  251. padding: 0 50rpx;
  252. height: 100rpx;
  253. justify-content: flex-start;
  254. color: $page-color-base;
  255. .tabItem {
  256. position: relative;
  257. font-size: 28rpx;
  258. margin-right: 90rpx;
  259. color: $font-color-light;
  260. &.action {
  261. font-weight: bold;
  262. color: $font-color-dark;
  263. }
  264. .iconAction {
  265. width: 100%;
  266. position: absolute;
  267. bottom: -15rpx;
  268. left: 0rpx;
  269. height: 3px;
  270. background-color: $color-green;
  271. }
  272. }
  273. }
  274. .shopIndex {
  275. padding: 50rpx;
  276. position: relative;
  277. border-top-right-radius: 50rpx;
  278. border-top-left-radius: 50rpx;
  279. background-color: #FFFFFF;
  280. margin-top: -50RPX;
  281. .shopitem {
  282. justify-content: flex-start;
  283. font-size: 22rpx;
  284. color: $font-color-light;
  285. margin-top: 20rpx;
  286. }
  287. .shopName {
  288. font-size: 36rpx;
  289. font-weight: bold;
  290. color: $font-color-dark;
  291. }
  292. .shopLogo {
  293. position: absolute;
  294. top: -30rpx;
  295. right: 70rpx;
  296. border-radius: 20rpx;
  297. width: 160rpx;
  298. height: 160rpx;
  299. }
  300. .iconShop {
  301. width: 20rpx;
  302. margin-right: 10rpx;
  303. }
  304. }
  305. .listItem {
  306. padding: $page-row-spacing;
  307. padding-top: 0;
  308. background-color: #FFFFFF;
  309. .item {
  310. height: 240rpx;
  311. border-bottom: 1px solid $page-color-light;
  312. .imgBox {
  313. border: 1px solid $page-color-light;
  314. width: 200rpx;
  315. height: 200rpx;
  316. border-radius: 20rpx;
  317. }
  318. }
  319. .contentDetail {
  320. padding-left: 20rpx;
  321. height: 200rpx;
  322. position: relative;
  323. flex-grow: 1;
  324. .tip {
  325. font-size: 24rpx;
  326. color: $font-color-light;
  327. }
  328. .cartName {
  329. font-size: $font-base;
  330. color: $font-color-dark;
  331. }
  332. .moneyBox {
  333. position: absolute;
  334. bottom: 5rpx;
  335. left: 20rpx;
  336. right: 0;
  337. .money {
  338. color: $color-green;
  339. font-size: 44rpx;
  340. }
  341. .numPp {
  342. color: $font-color-light;
  343. font-size: 24rpx;
  344. }
  345. }
  346. }
  347. }
  348. </style>