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

342 lines
7.2 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
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
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
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
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
5 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
5 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
5 months ago
3 months ago
5 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
5 months ago
3 months ago
5 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 }}+ | 库存{{ item.num }}
  90. </view>
  91. </view>
  92. <!-- 购买按钮 -->
  93. <view class=""
  94. style="display: flex;justify-content: space-between;">
  95. <view @click.stop="item.num > 0 ? purchase(item.id) : ''"
  96. class="buy-btn"
  97. :class="{'disabled-btn': item.num <= 0}">
  98. {{ item.num > 0 ? '购买' : '库存不足' }}
  99. </view>
  100. <view v-if="item.num > 0" @click.stop="item.num > 0 ? addCart(item) : ''"
  101. class="buy-btn"
  102. :class="{'disabled-btn': item.num <= 0}">
  103. {{ item.num > 0 ? '加入购物车' : '库存不足' }}
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. import {
  111. mapState
  112. } from 'vuex'
  113. export default {
  114. props: {
  115. item: {
  116. default: {}
  117. }
  118. },
  119. computed: {
  120. ...mapState(['userInfo'])
  121. },
  122. data() {
  123. return {
  124. }
  125. },
  126. methods: {
  127. // 购买商品(创建订单)
  128. purchase(id) {
  129. this.$api('getRiceProductDetail', {
  130. id
  131. }, res => {
  132. if (res.code == 200) {
  133. res.result.num = 1
  134. this.$store.commit('setPayOrderProduct', [
  135. res.result
  136. ])
  137. this.$utils.navigateTo('/pages_order/order/createOrder')
  138. }
  139. })
  140. },
  141. // 加入购物车
  142. addCart(item){
  143. this.$api('addCart', {
  144. shopId : item.id,
  145. num : 1,
  146. }, res => {
  147. if(res.code == 200){
  148. uni.showToast({
  149. title: '加入购物车成功',
  150. icon: 'none'
  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: 100%;
  167. padding: 15rpx 20rpx;
  168. align-items: center;
  169. display: flex;
  170. box-sizing: border-box;
  171. border-bottom: 1rpx solid #00000012;
  172. background: white;
  173. border-radius: 20rpx;
  174. margin-bottom: 20rpx;
  175. box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
  176. // 商品图片
  177. .item-image {
  178. width: 220rpx;
  179. height: 220rpx;
  180. border-radius: 12rpx;
  181. overflow: hidden;
  182. image {
  183. height: 100%;
  184. width: 100%;
  185. }
  186. }
  187. // 商品信息
  188. .info {
  189. padding: 15rpx 0rpx 15rpx 25rpx;
  190. color: #555;
  191. width: calc(100% - 220rpx);
  192. box-sizing: border-box;
  193. overflow: hidden;
  194. display: flex;
  195. flex-direction: column;
  196. gap: 10rpx;
  197. // 商品标题
  198. .title {
  199. font-size: 30rpx;
  200. font-weight: bold;
  201. overflow: hidden; //超出的文本隐藏
  202. text-overflow: ellipsis; //溢出用省略号显示
  203. white-space: nowrap; //溢出不换行
  204. color: #333;
  205. margin-bottom: 5rpx;
  206. }
  207. .price-section {
  208. display: flex;
  209. flex-direction: column;
  210. gap: 6rpx;
  211. }
  212. // 价格
  213. .price {
  214. display: flex;
  215. align-items: center;
  216. color: #f40;
  217. font-size: 24rpx;
  218. align-items: flex-end;
  219. .money {
  220. font-size: 30rpx;
  221. font-weight: 600;
  222. .unit {
  223. font-size: 18rpx;
  224. font-weight: normal;
  225. margin-left: 2rpx;
  226. }
  227. }
  228. .price-imgs {
  229. display: flex;
  230. flex-wrap: wrap;
  231. align-items: center;
  232. .price-img {
  233. width: 70rpx;
  234. height: 26rpx;
  235. margin-left: 8rpx;
  236. }
  237. }
  238. }
  239. .oldPrice{
  240. color: #999;
  241. font-size: 20rpx;
  242. text-decoration: line-through;
  243. margin-left: 8rpx;
  244. }
  245. .member-price {
  246. display: flex;
  247. flex-direction: column;
  248. gap: 4rpx;
  249. margin-top: 4rpx;
  250. padding-top: 6rpx;
  251. border-top: 1rpx dashed #eee;
  252. .money {
  253. font-size: 26rpx;
  254. .unit {
  255. font-size: 18rpx;
  256. }
  257. }
  258. .price-imgs {
  259. display: flex;
  260. flex-wrap: wrap;
  261. .price-img {
  262. width: 70rpx;
  263. height: 26rpx;
  264. margin-left: 8rpx;
  265. }
  266. }
  267. }
  268. // 销量
  269. .sales-volume {
  270. display: flex;
  271. align-items: center;
  272. flex-wrap: wrap;
  273. margin-top: 2rpx;
  274. .sales-volume-imgbox {
  275. width: 18rpx;
  276. .sales-volume-img {
  277. width: 100%;
  278. }
  279. }
  280. .sales-volume-number {
  281. color: #B8B8B8;
  282. font-size: 24rpx;
  283. padding-left: 8rpx;
  284. }
  285. }
  286. // 购买按钮
  287. .buy-btn {
  288. background: $uni-color;
  289. color: white;
  290. display: inline-block;
  291. padding: 8rpx 18rpx;
  292. border-radius: 10rpx;
  293. width: fit-content;
  294. font-size: 26rpx;
  295. font-weight: 500;
  296. box-shadow: 0 2rpx 6rpx rgba(255,68,0,0.2);
  297. transition: all 0.3s;
  298. margin-top: 4rpx;
  299. }
  300. // 禁用按钮样式
  301. .disabled-btn {
  302. background: #cccccc;
  303. color: #ffffff;
  304. box-shadow: none;
  305. cursor: not-allowed;
  306. }
  307. }
  308. }
  309. </style>