productDetail.vue 13 KB

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