goodsDetail.vue 6.6 KB

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