敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
7.3 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
3 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
3 months ago
3 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
4 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
4 months ago
3 months ago
5 months ago
  1. <template>
  2. <view class="item" @click="$emit('click')">
  3. <!-- 商品图片 -->
  4. <view class="item-image">
  5. <!-- <image :src="item.image &&
  6. item.image.split(',')[0]" mode="aspectFill">
  7. </image> -->
  8. <image :src="item.image" mode="aspectFill" class="item-image-img" />
  9. </view>
  10. <!-- 商品信息 -->
  11. <view class="info">
  12. <!-- 商品标题 -->
  13. <view class="title">
  14. {{ item.title }}
  15. </view>
  16. <!-- 价格 -->
  17. <!-- <view class="price">
  18. <view class="money">
  19. <text>{{ getPriceByRole(item) }}</text>
  20. <text class="unit">/元每件</text>
  21. </view>
  22. <view class="price-imgs">
  23. <image v-if="userInfo.role == 1" :src="configList.vip_money_one" mode="aspectFill" class="price-img">
  24. </image>
  25. <image v-if="userInfo.role == 2" :src="configList.vip_money_two" mode="aspectFill" class="price-img">
  26. </image>
  27. <image v-if="userInfo.role == 3" :src="configList.vip_money_three" mode="aspectFill"
  28. class="price-img"></image>
  29. </view>
  30. </view> -->
  31. <!-- 价格区 -->
  32. <!-- <view class="price-section">
  33. <view class="price">
  34. <view class="money">
  35. <text>{{ item.price }}</text>
  36. <text class="unit">/元每件</text>
  37. </view>
  38. <view class="oldPrice">
  39. <text>{{ item.oldPrice }}</text>
  40. <text class="unit">/</text>
  41. </view>
  42. </view>
  43. <view class="oldPrice">
  44. <view class="money">
  45. <text>{{ item.oldPrice }}</text>
  46. <text class="unit">/元每件</text>
  47. </view>
  48. <view class="price-imgs">
  49. </view>
  50. </view>
  51. <view class="member-price">
  52. <view class="price">
  53. <view class="money">
  54. <text>{{ item.silverPrice }}</text>
  55. <text class="unit">/元每件</text>
  56. </view>
  57. <view class="price-imgs">
  58. <image :src="configList.vip_money_one" mode="aspectFill" class="price-img">
  59. </image>
  60. </view>
  61. </view>
  62. <view class="price">
  63. <view class="money">
  64. <text>{{ item.goldPrice }}</text>
  65. <text class="unit">/元每件</text>
  66. </view>
  67. <view class="price-imgs">
  68. <image :src="configList.vip_money_two" mode="aspectFill"
  69. class="price-img"></image>
  70. </view>
  71. </view>
  72. <view class="price">
  73. <view class="money">
  74. <text>{{ item.diamondPrice }}</text>
  75. <text class="unit">/元每件</text>
  76. </view>
  77. <view class="price-imgs">
  78. <image :src="configList.vip_money_three" mode="aspectFill" class="price-img">
  79. </image>
  80. </view>
  81. </view>
  82. </view>
  83. </view> -->
  84. <!-- 销量 -->
  85. <view class="sales-volume">
  86. <view class="sales-volume-imgbox">
  87. <image src="@/static/image/category/sales-volume-icon.png" mode="widthFix" class="sales-volume-img">
  88. </image>
  89. </view>
  90. <view class="sales-volume-number">
  91. 已售出{{ item.sales }}
  92. </view>
  93. </view>
  94. <!-- 价格 -->
  95. <view :style="{ color: '#FF2A2A'}">
  96. <text style="font-size: 18rpx;"></text><text style="font-size: 30rpx;">{{ item.price }}</text>
  97. </view>
  98. <!-- 购买按钮 -->
  99. <view class="" style="display: flex;justify-content: space-between;">
  100. <view @click.stop="purchase" class="buy-btn buy-order">
  101. 立即下单
  102. </view>
  103. <view @click.stop="addCart(item)" class="buy-btn">
  104. <!-- <uv-badge type="error" max="9" :value="getProductCount(item.id)" absolute :offset="[-10, 1]" bg-color="#FF2A2A" /> -->
  105. 加购物车
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. import {
  113. mapState,
  114. mapGetters,
  115. mapMutations
  116. } from 'vuex'
  117. export default {
  118. props: {
  119. item: {
  120. default: {}
  121. }
  122. },
  123. computed: {
  124. ...mapState(['userInfo']),
  125. ...mapGetters( 'cartNum' , ['getProductCount'] )
  126. },
  127. data() {
  128. },
  129. methods: {
  130. ...mapMutations( 'cartNum' , ['incrementProduct'] ),
  131. // 购买商品(创建订单)
  132. purchase() {
  133. this.$emit('purchase')
  134. },
  135. // 加入购物车
  136. addCart(item){
  137. this.incrementProduct({ productId: item.id })
  138. uni.showLoading({
  139. title: '加载中...'
  140. })
  141. this.$api('addShopcar', {
  142. goodsId : item.id,
  143. num : 1,
  144. }, res => {
  145. uni.hideLoading()
  146. if(res.code == 200){
  147. uni.showToast({
  148. title: '加入购物车成功',
  149. icon: 'none',
  150. duration: 1000
  151. })
  152. }
  153. })
  154. },
  155. //根据角色获取对应价格
  156. getPriceByRole(item) {
  157. let priceFiledList = ['goldPrice','silverPrice','diamondPrice']
  158. let price = item[priceFiledList[this.userInfo.role - 1]]
  159. return price >= 0 ? price : item.price
  160. }
  161. },
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .item {
  166. width: 92%;
  167. margin: 20rpx auto;
  168. padding: 20rpx 10rpx;
  169. align-items: center;
  170. display: flex;
  171. box-sizing: border-box;
  172. border-bottom: 1rpx solid #00000012;
  173. background: white;
  174. border-radius: 10rpx;
  175. // margin-bottom: 20rpx;
  176. // box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
  177. // 商品图片
  178. .item-image {
  179. width: 200rpx;
  180. height: 200rpx;
  181. overflow: hidden;
  182. image {
  183. height: 100%;
  184. width: 100%;
  185. }
  186. }
  187. // 商品信息
  188. .info {
  189. // height: 220rpx;
  190. padding: 15rpx 0rpx 15rpx 15rpx;
  191. color: #555;
  192. width: calc(100% - 200rpx);
  193. box-sizing: border-box;
  194. overflow: hidden;
  195. display: flex;
  196. flex-direction: column;
  197. gap: 4rpx;
  198. // 商品标题
  199. .title {
  200. font-size: 30rpx;
  201. font-weight: bold;
  202. overflow: hidden; //超出的文本隐藏
  203. text-overflow: ellipsis; //溢出用省略号显示
  204. white-space: nowrap; //溢出不换行
  205. color: #333;
  206. margin-bottom: 5rpx;
  207. }
  208. .price-section {
  209. display: flex;
  210. flex-direction: column;
  211. gap: 6rpx;
  212. }
  213. // 价格
  214. .price {
  215. display: flex;
  216. align-items: center;
  217. color: #f40;
  218. font-size: 24rpx;
  219. align-items: flex-end;
  220. .money {
  221. font-size: 30rpx;
  222. font-weight: 600;
  223. .unit {
  224. font-size: 18rpx;
  225. font-weight: normal;
  226. margin-left: 2rpx;
  227. }
  228. }
  229. .price-imgs {
  230. display: flex;
  231. flex-wrap: wrap;
  232. align-items: center;
  233. .price-img {
  234. width: 70rpx;
  235. height: 26rpx;
  236. margin-left: 8rpx;
  237. }
  238. }
  239. }
  240. .oldPrice{
  241. color: #999;
  242. font-size: 20rpx;
  243. text-decoration: line-through;
  244. margin-left: 8rpx;
  245. }
  246. .member-price {
  247. display: flex;
  248. flex-direction: column;
  249. gap: 4rpx;
  250. margin-top: 4rpx;
  251. padding-top: 6rpx;
  252. border-top: 1rpx dashed #eee;
  253. .money {
  254. font-size: 26rpx;
  255. .unit {
  256. font-size: 18rpx;
  257. }
  258. }
  259. .price-imgs {
  260. display: flex;
  261. flex-wrap: wrap;
  262. .price-img {
  263. width: 70rpx;
  264. height: 26rpx;
  265. margin-left: 8rpx;
  266. }
  267. }
  268. }
  269. // 销量
  270. .sales-volume {
  271. display: flex;
  272. align-items: center;
  273. flex-wrap: wrap;
  274. margin-top: 2rpx;
  275. .sales-volume-imgbox {
  276. width: 18rpx;
  277. .sales-volume-img {
  278. width: 100%;
  279. }
  280. }
  281. .sales-volume-number {
  282. color: #999;
  283. font-size: 24rpx;
  284. padding-left: 8rpx;
  285. }
  286. }
  287. // 购买按钮
  288. .buy-btn {
  289. background: $uni-color;
  290. color: white;
  291. display: inline-block;
  292. padding: 10rpx 24rpx;
  293. border-radius: 10rpx;
  294. width: fit-content;
  295. font-size: 23rpx;
  296. font-weight: 500;
  297. box-shadow: 0 2rpx 6rpx rgba(255,68,0,0.2);
  298. transition: all 0.3s;
  299. margin-top: 4rpx;
  300. position: relative;
  301. }
  302. .buy-order{
  303. background: inherit;
  304. border: 3rpx solid $uni-color;
  305. color: $uni-color;
  306. }
  307. }
  308. }
  309. </style>