parity.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view style="background-color: #fff;">
  3. <view class="padding-lr" style="padding-bottom: 22rpx;padding-top: 24rpx;background-color: #fff;" v-if="iste">
  4. <view @click="naviageToPage('/pages/product/search')" style="height: 64rpx;border: 1px solid #C4C4CC;" class="bg-white round flex align-center">
  5. <view class="flex align-center padding-left">
  6. <text class="yticon icon-sousuo" style="margin-right: 10rpx;"></text><text class="lem-text-gray"
  7. style="font-size: 26rpx;">新鲜,搜一下就涞了</text>
  8. </view>
  9. </view>
  10. </view>
  11. <view class="flex justify-center">
  12. <scroll-view scroll-with-animation scroll-x :scroll-into-view="curentTabView"
  13. class="bg-white"
  14. style="width:90%;height: 100rpx;overflow-x: scroll;" v-if="iste">
  15. <view class="flex align-start">
  16. <view v-for="item in slist" :key="item.id"
  17. @click="sTabTap(item)" :id="'id'+item.id"
  18. :class="{actived: item.id == currentIded}"
  19. class="flex align-center justify-center margin-left-sm"
  20. style="padding: 20rpx 0; box-sizing: border-box;width: auto;flex-shrink: 0;"
  21. >
  22. <view style="font-size: 28rpx;line-height: 40rpx;"
  23. >{{item.title}}</view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. <view style="padding: 40rpx 30rpx;" >
  29. <image src="https://nontax.oss-cn-beijing.aliyuncs.com/kxmall/G2usUI.png" mode="aspectFill"
  30. style="width: 690rpx;height: 170rpx;border-radius: 12rpx;"></image>
  31. </view>
  32. <view class="" style="background-color: #fff;padding: 8px 20px 0; ">
  33. <view v-for="(item,index) in tlist" :key="index"
  34. @click="navToDetail(item.productId)"
  35. class=" padding-tb-sm padding-lr-xs flex"
  36. style="width: 100%;height: 180rpx;border-bottom: solid #E6E6E6 1rpx;">
  37. <image :src="JSON.parse(item.img)[0].url" mode="aspectFit" class="round"
  38. style="width: 144rpx;height: 144rpx;margin-right: 50rpx;"></image>
  39. <view style="padding-top: 4rpx;padding-bottom: 2rpx;flex-grow: 1;">
  40. <view class="text-black padding-bottom-xs text-cut"
  41. style="font-size: 30rpx;line-height: 42rpx;width: 300rpx;"
  42. >{{item.title}}</view>
  43. <!-- <view class="text-gray text-cut"
  44. style="font-size: 24rpx;line-height: 34rpx;width: 300rpx;"
  45. >{{item.description}}</view> -->
  46. <view class="flex justify-between" style="width: 100%;padding-top: 12rpx;">
  47. <view style="flex-grow: 1;" class="flex align-center">
  48. <view class="text-black padding-right-sm"
  49. style="font-size: 30rpx;line-height: 42rpx;"
  50. >¥{{item.price}}</view>
  51. <view class="text-black padding-right-sm"
  52. style="font-size: 30rpx;line-height: 42rpx;text-decoration:line-through;color: #8D8E99; "
  53. >¥{{item.originalPrice}}</view>
  54. </view>
  55. <uni-number-box
  56. class="number-box"
  57. :min="0"
  58. :value="item.num"
  59. :isMin="item.num===0"
  60. :index="index"
  61. @eventChange="numberChange"
  62. v-if="item.num!==0"
  63. ></uni-number-box>
  64. <image @click.stop="addCart(index)" src="/static/add.png" mode="aspectFit"
  65. style="width: 44rpx;height: 44rpx;" v-if="item.num==0"></image>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view style="position: relative;height: 100rpx;"></view>
  71. <view class="bg-white flex align-end"
  72. style="position: fixed;bottom: 0;width: 750rpx;height: 98rpx;padding-left: 38rpx;">
  73. <view @click="navCart" class="flex align-end" style="width: 346rpx;height: 98rpx;padding-bottom: 16rpx;">
  74. <view style="position: relative;">
  75. <image src="/static/tab-icon/tab3_2.png" mode="aspectFit"
  76. style="width: 56rpx;height: 52rpx;" ></image>
  77. <view v-if="cartNum+cartNums" class="badge round"
  78. >{{cartNum+cartNums}}</view>
  79. </view>
  80. <view style="font-size: 28rpx;line-height: 40rpx;color: #8D8E99;padding-left: 40rpx;">
  81. 已选{{cartNum+cartNums}}件
  82. </view>
  83. </view>
  84. <view @click="navToCart" style="font-size: 28rpx;line-height: 40rpx;width: 404rpx;height: 98rpx;"
  85. class="flex align-center justify-center bg-green ">
  86. 去购物车
  87. </view>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import uniNumberBox from '@/components/uni-number-box.vue'
  93. export default {
  94. data() {
  95. return {
  96. slist: [{
  97. id: 2,
  98. title: '平价菜场',
  99. }, {
  100. id: 3,
  101. title: '鲜肉蛋',
  102. }, {
  103. id:4,
  104. title: '新鲜水果',
  105. },
  106. {
  107. id:5,
  108. title: '活鱼河虾',
  109. }],
  110. currentIded: 32,
  111. sTitle: '',
  112. tlist:[],
  113. cartNum:0,
  114. cartNums:0,
  115. recommendType:2,
  116. enumsList:[],
  117. curentTabView:0,
  118. iste:true,
  119. banner:{
  120. imgUrl:''
  121. },
  122. total:0,
  123. pageNo:1
  124. }
  125. },
  126. components: {
  127. uniNumberBox
  128. },
  129. onLoad(option) {
  130. if(option.title!='今日特价' && option.title != '热卖推荐'){
  131. this.recommendType=option.id
  132. this.currentIded=option.id
  133. this.curentTabView='id'+option.id
  134. // this.getRecommendByStorage()
  135. this.slist = uni.getStorageSync('categoryButtomList');
  136. this.slist = this.slist.filter(item => item.url.includes("/pages/parity/parity"));
  137. this.getRecommendTypeEnums()
  138. }else if(option.title == '今日特价'){
  139. this.iste=false
  140. this.recommendType=option.id
  141. }else if(option.title == '热卖推荐'){
  142. this.iste=false
  143. this.recommendType=option.id
  144. }
  145. this.countCart()
  146. this.getRecommendByStorage('refresh')
  147. uni.setNavigationBarTitle({
  148. title: option.title
  149. });
  150. this.$api.request('get','carousel/app/getCarouselActive',{
  151. adType:10
  152. }).then(res=>{
  153. this.banner = res.data[0]
  154. })
  155. },
  156. onShow() {
  157. },
  158. onReachBottom() {
  159. if(this.tlist.length >= this.total){
  160. return
  161. }
  162. this.getRecommendByStorage()
  163. },
  164. watch:{
  165. },
  166. methods: {
  167. naviageToPage(page,title) {
  168. const that = this
  169. if(title){
  170. console.log(title,'jinlai')
  171. title?title:''
  172. uni.navigateTo({
  173. url: page
  174. })
  175. }else{
  176. console.log(title)
  177. uni.navigateTo({
  178. url: page
  179. })
  180. }
  181. // console.log(that.categoryButtomList[index].title)
  182. },
  183. getRecommendTypeEnums(){
  184. this.$api.request('get','recommend/app/getRecommendTypeEnums').then(res=>{
  185. console.log(res )
  186. this.enumsList=res.data
  187. }).catch(err=>{
  188. this.$api.msg('请求失败,请稍后再试')
  189. })
  190. },
  191. getRecommendByStorage(loadMore = ''){
  192. console.log(this.recommendType,'this.recommendType')
  193. if (loadMore == 'refresh') {
  194. this.pageNo = 1
  195. }
  196. this.$api.request('get','storage/position/getRecommendByStorage',{
  197. storageId: this.$store.state.storageId,
  198. recommendType:this.recommendType,
  199. pageNo:this.pageNo
  200. }).then(res=>{
  201. console.log(res )
  202. this.pageNo++
  203. let tempList = res.data.rows
  204. if (loadMore == 'refresh') {
  205. this.tlist = [];
  206. }
  207. this.tlist = this.tlist.concat(tempList)
  208. this.total = res.total
  209. for (let i = 0; i < this.tlist.length; i++) {
  210. this.tlist[i].num=0
  211. }
  212. }).catch(err=>{
  213. this.$api.msg('请求失败,请稍后再试')
  214. })
  215. },
  216. //统计购物车数量
  217. countCart(){
  218. this.$api.request('get','cart/app/countCart',{
  219. storageId:this.$store.state.storageId
  220. }).then(res=>{
  221. this.cartNum = res.data
  222. }).catch(err=>{
  223. this.$api.msg('请求失败,请稍后再试')
  224. })
  225. },
  226. navToDetail(id){
  227. uni.navigateTo({
  228. url:`../product/detail?id=${id}`
  229. })
  230. },
  231. navToCart(id){
  232. // console.log()
  233. uni.switchTab({
  234. url:`../cart/cart`
  235. })
  236. },
  237. cartNumFn(){
  238. let cartNum=0
  239. this.tlist.forEach((item,i)=>{
  240. cartNum+=item.num
  241. })
  242. this.cartNums=cartNum
  243. },
  244. addCart(index){
  245. this.tlist[index].num++
  246. this.cartNumFn()
  247. const that = this
  248. that.$api.request('get', 'cart/app/addCartItem', {
  249. productId: this.tlist[index].productId,
  250. num: 1,
  251. activityId:this.tlist[index].activityId,
  252. couponId:this.tlist[index].couponId
  253. }).then(res => {
  254. that.$api.msg('添加购物车成功')
  255. var cartNum = this.$store.state.cartNum+1
  256. that.$store.commit('addCart',cartNum)
  257. uni.setTabBarBadge({
  258. index:2,
  259. text:cartNum+''
  260. })
  261. })
  262. },
  263. //数量
  264. numberChange(data){
  265. const that = this
  266. // console.log(data)
  267. this.tlist[data.index].num=data.number
  268. this.cartNumFn()
  269. that.$api.request('get', 'cart/app/addCartItem', {
  270. productId: this.tlist[data.index].productId,
  271. activityId:this.tlist[data.index].activityId,
  272. couponId:this.tlist[data.index].couponId,
  273. num: 1
  274. }).then(res => {
  275. that.$api.msg('添加购物车成功')
  276. var cartNum = this.$store.state.cartNum+1
  277. that.$store.commit('addCart',cartNum)
  278. uni.setTabBarBadge({
  279. index:2,
  280. text:cartNum+''
  281. })
  282. })
  283. // this.addCart(data.index)
  284. },
  285. //二级分类点击
  286. sTabTap(item) {
  287. console.log(this.enumsList)
  288. for (let i = 0; i < this.enumsList.length; i++) {
  289. if(this.enumsList[i].title==item.title){
  290. this.recommendType=this.enumsList[i].id
  291. console.log(this.recommendType,this.enumsList[i].title)
  292. }
  293. }
  294. this.curentTabView='id'+item.id
  295. this.currentIded = item.id
  296. this.sTitle = item.title //二级分类不用显示这个东西
  297. this.getRecommendByStorage('refresh')
  298. },
  299. }
  300. }
  301. </script>
  302. <style lang='scss'>
  303. /* page,
  304. .content {
  305. background-color: #fff;
  306. } */
  307. .actived {
  308. font-size: 28rpx;
  309. color: #2AAC34;
  310. position: relative;
  311. }
  312. .badge{
  313. background-color: #FF473C;
  314. width: 32rpx;
  315. height: 32rpx;
  316. color: #fff;
  317. font-size: 22rpx;line-height: 32rpx;text-align: center;
  318. position: absolute;
  319. left: 42rpx;
  320. bottom: 32rpx;
  321. }
  322. .actived:after {
  323. display: block;
  324. content: '';
  325. width: 54rpx;
  326. height: 8rpx;
  327. background-color: #2AAC34;
  328. position: absolute;
  329. bottom: -10rpx;
  330. left: 50%;
  331. transform: translateX(-50%);
  332. border-radius: 2px;
  333. }
  334. .number-box{
  335. width: 73px;
  336. }
  337. </style>