shop.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view class="content">
  3. <view class="" style="position: relative;">
  4. <u-navbar title=" " height="44px" :bgColor="bgColor" :placeholder="true">
  5. <view class="navbar_left hflex acenter" @click="changeCity" slot="left">
  6. <view class="city">{{city}}</view>
  7. <u-icon name="arrow-down-fill" color="#000" size="10"></u-icon>
  8. </view>
  9. </u-navbar>
  10. <view class="search" @click="search" :style="scrollHeight > 0 ? 'background: #fff' : ''">
  11. <u-input v-model="serach_value" type="text" :border="true" placeholder="热搜榜单" shape="circle"
  12. prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" bgColor="#fff">
  13. <template slot="suffix">
  14. <view @click.stop="search">搜索</view>
  15. </template>
  16. </u-input>
  17. </view>
  18. </view>
  19. <view class="swiper">
  20. <u-swiper :indicator="true" indicatorActiveColor="#506dff" height="160" :list="bannerList" keyName="img" radius="20rpx" @click="toBanner"></u-swiper>
  21. </view>
  22. <view class="grid">
  23. <u-grid :border="false" @click="clickBase" col="4">
  24. <u-grid-item v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">
  25. <image :src="baseListItem.cover" mode="aspectFill" class="grid_icon"></image>
  26. <text class="grid_text text_hide">{{baseListItem.name}}</text>
  27. </u-grid-item>
  28. </u-grid>
  29. </view>
  30. <view class="list hflex acenter fwrap">
  31. <block v-for="(item,index) in pageList" :key="index">
  32. <view class="list_item" @click="toDetail(item.id)">
  33. <image :src="item.cover[0]" mode="aspectFill" class="item_img"></image>
  34. <view style="box-sizing: border-box;padding: 12rpx 10rpx 0;">
  35. <view class="item_name text_hide">{{item.name}}</view>
  36. <!-- <view class="hflex acenter " style="padding-top: 12rpx;" v-if="item.items.length !== 0">
  37. <view class="item_type">{{item.items[0].goods_spec}}</view>
  38. <view class="item_type">{{item.parts}}</view>
  39. </view>
  40. <view class="hflex acenter " style="padding-top: 12rpx;" v-else>
  41. <view class="item_type"></view>
  42. <view class="item_type">{{item.parts}}</view>
  43. </view> -->
  44. <view class="item_price">¥{{item.price_selling}}</view>
  45. </view>
  46. </view>
  47. </block>
  48. </view>
  49. <view class="suspension">
  50. <view @click="toCart" class="img_box">
  51. <u-badge numberType="overflow" max="99" :value="cart_num"></u-badge>
  52. <image src="https://ship.shipcc.cn/common/cart.png" class="susp_icon"></image>
  53. </view>
  54. <view @click="toCenter">
  55. <image src="https://ship.shipcc.cn/common/center.png" class="susp_icon"></image>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import $api from '@/static/js/api.js'
  62. var that = ''
  63. export default {
  64. data() {
  65. return {
  66. cart_num: 0,
  67. bgColor: 'rgb(255,255,255,0)',
  68. city: '北京市',
  69. serach_value: '',
  70. bannerList: [
  71. ],
  72. baseList: [],
  73. pageList: [
  74. ],
  75. page: 1,
  76. limit: 10,
  77. total: 1,
  78. token: '',
  79. scrollHeight: 0
  80. }
  81. },
  82. onLoad() {
  83. that = this
  84. var city = uni.getStorageSync('city')
  85. if(city) {
  86. that.city = city
  87. }
  88. that.getBanner()
  89. },
  90. onShow() {
  91. that.token = uni.getStorageSync("token")
  92. if(that.token) {
  93. that.getNum()
  94. }
  95. that.page = 1
  96. that.pageList = []
  97. that.getCate()
  98. that.getList()
  99. },
  100. onPullDownRefresh() {
  101. that.page = 1
  102. that.pageList = []
  103. that.getCate()
  104. that.getList()
  105. var token = uni.getStorageSync("token")
  106. if(token) {
  107. that.getNum()
  108. }
  109. },
  110. onPageScroll(e) {
  111. that.scrollHeight = e.scrollTop
  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/password_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.token) {
  191. $api.jump('/pages/login/password_login')
  192. } else {
  193. if(!that.baseList[e].sub) {
  194. var url = '/page_shop/pages/base/base?name='+ that.baseList[e].name + '&id=' + that.baseList[e].id
  195. } else {
  196. var url = '/page_shop/pages/base/base?name='+ that.baseList[e].name + '&id=' + that.baseList[e].id + '&data=' + JSON.stringify(that.baseList[e].sub)
  197. }
  198. $api.jump(url)
  199. }
  200. },
  201. // 商品详情
  202. toDetail(id) {
  203. if(!that.token) {
  204. $api.jump('/pages/login/password_login')
  205. } else {
  206. $api.jump('/page_shop/pages/good/detail?id=' + id)
  207. }
  208. },
  209. // 去购物车
  210. toCart() {
  211. console.log(that.token);
  212. if(!that.token) {
  213. $api.jump('/pages/login/password_login')
  214. } else {
  215. $api.jump('/page_shop/pages/mine/cart')
  216. }
  217. },
  218. // 去个人中心
  219. toCenter() {
  220. if(!that.token) {
  221. $api.jump('/pages/login/password_login')
  222. } else {
  223. $api.jump('/page_shop/pages/mine/mine')
  224. }
  225. },
  226. search() {
  227. $api.jump('/page_shop/pages/mine/search?value=' + that.serach_value)
  228. },
  229. onReachBottom() {
  230. if (Number(that.page) * Number(that.limit) >= Number(that.total)) {
  231. $api.info("没有更多了")
  232. } else {
  233. that.page++
  234. that.getList()
  235. }
  236. }
  237. },
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .content::v-deep {
  242. background: url('https://ship.shipcc.cn/common/shop_bg.png') #F5F5F5 no-repeat;
  243. background-size: 100%;
  244. // padding: 0 30rpx;
  245. position: relative;
  246. .navbar_left {
  247. .city {
  248. color: #222222;
  249. font-size: 32rpx;
  250. margin-right: 16rpx;
  251. }
  252. }
  253. .search {
  254. position: fixed;
  255. z-index: 999;
  256. // background: #fff;
  257. width: 100%;
  258. height: 88rpx;
  259. box-sizing: border-box;
  260. padding: 0 42rpx 0;
  261. .u-input {
  262. background-color: #fff;
  263. height: 64rpx;
  264. padding: 0 0 0 18rpx !important;
  265. border: 1rpx solid #506Dff;
  266. margin-bottom: 12rpx;
  267. }
  268. .u-input__content__subfix-icon {
  269. width: 128rpx;
  270. height: 64rpx;
  271. background-color: #506Dff;
  272. border-radius: 32rpx;
  273. color: #fff;
  274. font-size: 28rpx;
  275. text-align: center;
  276. line-height: 64rpx;
  277. }
  278. }
  279. .swiper {
  280. width: 100%;
  281. margin-top: 108rpx;
  282. height: 320rpx;
  283. padding: 0 30rpx;
  284. box-sizing: border-box;
  285. }
  286. .grid {
  287. margin: 20rpx auto 0;
  288. background: #FFFFFF;
  289. border-radius: 10px;
  290. width: 690rpx;
  291. box-sizing: border-box;
  292. padding: 14rpx 0;
  293. .u-grid-item {
  294. margin: 14rpx 0;
  295. }
  296. .grid_icon {
  297. width: 96rpx;
  298. height: 96rpx;
  299. border-radius: 12rpx;
  300. }
  301. .grid_text {
  302. max-width: 96rpx;
  303. overflow: hidden;
  304. white-space: nowrap;
  305. text-overflow: ellipsis;
  306. font-size: 24rpx;
  307. font-weight: 400;
  308. color: #222222;
  309. line-height: 34rpx;
  310. padding-top: 12rpx;
  311. text-align: center;
  312. }
  313. }
  314. .list {
  315. width: 690rpx;
  316. margin: 20rpx auto;
  317. .list_item {
  318. width: 334rpx;
  319. background: #FFFFFF;
  320. border-radius: 20rpx;
  321. box-sizing: border-box;
  322. padding: 0 0 22rpx;
  323. margin: 0 22rpx 20rpx 0;
  324. .item_img {
  325. width: 334rpx;
  326. height: 280rpx;
  327. border-radius: 20rpx 20rpx 0px 0px;
  328. }
  329. .item_name {
  330. width: 100%;
  331. /* text-overflow: ellipsis;
  332. overflow: hidden;
  333. display: -webkit-box;
  334. -webkit-box-orient: vertical;
  335. box-orient: vertical;
  336. line-clamp: 2;
  337. -webkit-line-clamp: 2; */
  338. font-size: 28rpx;
  339. font-weight: 400;
  340. color: #222222;
  341. line-height: 40rpx;
  342. }
  343. .item_type {
  344. width: max-content;
  345. overflow: hidden;
  346. white-space: nowrap;
  347. text-overflow: ellipsis;
  348. height: 28rpx;
  349. background: #F5F5F5;
  350. border-radius: 4rpx;
  351. font-size: 20rpx;
  352. font-weight: 400;
  353. color: #999999;
  354. line-height: 28rpx;
  355. padding: 0 14rpx;
  356. margin-right: 12rpx;
  357. }
  358. .item_price {
  359. padding-top: 12rpx;
  360. font-size: 28rpx;
  361. font-weight: bold;
  362. color: #FF4747;
  363. line-height: 32rpx;
  364. }
  365. }
  366. .list_item:nth-child(2n+2) {
  367. margin: 0 0 20rpx;
  368. }
  369. }
  370. .suspension {
  371. position: fixed;
  372. bottom: 22rpx;
  373. right: 14rpx;
  374. .susp_icon {
  375. width: 132rpx;
  376. height: 132rpx;
  377. margin-top: 8rpx;
  378. }
  379. .img_box {
  380. position: relative;
  381. .u-badge {
  382. position: absolute;
  383. right: 16rpx;
  384. top: 18rpx;
  385. font-size: 20rpx !important;
  386. font-weight: 400;
  387. color: #FFFFFF !important;
  388. line-height: 24rpx !important;
  389. // width: 28rpx;
  390. // height: 28rpx;
  391. background: #FF4747;
  392. box-shadow: 0px 4rpx 8rpx 0px rgba(255,71,71,0.4);
  393. }
  394. }
  395. }
  396. }
  397. </style>