goodsDetail.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view class="goods-detail">
  3. <view>
  4. <!-- 商品信息 -->
  5. <view class="goods-head">
  6. <view class="goods-imgs">
  7. <view class="goods-staus" v-if="goodContent.inventoryQty == 0 || goodContent.delFlage == 0 || goodContent.state == 0"></view>
  8. <u-swiper height="325" :border-radius="15" mode="number" indicator-pos="bottomRight" :list="imageList"></u-swiper>
  9. </view>
  10. <view class="goods-name">
  11. <view>
  12. {{goodContent.name}}
  13. </view>
  14. <view>
  15. <text>{{goodContent.sellGold}}</text>
  16. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  17. </view>
  18. </view>
  19. <view class="goods-price">
  20. <view>兑换数量<text>(库存{{goodContent.inventoryQty}}件)</text></view>
  21. <view>
  22. <u-number-box :max="goodContent.inventoryQty" v-model="nums"></u-number-box>
  23. </view>
  24. </view>
  25. <view v-if="goldLimit>0" class="goods-goldLimit">
  26. 此商品需要满<text>{{goldLimit}}</text>乐豆才可购买
  27. </view>
  28. </view>
  29. <!-- 商品属性 -->
  30. <view class="goods-attr">
  31. <view>
  32. <view>运费</view>
  33. <view>免运费</view>
  34. </view>
  35. <view>
  36. <view>限购</view>
  37. <view>每人限购1件</view>
  38. </view>
  39. <view>
  40. <view>售后</view>
  41. <view>兑换商品,一经售出,不支持退换货</view>
  42. </view>
  43. </view>
  44. <!-- 商品详情 -->
  45. <view class="goods-content">
  46. <jyf-parser :html="goodContent.desc" ref="article"></jyf-parser>
  47. </view>
  48. </view>
  49. <!-- 底部浮动按钮 -->
  50. <view class="bottom-btns" v-if="goodContent&&goodContent.inventoryQty > 0&&goodContent.state==1">
  51. <view><u-button :custom-style="addCartButton" type="warning" @click="addCart">加入购物车</u-button></view>
  52. <view><u-button :custom-style="toOrderButton" type="error" @click="toOrder()">立即下单</u-button></view>
  53. </view>
  54. <!-- 购物车 -->
  55. <uni-cart-fix :closeCurPage="true" :dragPic="dragPic"></uni-cart-fix>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. getGoodsDetail
  61. } from '@/api/goods.js'
  62. import {
  63. addGoodsToCart
  64. } from '@/api/shoppingCart.js'
  65. import jyfParser from "@/components/jyf-parser/jyf-parser";
  66. export default {
  67. components: {
  68. jyfParser
  69. },
  70. data() {
  71. return {
  72. addCartButton: {
  73. background: '#ff9000',
  74. borderRadius:'100rpx 0 0 100rpx'
  75. },
  76. toOrderButton: {
  77. borderRadius:'0 100rpx 100rpx 0'
  78. },
  79. imageList:[], // 商品图片
  80. nums:1, // 商品数量
  81. id: '',
  82. goodContent: null,
  83. goldLimit: 0,
  84. dragPic: '/static/cart.png', // 购物车图标
  85. };
  86. },
  87. onLoad(opts) {
  88. console.log(opts)
  89. this.id = opts.id
  90. this.getDetail()
  91. },
  92. methods: {
  93. // 查详情
  94. getDetail(){
  95. getGoodsDetail({id:this.id}).then(res => {
  96. console.log(res)
  97. if(res.status == 200){
  98. this.goodContent = res.data
  99. this.goldLimit = res.data.goodsType.goldLimit || 0
  100. let arr=res.data.images.split(',')
  101. arr.map(item => {
  102. this.imageList.push({image:item})
  103. })
  104. }
  105. })
  106. },
  107. // 添加购物车
  108. addGoodToCart(item){
  109. uni.showLoading({
  110. mask: true,
  111. title: "正在加入购物车..."
  112. })
  113. addGoodsToCart(item).then(res => {
  114. if(res.status == 200){
  115. // 刷新购物车数量
  116. if(!item.hasCunzai){
  117. this.$store.state.vuex_cartNums = this.$store.state.vuex_cartNums + 1
  118. }
  119. setTimeout(()=>{
  120. uni.showToast({
  121. icon: 'none',
  122. title:'添加成功'
  123. })
  124. // 刷新购物车数据
  125. uni.$emit('getCartList')
  126. },50)
  127. }
  128. })
  129. },
  130. // 判断当前商品是否已存在购物车中
  131. hasCunzai(data){
  132. let list = this.$store.state.vuex_cartList
  133. let row = list.find(item=> item.goodsTypeNo == data.goodsTypeNo)
  134. return row
  135. },
  136. // 加入购物车
  137. addCart() {
  138. let item = this.goodContent
  139. this.addGoodToCart({goodsNo:item.goodsNo,buyQty:this.nums,hasCunzai:this.hasCunzai(item)})
  140. },
  141. // 立即下单
  142. toOrder(){
  143. // console.log(this.goodContent,this.id,'pppppppp')
  144. if(this.goodContent.sellGold * this.nums >= this.goldLimit){
  145. this.$u.vuex("vuex_toOrderList",[{id:this.id,buyQty:this.nums,goodsNo:this.goodContent.goodsNo,goods:this.goodContent}])
  146. uni.redirectTo({
  147. url:"/pages/toOrder/index?orderForm=ORDER_NOW"
  148. })
  149. }else{
  150. uni.showToast({
  151. icon:"none",
  152. title:"此商品需要满" +this.goldLimit+ "乐豆才可购买"
  153. })
  154. }
  155. }
  156. },
  157. }
  158. </script>
  159. <style lang="scss">
  160. page{
  161. height: 100%;
  162. }
  163. .goods-detail{
  164. width: 100%;
  165. height: 100%;
  166. display: flex;
  167. flex-direction: column;
  168. > view{
  169. &:first-child{
  170. flex-grow: 1;
  171. overflow: auto;
  172. }
  173. }
  174. .goods-head{
  175. background: #FFFFFF;
  176. box-shadow: 1px 1px 3px #eee;
  177. padding: 10upx 0;
  178. .goods-imgs{
  179. position: relative;
  180. margin: 20upx 30upx 10upx;
  181. .goods-staus{
  182. width: 100%;
  183. height: 100%;
  184. position: absolute;
  185. z-index: 10000;
  186. background: url(../../static/yxt.png) no-repeat center center;
  187. background-size: 100% 100%;
  188. left: 0;
  189. top: 0;
  190. }
  191. }
  192. .goods-name{
  193. padding:0 40upx;
  194. margin: 20upx 0;
  195. display: flex;
  196. align-items: center;
  197. justify-content: space-between;
  198. >view{
  199. &:first-child{
  200. width: 60%;
  201. font-weight: bold;
  202. font-size: 30upx;
  203. }
  204. &:last-child{
  205. display: flex;
  206. align-items: center;
  207. text{
  208. color: #d42a26;
  209. font-size: 36upx;
  210. margin-right: 6upx;
  211. font-weight: bold;
  212. }
  213. }
  214. }
  215. }
  216. .goods-price{
  217. display: flex;
  218. align-items: center;
  219. justify-content: space-between;
  220. padding:0 40upx;
  221. >view{
  222. &:first-child{
  223. font-size: 22upx;
  224. text{
  225. color: #999;
  226. font-size: 24upx;
  227. margin-right: 6upx;
  228. }
  229. }
  230. }
  231. }
  232. .goods-goldLimit{
  233. padding: 10upx 40upx;
  234. color: #F0AD4E;
  235. font-size: 24rpx;
  236. text-align: right;
  237. text{
  238. color: red;
  239. }
  240. }
  241. }
  242. .goods-attr{
  243. margin: 20upx 0;
  244. background: #FFFFFF;
  245. padding: 20upx 40upx;
  246. box-shadow: 1px 1px 3px #eee;
  247. > view{
  248. display: flex;
  249. align-items: center;
  250. >view{
  251. padding: 10upx 0;
  252. &:first-child{
  253. padding-right: 15upx;
  254. color: #666;
  255. }
  256. }
  257. }
  258. }
  259. .goods-content{
  260. background: #F8F8F8;
  261. padding: 20upx;
  262. box-shadow: 1px 1px 3px #eee;
  263. min-height: 50vh;
  264. }
  265. .bottom-btns{
  266. background: #FFFFFF;
  267. display: flex;
  268. align-items: center;
  269. justify-content: space-around;
  270. padding: 30upx 100upx;
  271. >view{
  272. width: 50%;
  273. }
  274. }
  275. }
  276. </style>