productDetail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <view class="pages">
  3. <!-- head -->
  4. <view class="scrollPage-header">
  5. <view :style="{height:statusBarHeight+'px'}"></view>
  6. <view class="header-title">
  7. <view class="header-left" @click="goBack">
  8. <image style="width: 16px; height: 16px;margin-right:3px;" mode="aspectFit" src="../static/arrow-left.png"></image>
  9. <text>返回</text>
  10. </view>
  11. <view class="header-right"></view>
  12. </view>
  13. </view>
  14. <!-- 内容 -->
  15. <view class="scrollPage-content">
  16. <view class="product-info" v-if="detail">
  17. <view :style="{height:statusBarHeight+'px'}"></view>
  18. <u-swiper mode="number" :border-radius="0" bg-color="#000" img-mode="widthFix" :interval="3000" :height="450" :list="imgList"></u-swiper>
  19. <view class="product-info-text">
  20. <view class="product-info-text-title">{{detail.productName}}</view>
  21. <view class="product-info-text-attr">
  22. <view class="product-info-price">
  23. ¥<text class="price-red">{{hasLogin ? detail.price : '***'}}</text>
  24. </view>
  25. <view class="product-info-nums">
  26. <view class="share">
  27. <button open-type="share"><u-icon :size='24' name="zhuanfa"></u-icon> 分享</button>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <u-divider bg-color="">商品详情</u-divider>
  34. <view class="product-info-guige" v-if="detail">
  35. <view class="row">品牌:<text>{{detail.productBrandName||'--'}}</text></view>
  36. <view class="row-ban">原厂编码:<text>{{detail.productOrigCode||'--'}} </text></view>
  37. <view class="row-ban">产品编码:<text>{{detail.productCode||'--'}}</text></view>
  38. <view class="row-ban">计量单位:<text>{{detail.unit||'--'}}</text></view>
  39. <view class="row-ban">包装数:<text>{{ (detail && detail.packQty) || '--' }}{{ (detail && detail.packQty) ? detail.unit : '' }}/{{ detail.packQtyUnit||'--' }}</text></view>
  40. <view class="row-ban">尺寸:<text>{{detail.size||'--'}}</text></view>
  41. <view class="row-ban">内盒尺寸:<text>{{detail.size||'--'}}</text></view>
  42. <view class="row-ban">重量:<text>{{detail.weight||'--'}}</text></view>
  43. <view class="row-ban">颜色:<text>{{detail.color||'--'}}</text></view>
  44. </view>
  45. <view class="product-info-content">
  46. <rich-text v-if="detail && detail.description" :nodes="detail.description"></rich-text>
  47. <view v-else style="font-size: 12px;color: #999;text-align: center;">暂无产品介绍</view>
  48. </view>
  49. </view>
  50. <!-- 底部栏 -->
  51. <view class="scrollPage-footer">
  52. <view class="scrollPage-footer-box">
  53. <view class="footer-left">
  54. <view class="footer-left-item" @click="toCart">
  55. <u-icon :size='50' name="shopping-cart"></u-icon>
  56. <text class="footer-left-item-text">购物车</text>
  57. <text class="badge" v-if="totalNum">{{totalNum>99?'99+':totalNum}}</text>
  58. </view>
  59. </view>
  60. <view class="footer-right">
  61. <view class="footer-right-item" @click="addCart">
  62. <text>加入购物车</text>
  63. </view>
  64. <view class="footer-right-item" @click="toBuy">
  65. <text>立即购买</text>
  66. </view>
  67. </view>
  68. </view>
  69. <view :style="{height:safeAreaBottom+'px'}"></view>
  70. </view>
  71. <!-- 立即购买 -->
  72. <page-container
  73. :show="showPopu"
  74. :round="true"
  75. :z-index="100"
  76. position="bottom"
  77. custom-style="height:30%"
  78. @afterleave="closePopu">
  79. <view class="popu-content" v-if="detail">
  80. <view class="popu-close" @click="showPopu=false">
  81. <uni-icons size="26" type="closeempty"></uni-icons>
  82. </view>
  83. <view class="pupu-box">
  84. <view class="popu-content-img">
  85. <image style="width: 100px; height: 100px;" mode="aspectFit" :src="detail.productMsg"></image>
  86. </view>
  87. <view class="popu-content-info">
  88. <view class="popu-content-info-title">{{detail.productName}}</view>
  89. <view class="popu-content-box">
  90. <view class="popu-content-price">¥<text class="price-red">{{detail.price}}</text></view>
  91. <view class="popu-content-num flex align_center">
  92. <text style="margin-right: 10px;">数量</text>
  93. <uni-number-box v-model="qty" :min="1" :max="99"></uni-number-box>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="popu-content-btn">
  99. <view class="popu-content-btn-item" @click="toBuy">确定采购</view>
  100. </view>
  101. <view :style="{height:safeAreaBottom+'px'}"></view>
  102. </view>
  103. </page-container>
  104. </view>
  105. </template>
  106. <script>
  107. import {
  108. mapState,
  109. mapMutations,
  110. } from 'vuex'
  111. import { addCart, getCartCount } from '@/api/cart.js'
  112. import { getShopDetail } from '@/api/shop.js'
  113. import { purchaseSave } from '@/api/purchase.js'
  114. export default {
  115. data() {
  116. return {
  117. showPopu: false, // 弹框
  118. statusBarHeight: 0, // 状态栏高度
  119. safeAreaBottom: 0, // 底部安全区域高度
  120. imgList: [],
  121. totalNum: 0 ,// 购物车总数
  122. shopProductSn: null,
  123. detail: null,
  124. qty: 1,// 数量
  125. }
  126. },
  127. onLoad(option) {
  128. // 计算安全区域
  129. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  130. this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
  131. this.shopProductSn = option.sn
  132. // 获取产品详情
  133. this.getDetail()
  134. },
  135. onShow(){
  136. if(this.hasLogin){
  137. // 购物车数量
  138. this.cartCount()
  139. }
  140. },
  141. // 分享
  142. onShareAppMessage(e){
  143. return {
  144. title: this.detail ? this.detail.productName : '商品名称',
  145. path: '/pagesB/shopiing/productDetail?sn='+this.shopProductSn,
  146. imageUrl:this.detail ? this.detail.productMsg : '',
  147. type: '1'
  148. }
  149. },
  150. computed: {
  151. ...mapState(['hasLogin'])
  152. },
  153. methods: {
  154. // 返回
  155. goBack(){
  156. uni.navigateBack()
  157. },
  158. // 产品详情
  159. getDetail(){
  160. uni.showLoading({
  161. title: '加载中'
  162. })
  163. // 获取产品详情
  164. getShopDetail({
  165. shopProductSn: this.shopProductSn
  166. }).then(res => {
  167. if(res.status == 200){
  168. this.detail = res.data
  169. this.imgList = [res.data.productMsg]
  170. }
  171. uni.hideLoading()
  172. })
  173. },
  174. // 购物车数量
  175. cartCount(){
  176. getCartCount({}).then(res => {
  177. if(res.status == 200){
  178. this.totalNum = res.data?res.data.qty:0
  179. }
  180. })
  181. },
  182. // 加入购物车
  183. addCart(){
  184. if(this.hasLogin){
  185. addCart({
  186. qty: 1,
  187. price: this.detail.price,
  188. productSn: this.detail.productSn
  189. }).then(res => {
  190. if(res.status == 200){
  191. this.cartCount()
  192. uni.showToast({
  193. title: '加入成功',
  194. icon: 'success'
  195. })
  196. }
  197. })
  198. }else{
  199. uni.navigateTo({
  200. url: '/pages/login/login'
  201. })
  202. }
  203. },
  204. // 打开购物车
  205. toCart(){
  206. if(this.hasLogin){
  207. uni.navigateTo({
  208. url: '/pagesB/cart/index'
  209. })
  210. }else{
  211. uni.navigateTo({
  212. url: '/pages/login/login'
  213. })
  214. }
  215. },
  216. // 立即购买
  217. toBuy(){
  218. if(this.hasLogin){
  219. // 打开数量选择弹框
  220. if(!this.showPopu){
  221. this.showPopu = true
  222. }else{
  223. // 提交
  224. this.submitOrder()
  225. }
  226. }else{
  227. uni.navigateTo({
  228. url: '/pages/login/login'
  229. })
  230. }
  231. },
  232. // 去结算
  233. submitOrder(){
  234. uni.showLoading({
  235. title: '提交中...',
  236. mask: true
  237. })
  238. const detailList = [{
  239. productSn:this.detail.productSn,
  240. productCode:this.detail.productCode,
  241. qty: this.qty,
  242. price:this.detail.price,
  243. }]
  244. purchaseSave({
  245. detailList: detailList
  246. }).then(res => {
  247. if(res.status == 200){
  248. res.data.detailList = []
  249. this.$store.state.vuex_tempData = res.data
  250. this.showPopu = false
  251. this.submitOk = true
  252. }else{
  253. uni.showToast({
  254. title: res.message,
  255. icon: 'none'
  256. })
  257. }
  258. })
  259. },
  260. // 关闭后
  261. closePopu(){
  262. this.showPopu = false
  263. this.qty = 1
  264. uni.hideLoading()
  265. // 提交成功
  266. if(this.submitOk){
  267. uni.navigateTo({
  268. url: "/pagesB/procureOrder"
  269. })
  270. }
  271. },
  272. }
  273. }
  274. </script>
  275. <style lang="less">
  276. .pages {
  277. height: 100vh;
  278. display: flex;
  279. flex-direction: column;
  280. .scrollPage-header{
  281. z-index: 1;
  282. width: 100%;
  283. position:fixed;
  284. left: 0;
  285. top: 0;
  286. .header-title{
  287. display: flex;
  288. align-items: center;
  289. justify-content: space-between;
  290. padding: 0 10px;
  291. height: 44px;
  292. .header-left{
  293. display: flex;
  294. align-items: center;
  295. text{
  296. font-size: 14px;
  297. color: #333333;
  298. }
  299. background-color: rgba(255,255,255,0.6);
  300. box-shadow: 0px 1px 0px 0px #E6E6E6;
  301. border-radius: 50px;
  302. padding: 3px 6px 3px;
  303. }
  304. .header-right{
  305. width: 50px;
  306. }
  307. }
  308. }
  309. .scrollPage-content{
  310. flex: 1;
  311. overflow-y: auto;
  312. .product-info{
  313. background:#fff;
  314. margin-bottom: 10px;
  315. .product-info-text{
  316. padding: 10px;
  317. .product-info-text-title{
  318. font-weight: bold;
  319. color: #333333;
  320. line-height: 22px;
  321. margin-bottom: 5px;
  322. }
  323. .product-info-text-attr{
  324. display: flex;
  325. align-items: center;
  326. justify-content: space-between;
  327. .product-info-price{
  328. font-size: 14px;
  329. color: #FF0000;
  330. .price-red{
  331. font-size: 24px;
  332. }
  333. }
  334. .product-info-nums{
  335. font-size: 12px;
  336. color: #999999;
  337. >view{
  338. display: flex;
  339. align-items: center;
  340. }
  341. .share{
  342. button{
  343. width: auto;
  344. padding: 0;
  345. border: 0;
  346. background: none;
  347. line-height: normal;
  348. margin: 0;
  349. display: inline;
  350. font-size: 12px;
  351. color: #999;
  352. &::after{
  353. border:none;
  354. }
  355. /deep/ .u-icon{
  356. margin-right: 3px;
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. .product-info-guige{
  365. display: flex;
  366. flex-wrap: wrap;
  367. justify-content: space-between;
  368. background:#fff;
  369. margin: 10px 0;
  370. padding: 10px;
  371. line-height: 28px;
  372. .row{
  373. width: 100%;
  374. }
  375. .row-ban{
  376. width: 50%;
  377. }
  378. >view{
  379. color: #999;
  380. text{
  381. color: #333333;
  382. }
  383. }
  384. }
  385. .product-info-content{
  386. background:#fff;
  387. margin-bottom: 10px;
  388. padding: 10px;
  389. line-height: 28px;
  390. }
  391. }
  392. .scrollPage-footer{
  393. background-color: #FFFFFF;
  394. width: 100%;
  395. position: fixed;
  396. left: 0;
  397. bottom: 0;
  398. .scrollPage-footer-box{
  399. display: flex;
  400. align-items: center;
  401. justify-content: space-between;
  402. height: 50px;
  403. }
  404. .footer-left{
  405. display: flex;
  406. align-items: center;
  407. justify-content: space-between;
  408. width: 35%;
  409. .footer-left-item{
  410. display: flex;
  411. flex-direction: column;
  412. align-items: center;
  413. justify-content: center;
  414. padding: 0 15px;
  415. position: relative;
  416. .footer-left-item-text{
  417. font-size: 12px;
  418. color: #666666;
  419. }
  420. .badge{
  421. background: #f44336;
  422. color: #fff;
  423. position: absolute;
  424. right: 0;
  425. top: -8px;
  426. font-size: 12px;
  427. display: flex;
  428. align-items: center;
  429. justify-content: center;
  430. border-radius: 50rpx;
  431. padding: 0 10rpx;
  432. }
  433. }
  434. }
  435. .footer-right{
  436. width: 60%;
  437. height: 100%;
  438. display: flex;
  439. align-items: center;
  440. .footer-right-item{
  441. height: 100%;
  442. display: flex;
  443. flex-direction: column;
  444. align-items: center;
  445. justify-content: center;
  446. width: 50%;
  447. font-size: 14px;
  448. color: #FFFFFF;
  449. }
  450. .footer-right-item:first-child{
  451. background-color: #FF9900;
  452. }
  453. .footer-right-item:last-child{
  454. background-color: #FF0000;
  455. }
  456. }
  457. }
  458. .popu-content{
  459. display: flex;
  460. flex-direction: column;
  461. align-items: center;
  462. padding: 10px;
  463. .popu-close{
  464. padding: 10px;
  465. position: absolute;
  466. right: 0;
  467. top: 0;
  468. }
  469. .pupu-box{
  470. display: flex;
  471. align-items: center;
  472. justify-content: space-between;
  473. margin-top: 25px;
  474. }
  475. .popu-content-img{
  476. border-radius: 10px;
  477. border: 1px solid #eee;
  478. }
  479. .popu-content-info{
  480. padding: 0 0 0 10px;
  481. .popu-content-info-title{
  482. font-size: 14px;
  483. font-weight: bold;
  484. }
  485. }
  486. .popu-content-box{
  487. display: flex;
  488. align-items: center;
  489. justify-content: space-between;
  490. margin-top: 10px;
  491. .popu-content-price{
  492. font-size: 14px;
  493. color: #d50e0e;
  494. .price-red{
  495. font-size: 24px;
  496. }
  497. }
  498. .popu-content-num{
  499. font-size: 12px;
  500. color: #999999;
  501. padding: 0 10px;
  502. }
  503. }
  504. .popu-content-btn{
  505. width: 100%;
  506. display: flex;
  507. align-items: center;
  508. justify-content: center;
  509. margin-top: 20px;
  510. .popu-content-btn-item{
  511. width: 50%;
  512. height: 40px;
  513. background-color: #d50e0e;
  514. color: #FFFFFF;
  515. font-size: 14px;
  516. display: flex;
  517. align-items: center;
  518. justify-content: center;
  519. border-radius: 10px;
  520. }
  521. }
  522. }
  523. }
  524. </style>