敢为人鲜小程序前端代码仓库
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.

352 lines
7.4 KiB

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