goodsDetail.vue 6.7 KB

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