shop.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view class="content">
  3. <u-navbar title=" " height="44px" :bgColor="bgColor" :placeholder="true">
  4. <view class="navbar_left hflex acenter" @click="changeCity" slot="left">
  5. <view class="city">{{city}}</view>
  6. <u-icon name="arrow-down-fill" color="#000" size="10"></u-icon>
  7. </view>
  8. </u-navbar>
  9. <view class="search" @click="search">
  10. <u-input v-model="serach_value" type="text" :border="true" placeholder="热搜榜单" shape="circle"
  11. prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" disabled bgColor="#fff">
  12. <template slot="suffix">
  13. <view @click.stop="search">搜索</view>
  14. </template>
  15. </u-input>
  16. </view>
  17. <view class="swiper">
  18. <u-swiper :indicator="true" indicatorActiveColor="#506dff" height="160" :list="bannerList" keyName="img" radius="20rpx" @click="toBanner"></u-swiper>
  19. </view>
  20. <view class="grid">
  21. <u-grid :border="false" @click="clickBase" col="4">
  22. <u-grid-item v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">
  23. <image :src="baseListItem.cover" mode="aspectFill" class="grid_icon"></image>
  24. <text class="grid_text text_hide">{{baseListItem.name}}</text>
  25. </u-grid-item>
  26. </u-grid>
  27. </view>
  28. <view class="list hflex acenter fwrap">
  29. <block v-for="(item,index) in pageList" :key="index">
  30. <view class="list_item" @click="toDetail(item.id)">
  31. <image :src="item.cover[0]" mode="aspectFill" class="item_img"></image>
  32. <view style="box-sizing: border-box;padding: 12rpx 10rpx 0;">
  33. <view class="item_name text_hide">{{item.name}}</view>
  34. <!-- <view class="hflex acenter " style="padding-top: 12rpx;" v-if="item.items.length !== 0">
  35. <view class="item_type">{{item.items[0].goods_spec}}</view>
  36. <view class="item_type">{{item.parts}}</view>
  37. </view>
  38. <view class="hflex acenter " style="padding-top: 12rpx;" v-else>
  39. <view class="item_type"></view>
  40. <view class="item_type">{{item.parts}}</view>
  41. </view> -->
  42. <view class="item_price">¥{{item.price_selling}}</view>
  43. </view>
  44. </view>
  45. </block>
  46. </view>
  47. <view class="suspension">
  48. <view @click="toCart" class="img_box">
  49. <u-badge numberType="overflow" max="99" :value="cart_num"></u-badge>
  50. <image src="https://ship-expert.zhousi.hdlkeji.com/common/cart.png" class="susp_icon"></image>
  51. </view>
  52. <view @click="toCenter">
  53. <image src="https://ship-expert.zhousi.hdlkeji.com/common/center.png" class="susp_icon"></image>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import $api from '@/static/js/api.js'
  60. var that = ''
  61. export default {
  62. data() {
  63. return {
  64. cart_num: 0,
  65. bgColor: 'rgb(255,255,255,0)',
  66. city: '北京市',
  67. serach_value: '',
  68. bannerList: [
  69. ],
  70. baseList: [],
  71. pageList: [
  72. ],
  73. page: 1,
  74. limit: 10,
  75. total: 1,
  76. }
  77. },
  78. onLoad() {
  79. that = this
  80. var city = uni.getStorageSync('city')
  81. var token = uni.getStorageSync("token")
  82. if(city) {
  83. that.city = city
  84. }
  85. if(token) {
  86. that.getNum()
  87. } else {
  88. $api.info("去登录")
  89. setTimeout(()=> {
  90. $api.jump('/pages/login/code_login')
  91. },1000)
  92. }
  93. that.getBanner()
  94. },
  95. onShow() {
  96. that.page = 1
  97. that.pageList = []
  98. that.getCate()
  99. that.getList()
  100. },
  101. onPullDownRefresh() {
  102. that.page = 1
  103. that.pageList = []
  104. that.getCate()
  105. that.getList()
  106. var token = uni.getStorageSync("token")
  107. if(token) {
  108. that.getNum()
  109. }
  110. },
  111. onPageScroll(e) {
  112. if(e.scrollTop != 0) {
  113. that.bgColor = "#fff"
  114. } else {
  115. that.bgColor = 'rgba(255,255,255,0)'
  116. }
  117. },
  118. methods: {
  119. // 获取分类数据
  120. getCate() {
  121. $api.req({
  122. url: '/data/api.Goods/getCate'
  123. }, function(res) {
  124. if(res.code == 1) {
  125. console.log('分类接口',res);
  126. that.baseList = res.data
  127. }
  128. })
  129. },
  130. getList() {
  131. $api.req({
  132. url: '/data/api.Goods/getGoods',
  133. data: {
  134. page: that.page
  135. }
  136. }, function(res) {
  137. if(res.code == 1) {
  138. if(that.page == 1) {
  139. that.pageList = res.data.list
  140. } else {
  141. that.pageList = that.pageList.concat(res.data.list)
  142. }
  143. for(var i=0;i<that.pageList.length;i++) {
  144. if(typeof(that.pageList[i].cover) == 'string') {
  145. that.pageList[i].cover = that.pageList[i].cover.split('|')
  146. }
  147. }
  148. that.total = res.data.page.total
  149. that.limit = res.data.page.limit
  150. } else if(res.code == 401) {
  151. $api.info("去登录")
  152. setTimeout(()=> {
  153. $api.jump('/pages/login/code_login')
  154. },1000)
  155. }
  156. uni.stopPullDownRefresh();
  157. })
  158. },
  159. getNum() {
  160. $api.req({
  161. url: '/data/api.Goods/cart_number'
  162. }, function(res) {
  163. if(res.code == 1) {
  164. that.cart_num = res.data
  165. }
  166. })
  167. },
  168. getBanner() {
  169. $api.req({
  170. url: '/data/api.Data/getSlider',
  171. data: {
  172. keys: 'mall_banner '
  173. }
  174. }, function(res) {
  175. if(res.code == 1) {
  176. that.bannerList = res.data
  177. }
  178. })
  179. },
  180. // banner图跳转
  181. toBanner(e) {
  182. var url = that.bannerList[e].url
  183. if(url == '#') {
  184. return
  185. }
  186. $api.jump('/pages/user/web_view?src=' +url)
  187. },
  188. // 点击base
  189. clickBase(e) {
  190. if(!that.baseList[e].sub) {
  191. var url = '/page_shop/pages/base/base?name='+ that.baseList[e].name + '&id=' + that.baseList[e].id
  192. } else {
  193. var url = '/page_shop/pages/base/base?name='+ that.baseList[e].name + '&id=' + that.baseList[e].id + '&data=' + JSON.stringify(that.baseList[e].sub)
  194. }
  195. $api.jump(url)
  196. },
  197. // 商品详情
  198. toDetail(id) {
  199. $api.jump('/page_shop/pages/good/detail?id=' + id)
  200. },
  201. // 去购物车
  202. toCart() {
  203. $api.jump('/page_shop/pages/mine/cart')
  204. },
  205. // 去个人中心
  206. toCenter() {
  207. $api.jump('/page_shop/pages/mine/mine')
  208. },
  209. search() {
  210. $api.jump('/page_shop/pages/mine/search?value=' + that.serach_value)
  211. },
  212. onReachBottom() {
  213. if (Number(that.page) * Number(that.limit) >= Number(that.total)) {
  214. $api.info("没有更多了")
  215. } else {
  216. that.page++
  217. that.getList()
  218. }
  219. }
  220. },
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .content::v-deep {
  225. background: url('https://ship-expert.zhousi.hdlkeji.com/common/shop_bg.png') #F5F5F5 no-repeat;
  226. background-size: 100%;
  227. padding: 0 30rpx;
  228. position: relative;
  229. .navbar_left {
  230. .city {
  231. color: #222222;
  232. font-size: 32rpx;
  233. margin-right: 16rpx;
  234. }
  235. }
  236. .search {
  237. // background: #fff;
  238. width: 100%;
  239. height: 88rpx;
  240. box-sizing: border-box;
  241. padding: 12rpx 0;
  242. .u-input {
  243. background-color: #fff;
  244. height: 64rpx;
  245. padding: 0 0 0 18rpx !important;
  246. border: 1rpx solid #506Dff;
  247. margin-bottom: 12rpx;
  248. }
  249. .u-input__content__subfix-icon {
  250. width: 128rpx;
  251. height: 64rpx;
  252. background-color: #506Dff;
  253. border-radius: 32rpx;
  254. color: #fff;
  255. font-size: 28rpx;
  256. text-align: center;
  257. line-height: 64rpx;
  258. }
  259. }
  260. .swiper {
  261. width: 100%;
  262. margin-top: 20rpx;
  263. height: 320rpx;
  264. }
  265. .grid {
  266. margin-top: 20rpx;
  267. background: #FFFFFF;
  268. border-radius: 10px;
  269. width: 100%;
  270. box-sizing: border-box;
  271. padding: 14rpx 0;
  272. .u-grid-item {
  273. margin: 14rpx 0;
  274. }
  275. .grid_icon {
  276. width: 96rpx;
  277. height: 96rpx;
  278. border-radius: 12rpx;
  279. }
  280. .grid_text {
  281. max-width: 96rpx;
  282. overflow: hidden;
  283. white-space: nowrap;
  284. text-overflow: ellipsis;
  285. font-size: 24rpx;
  286. font-weight: 400;
  287. color: #222222;
  288. line-height: 34rpx;
  289. padding-top: 12rpx;
  290. text-align: center;
  291. }
  292. }
  293. .list {
  294. width: 100%;
  295. margin-top: 20rpx;
  296. .list_item {
  297. width: 334rpx;
  298. background: #FFFFFF;
  299. border-radius: 20rpx;
  300. box-sizing: border-box;
  301. padding: 0 0 22rpx;
  302. margin: 0 22rpx 20rpx 0;
  303. .item_img {
  304. width: 334rpx;
  305. height: 280rpx;
  306. border-radius: 20rpx 20rpx 0px 0px;
  307. }
  308. .item_name {
  309. width: 100%;
  310. /* text-overflow: ellipsis;
  311. overflow: hidden;
  312. display: -webkit-box;
  313. -webkit-box-orient: vertical;
  314. box-orient: vertical;
  315. line-clamp: 2;
  316. -webkit-line-clamp: 2; */
  317. font-size: 28rpx;
  318. font-weight: 400;
  319. color: #222222;
  320. line-height: 40rpx;
  321. }
  322. .item_type {
  323. width: max-content;
  324. overflow: hidden;
  325. white-space: nowrap;
  326. text-overflow: ellipsis;
  327. height: 28rpx;
  328. background: #F5F5F5;
  329. border-radius: 4rpx;
  330. font-size: 20rpx;
  331. font-weight: 400;
  332. color: #999999;
  333. line-height: 28rpx;
  334. padding: 0 14rpx;
  335. margin-right: 12rpx;
  336. }
  337. .item_price {
  338. padding-top: 12rpx;
  339. font-size: 28rpx;
  340. font-weight: bold;
  341. color: #FF4747;
  342. line-height: 32rpx;
  343. }
  344. }
  345. .list_item:nth-child(2n+2) {
  346. margin: 0 0 20rpx;
  347. }
  348. }
  349. .suspension {
  350. position: fixed;
  351. bottom: 22rpx;
  352. right: 14rpx;
  353. .susp_icon {
  354. width: 132rpx;
  355. height: 132rpx;
  356. margin-top: 8rpx;
  357. }
  358. .img_box {
  359. position: relative;
  360. .u-badge {
  361. position: absolute;
  362. right: 16rpx;
  363. top: 18rpx;
  364. font-size: 20rpx !important;
  365. font-weight: 400;
  366. color: #FFFFFF !important;
  367. line-height: 24rpx !important;
  368. // width: 28rpx;
  369. // height: 28rpx;
  370. background: #FF4747;
  371. box-shadow: 0px 4rpx 8rpx 0px rgba(255,71,71,0.4);
  372. }
  373. }
  374. }
  375. }
  376. </style>