goodsDetail.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. userData: null
  86. };
  87. },
  88. onLoad(opts) {
  89. console.log(opts)
  90. this.id = opts.id
  91. this.userData = this.$store.state.vuex_userData
  92. this.getDetail()
  93. },
  94. methods: {
  95. // 查详情
  96. getDetail(){
  97. getGoodsDetail({id:this.id}).then(res => {
  98. console.log(res)
  99. if(res.status == 200){
  100. this.goodContent = res.data
  101. this.goldLimit = res.data.goodsType.goldLimit || 0
  102. let arr=res.data.images.split(',')
  103. arr.map(item => {
  104. this.imageList.push({image:item})
  105. })
  106. }
  107. })
  108. },
  109. // 添加购物车
  110. addGoodToCart(item){
  111. uni.showLoading({
  112. mask: true,
  113. title: "正在加入购物车..."
  114. })
  115. addGoodsToCart(item).then(res => {
  116. if(res.status == 200){
  117. // 刷新购物车数量
  118. if(!item.hasCunzai){
  119. this.$store.state.vuex_cartNums = this.$store.state.vuex_cartNums + 1
  120. }
  121. setTimeout(()=>{
  122. uni.showToast({
  123. icon: 'none',
  124. title:'添加成功'
  125. })
  126. // 刷新购物车数据
  127. uni.$emit('getCartList')
  128. },50)
  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. if(this.userData.customerRole == 9){
  146. uni.showToast({
  147. icon:"none",
  148. title:"抱歉,您目前无法使用乐豆"
  149. })
  150. }else{
  151. if(this.goodContent.sellGold * this.nums >= this.goldLimit){
  152. this.$u.vuex("vuex_toOrderList",[{id:this.id,buyQty:this.nums,goodsNo:this.goodContent.goodsNo,goods:this.goodContent}])
  153. uni.redirectTo({
  154. url:"/pagesA/toOrder/index?orderForm=ORDER_NOW"
  155. })
  156. }else{
  157. uni.showToast({
  158. icon:"none",
  159. title:"此类商品需要满" +this.goldLimit+ "乐豆才可购买"
  160. })
  161. }
  162. }
  163. }
  164. },
  165. }
  166. </script>
  167. <style lang="scss">
  168. page{
  169. height: 100%;
  170. }
  171. .goods-detail{
  172. width: 100%;
  173. height: 100%;
  174. display: flex;
  175. flex-direction: column;
  176. > view{
  177. &:first-child{
  178. flex-grow: 1;
  179. overflow: auto;
  180. }
  181. }
  182. .goods-head{
  183. background: #FFFFFF;
  184. box-shadow: 1px 1px 3px #eee;
  185. padding: 10upx 0;
  186. .goods-imgs{
  187. position: relative;
  188. margin: 20upx 30upx 10upx;
  189. .goods-staus{
  190. width: 100%;
  191. height: 100%;
  192. position: absolute;
  193. z-index: 10000;
  194. background: url(../../static/yxt.png) no-repeat center center;
  195. background-size: 100% 100%;
  196. left: 0;
  197. top: 0;
  198. }
  199. }
  200. .goods-name{
  201. padding:0 40upx;
  202. margin: 20upx 0;
  203. display: flex;
  204. align-items: center;
  205. justify-content: space-between;
  206. >view{
  207. &:first-child{
  208. width: 60%;
  209. font-weight: bold;
  210. font-size: 30upx;
  211. }
  212. &:last-child{
  213. display: flex;
  214. align-items: center;
  215. text{
  216. color: #d42a26;
  217. font-size: 36upx;
  218. margin-right: 6upx;
  219. font-weight: bold;
  220. }
  221. }
  222. }
  223. }
  224. .goods-price{
  225. display: flex;
  226. align-items: center;
  227. justify-content: space-between;
  228. padding:0 40upx;
  229. >view{
  230. &:first-child{
  231. font-size: 22upx;
  232. text{
  233. color: #999;
  234. font-size: 24upx;
  235. margin-right: 6upx;
  236. }
  237. }
  238. }
  239. }
  240. .goods-goldLimit{
  241. padding: 10upx 40upx;
  242. color: #F0AD4E;
  243. font-size: 24rpx;
  244. text-align: right;
  245. text{
  246. color: red;
  247. }
  248. }
  249. }
  250. .goods-attr{
  251. margin: 20upx 0;
  252. background: #FFFFFF;
  253. padding: 20upx 40upx;
  254. box-shadow: 1px 1px 3px #eee;
  255. > view{
  256. display: flex;
  257. align-items: center;
  258. >view{
  259. padding: 10upx 0;
  260. &:first-child{
  261. padding-right: 15upx;
  262. color: #666;
  263. }
  264. }
  265. }
  266. }
  267. .goods-content{
  268. background: #F8F8F8;
  269. padding: 20upx;
  270. box-shadow: 1px 1px 3px #eee;
  271. min-height: 50vh;
  272. }
  273. .bottom-btns{
  274. background: #FFFFFF;
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-around;
  278. padding: 30upx 100upx;
  279. >view{
  280. width: 50%;
  281. }
  282. }
  283. }
  284. </style>