珠宝小程序前端代码
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.

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