goodsDetail.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. },100)
  127. }else{
  128. uni.hideLoading()
  129. }
  130. })
  131. },
  132. // 判断当前商品是否已存在购物车中
  133. hasCunzai(data){
  134. let list = this.$store.state.vuex_cartList
  135. let row = list.find(item=> item.goodsTypeNo == data.goodsTypeNo)
  136. return row
  137. },
  138. // 加入购物车
  139. addCart() {
  140. let item = this.goodContent
  141. this.addGoodToCart({goodsNo:item.goodsNo,buyQty:this.nums,hasCunzai:this.hasCunzai(item)})
  142. },
  143. // 立即下单
  144. toOrder(){
  145. // console.log(this.goodContent,this.id,'pppppppp')
  146. if(this.goodContent.sellGold * this.nums >= this.goldLimit){
  147. this.$u.vuex("vuex_toOrderList",[{id:this.id,buyQty:this.nums,goodsNo:this.goodContent.goodsNo,goods:this.goodContent}])
  148. uni.redirectTo({
  149. url:"/pages/toOrder/index?orderForm=ORDER_NOW"
  150. })
  151. }else{
  152. uni.showToast({
  153. icon:"none",
  154. title:"此商品需要满" +this.goldLimit+ "乐豆才可购买"
  155. })
  156. }
  157. }
  158. },
  159. }
  160. </script>
  161. <style lang="scss">
  162. page{
  163. height: 100%;
  164. }
  165. .goods-detail{
  166. width: 100%;
  167. height: 100%;
  168. display: flex;
  169. flex-direction: column;
  170. > view{
  171. &:first-child{
  172. flex-grow: 1;
  173. overflow: auto;
  174. }
  175. }
  176. .goods-head{
  177. background: #FFFFFF;
  178. box-shadow: 1px 1px 3px #eee;
  179. padding: 10upx 0;
  180. .goods-imgs{
  181. position: relative;
  182. margin: 20upx 30upx 10upx;
  183. .goods-staus{
  184. width: 100%;
  185. height: 100%;
  186. position: absolute;
  187. z-index: 10000;
  188. background: url(../../static/yxt.png) no-repeat center center;
  189. background-size: 100% 100%;
  190. left: 0;
  191. top: 0;
  192. }
  193. }
  194. .goods-name{
  195. padding:0 40upx;
  196. margin: 20upx 0;
  197. display: flex;
  198. align-items: center;
  199. justify-content: space-between;
  200. >view{
  201. &:first-child{
  202. width: 60%;
  203. font-weight: bold;
  204. font-size: 30upx;
  205. }
  206. &:last-child{
  207. display: flex;
  208. align-items: center;
  209. text{
  210. color: #d42a26;
  211. font-size: 36upx;
  212. margin-right: 6upx;
  213. font-weight: bold;
  214. }
  215. }
  216. }
  217. }
  218. .goods-price{
  219. display: flex;
  220. align-items: center;
  221. justify-content: space-between;
  222. padding:0 40upx;
  223. >view{
  224. &:first-child{
  225. font-size: 22upx;
  226. text{
  227. color: #999;
  228. font-size: 24upx;
  229. margin-right: 6upx;
  230. }
  231. }
  232. }
  233. }
  234. .goods-goldLimit{
  235. padding: 10upx 40upx;
  236. color: #F0AD4E;
  237. font-size: 24rpx;
  238. text-align: right;
  239. text{
  240. color: red;
  241. }
  242. }
  243. }
  244. .goods-attr{
  245. margin: 20upx 0;
  246. background: #FFFFFF;
  247. padding: 20upx 40upx;
  248. box-shadow: 1px 1px 3px #eee;
  249. > view{
  250. display: flex;
  251. align-items: center;
  252. >view{
  253. padding: 10upx 0;
  254. &:first-child{
  255. padding-right: 15upx;
  256. color: #666;
  257. }
  258. }
  259. }
  260. }
  261. .goods-content{
  262. background: #F8F8F8;
  263. padding: 20upx;
  264. box-shadow: 1px 1px 3px #eee;
  265. min-height: 50vh;
  266. }
  267. .bottom-btns{
  268. background: #FFFFFF;
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-around;
  272. padding: 30upx 100upx;
  273. >view{
  274. width: 50%;
  275. }
  276. }
  277. }
  278. </style>