index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="index">
  3. <!-- section -->
  4. <view class="section">
  5. <view v-for="(item, index) in typeList" :key="index" class="item padding bg-white ">
  6. <view class="flex">
  7. <view style="width: 20upx;background-color: #4d6bab;" class="margin-right-xs"></view>
  8. <view style="flex: auto; background-image: linear-gradient(120deg,#4d6bab 0%, #fff 80%);" class="padding-tb-sm text-white bg-white padding-left-sm">
  9. {{ item.name }}
  10. <!-- <view @click="commodityFunc(item.id)" class="text-grey" style="float: right;">
  11. 查看更多<text class="cuIcon-right"></text>
  12. </view> -->
  13. </view>
  14. </view>
  15. <view class="content padding-tb flex flex-wrap align-center">
  16. <view
  17. @click="handler(it.id)"
  18. v-for="(it, ind) in item.commodity_list"
  19. :key="ind"
  20. class="content-item margin-bottom"
  21. style="width: calc(100vw / 3 - 40upx);border-radius: 20upx;overflow: hidden;"
  22. >
  23. <image
  24. style="width: calc(100vw / 3 - 40upx);height: calc(100vw / 3 - 40upx);"
  25. lazy-load="true"
  26. :src="it.show_image_url | lazyImage"
  27. mode="aspectFit"
  28. ></image>
  29. <view class="padding-xs">
  30. <view class="name text-black">{{ it.name }}</view>
  31. <view class="text-gray">销量:{{ it.sale_count }}</view>
  32. <view class="flex justify-between ">
  33. <view>
  34. <view v-if="it.type == 1" class="text-red text-price"><cu-price :value="it.price" size="32" /></view>
  35. <view v-else class="text-yellow">{{ it.point_price }}积分</view>
  36. <view class="bg-orange light text-xs padding-lr-xs">
  37. <text class="cuIcon-vip lg"></text>
  38. <text class="text-price margin-left-xs">{{ it.vip_price }}</text>
  39. </view>
  40. </view>
  41. <text @click.stop="handlerItem(it)" class="cuIcon-cart text-xl"></text>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- footer -->
  49. <cu-bar active="0" />
  50. <!-- 工具 -->
  51. <cu-goodA :value="value" @addcart="addcart" @buyclicked="buyclicked" :number="number" @changeNum="val => (number = val)" :show.sync="show" />
  52. </view>
  53. </template>
  54. <script>
  55. import { mapState } from 'vuex';
  56. import api from './api.js';
  57. export default {
  58. data() {
  59. return {
  60. typeList: [],
  61. value:{},
  62. number:1,
  63. show:false
  64. };
  65. },
  66. computed: {
  67. ...mapState(['customer_id','bind'])
  68. },
  69. async onLoad(options) {
  70. let { referrer } = options;
  71. if (referrer) uni.setStorageSync('referrer', referrer);
  72. var result = await api.index();
  73. if (result.code != 0) return false;
  74. if (result.data.length == 0) return false;
  75. result.data = result.data.filter(item => {
  76. return item['commodity_list'] && item['commodity_list'].length > 0;
  77. });
  78. this.typeList = result.data;
  79. },
  80. methods: {
  81. handler(id) {
  82. uni.navigateTo({
  83. url: `/pages/detail/index?id=${id}`
  84. });
  85. },
  86. commodityFunc(id){
  87. uni.switchTab({
  88. url:`/pages/commodity/index`
  89. })
  90. },
  91. // 添加购物车
  92. async addcart(){
  93. var result= await api.shoppingCart({quantity:this.number,commodity_details:this.value.id});
  94. if (result.code == 0) {
  95. this.show = false;
  96. uni.showToast({
  97. title: '添加成功',
  98. icon: 'success'
  99. });
  100. }
  101. },
  102. handlerItem(item){
  103. if (this.bind != 1) return false;
  104. item=JSON.parse(JSON.stringify(item));
  105. item['img']=item.show_image_url;
  106. delete item['show_image_url'];
  107. this.value = item;
  108. this.number=1;
  109. this.show = true;
  110. },
  111. async buyclicked(){
  112. let arr=[{...this.value,count:this.number}];
  113. this.show=false;
  114. uni.navigateTo({
  115. url:`/indexPages/pay/index?list=${JSON.stringify(arr)}`
  116. })
  117. },
  118. },
  119. onShareAppMessage() {
  120. return {
  121. title: '首页',
  122. path: '/pages/index/index?referrer=' + this.customer_id
  123. };
  124. },
  125. onShareTimeline() {
  126. return {
  127. title: '首页',
  128. query: 'referrer=' + this.customer_id
  129. };
  130. }
  131. };
  132. </script>
  133. <style lang="scss" scoped>
  134. .index {
  135. .section {
  136. .item {
  137. .content {
  138. .content-item {
  139. margin-right: 30upx;
  140. image {
  141. vertical-align: top;
  142. }
  143. .name {
  144. text-align: justify;
  145. display: -webkit-box;
  146. overflow: hidden;
  147. text-overflow: ellipsis;
  148. -webkit-line-clamp: 2;
  149. -webkit-box-orient: vertical;
  150. }
  151. }
  152. .content-item:nth-child(3n) {
  153. margin-right: 0;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. </style>