productDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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>{{isShare?'首页':'返回'}}</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" img-mode="aspectFit" :interval="3000" :height="450" :list="imgList" @click="viewImg"></u-swiper>
  19. <view class="product-info-text">
  20. <view class="product-info-text-title">
  21. {{detail.productName}}
  22. <view class="copyText" @click="copy(detail.productName)">复制</view>
  23. <uni-tag style="margin-left: 10px;" size="mini" :circle="true" v-if="detail.status==0 || detail.dealerScopeFlag==0" :text="detail.status==0?'已下架':'已售罄'"></uni-tag>
  24. </view>
  25. <view class="product-info-text-attr">
  26. <view class="product-info-price flex align_center" v-if="!hasLogin">
  27. ¥***
  28. </view>
  29. <view class="flex align_center" v-else>
  30. <view class="product-info-price">
  31. ¥<text>{{Number(detail.price).toFixed(2).toString().split('.')[0]}}</text>.{{Number(detail.price).toFixed(2).toString().split('.')[1]}}
  32. </view>
  33. <view class="flex align_center rebate-tag" v-if="detail.price==30">
  34. 返<text>5</text>元
  35. </view>
  36. <view class="flex align_center rebate-tag" v-if="detail.price==24">
  37. 买3赠2
  38. </view>
  39. <view class="flex align_center tejia-tag" v-if="detail.price==21">
  40. 特价<text>¥20</text>
  41. </view>
  42. </view>
  43. <view class="product-info-nums">
  44. <view class="share">
  45. <button open-type="share"><u-icon :size='24' name="zhuanfa"></u-icon> 分享</button>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <u-divider bg-color="">商品详情</u-divider>
  52. <view class="product-info-guige" v-if="detail&&detail.product">
  53. <view class="row">品牌:<text>{{detail.product.productBrandName||'--'}}</text></view>
  54. <view class="row">原厂编码:<text>{{detail.product.origCode||'--'}} </text> <view class="copyText" v-if="detail.product.origCode" @click="copy(detail.product.origCode)">复制</view></view>
  55. <view class="row">产品编码:<text>{{detail.product.code||'--'}}</text> <view class="copyText" v-if="detail.product.code" @click="copy(detail.product.code)">复制</view></view>
  56. <view class="row">条形码:<text>{{detail.product.qrCode||'--'}}</text> <view class="copyText" v-if="detail.product.qrCode" @click="copy(detail.product.qrCode)">复制</view></view>
  57. <view class="row-ban">商品尺寸:<text>{{detail.product.size||'--'}}</text></view>
  58. <view class="row-ban">计量单位:<text>{{detail.product.unit||'--'}}</text></view>
  59. <view class="row-ban">重量:<text>{{detail.product.weight||'--'}}</text></view>
  60. <view class="row-ban">包装数:<text>{{ (detail.product.packQty) || '--' }}{{ detail.product.packQty ? detail.product.unit : '' }}/{{ detail.product.packQtyUnit||'--' }}</text></view>
  61. </view>
  62. <view class="product-info-content">
  63. <rich-text v-if="detail && detail.product && detail.product.description" :nodes="detail.product.description"></rich-text>
  64. <view v-else style="font-size: 12px;color: #999;text-align: center;">暂无产品介绍</view>
  65. </view>
  66. </view>
  67. <!-- 底部栏 -->
  68. <view class="scrollPage-footer">
  69. <view class="scrollPage-footer-box">
  70. <view class="footer-left">
  71. <view v-if="isShare" class="footer-left-item" @click="goBack">
  72. <u-icon :size='50' color="#666" name="home"></u-icon>
  73. <text class="footer-left-item-text">首页</text>
  74. </view>
  75. <view class="footer-left-item" @click="toCart">
  76. <u-icon :size='50' color="#666" name="shopping-cart"></u-icon>
  77. <text class="footer-left-item-text">购物车</text>
  78. <text class="badge" v-if="totalNum">{{totalNum>99?'99+':totalNum}}</text>
  79. </view>
  80. </view>
  81. <view class="footer-right">
  82. <view class="footer-right-item" @click="addCart">
  83. <text>加入购物车</text>
  84. </view>
  85. <view class="footer-right-item" @click="toBuy">
  86. <text>立即购买</text>
  87. </view>
  88. </view>
  89. </view>
  90. <view :style="{height:safeAreaBottom+'px'}"></view>
  91. </view>
  92. <!-- 立即购买 -->
  93. <page-container
  94. :show="showPopu"
  95. :round="true"
  96. :z-index="100"
  97. position="bottom"
  98. custom-style="height:30%;"
  99. @afterleave="closePopu">
  100. <view class="popu-content" v-if="detail">
  101. <view class="popu-close" @click="showPopu=false">
  102. <uni-icons size="26" type="closeempty"></uni-icons>
  103. </view>
  104. <view class="pupu-box">
  105. <view class="popu-content-img">
  106. <image style="width: 100px; height: 100px;" mode="aspectFit" :src="detail.productMsg||'/static/def_imgs.png'"></image>
  107. </view>
  108. <view class="popu-content-info">
  109. <view class="popu-content-info-title">{{detail.productName}}</view>
  110. <view class="popu-content-box">
  111. <view class="popu-content-price">¥<text class="price-red">{{hasLogin?detail.price:'***'}}</text></view>
  112. <view class="popu-content-num flex align_center">
  113. <text style="margin-right: 10px;">数量</text>
  114. <uni-number-box v-model="qty" :min="1" :max="999999"></uni-number-box>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. <view class="popu-content-btn">
  120. <view class="popu-content-btn-item" @click="toBuy">确定采购</view>
  121. </view>
  122. <view :style="{height:safeAreaBottom+'px'}"></view>
  123. </view>
  124. </page-container>
  125. </view>
  126. </template>
  127. <script>
  128. import {
  129. mapState,
  130. mapMutations,
  131. } from 'vuex'
  132. import { addCart, getCartCount } from '@/api/cart.js'
  133. import { getShopDetail } from '@/api/shop.js'
  134. import { purchaseSave, purchaseCheck } from '@/api/purchase.js'
  135. import { toAuthStore, toLogin } from "@/utils/index.js"
  136. export default {
  137. data() {
  138. return {
  139. showPopu: false, // 弹框
  140. statusBarHeight: 0, // 状态栏高度
  141. safeAreaBottom: 0, // 底部安全区域高度
  142. imgList: [],
  143. shopProductSn: null,
  144. detail: null,
  145. qty: 1,// 数量
  146. isShare: false // 是否从分享打开的
  147. }
  148. },
  149. onLoad(option) {
  150. this.isShare = !!option.share
  151. // 计算安全区域
  152. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  153. this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
  154. this.shopProductSn = option.sn
  155. // 获取产品详情
  156. this.getDetail()
  157. },
  158. // 分享
  159. onShareAppMessage(e){
  160. return {
  161. title: this.detail ? this.detail.productName : '商品名称',
  162. path: '/pagesB/shopiing/productDetail?sn='+this.shopProductSn+'&share=1',
  163. imageUrl:this.detail ? this.detail.productMsg : '',
  164. type: '1'
  165. }
  166. },
  167. computed: {
  168. ...mapState(['hasLogin']),
  169. // 登录用户信息
  170. userInfo(){
  171. return this.$store.state.vuex_userInfo
  172. },
  173. totalNum(){
  174. return this.hasLogin&&this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_cartTotal : 0
  175. }
  176. },
  177. methods: {
  178. // 返回
  179. goBack(){
  180. if(this.isShare){
  181. uni.reLaunch({
  182. url: '/pages/index/index'
  183. })
  184. }else{
  185. uni.navigateBack()
  186. }
  187. },
  188. // 复制
  189. copy(text){
  190. uni.setClipboardData({
  191. data: text,
  192. })
  193. },
  194. viewImg(index){
  195. uni.previewImage({
  196. urls: this.imgList
  197. })
  198. },
  199. // 产品详情
  200. getDetail(){
  201. uni.showLoading({
  202. title: '加载中'
  203. })
  204. const storeShelf = this.$store.state.vuex_storeShelf
  205. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1'&&storeShelf ? storeShelf.dealerSn : ''
  206. // 获取产品详情
  207. getShopDetail({
  208. shopProductSn: this.shopProductSn,
  209. dealerSn: dealerSn
  210. }).then(res => {
  211. if(res.status == 200){
  212. this.detail = res.data
  213. if(res.data && res.data.productPicList){
  214. res.data.productPicList.forEach(item => {
  215. this.imgList.push(item.imageUrl||'/static/def_imgs.png')
  216. })
  217. }else{
  218. this.imgList.push(res.data.productMsg||'/static/def_imgs.png')
  219. }
  220. }
  221. uni.hideLoading()
  222. })
  223. },
  224. // 加入购物车
  225. addCart(){
  226. if(this.hasLogin){
  227. // 游客未认证
  228. if(this.userInfo.sysUserFlag == '0'){
  229. toAuthStore()
  230. }else{
  231. uni.showLoading({
  232. title: '加入中...',
  233. mask: true
  234. })
  235. // 加入购物车
  236. addCart({
  237. qty: 1,
  238. price: this.detail.price,
  239. productSn: this.detail.productSn
  240. }).then(res => {
  241. if(res.status == 200){
  242. uni.$emit('refashCart')
  243. uni.hideLoading()
  244. }
  245. })
  246. }
  247. }else{
  248. toLogin()
  249. }
  250. },
  251. // 打开购物车
  252. toCart(){
  253. if(this.hasLogin){
  254. // 游客未认证
  255. if(this.userInfo.sysUserFlag == '0'){
  256. toAuthStore()
  257. }else{
  258. uni.navigateTo({
  259. url: '/pagesB/cart/index'
  260. })
  261. }
  262. }else{
  263. toLogin()
  264. }
  265. },
  266. // 立即购买
  267. toBuy(){
  268. if(this.hasLogin){
  269. // 游客未认证
  270. if(this.userInfo.sysUserFlag == '0'){
  271. toAuthStore()
  272. }else{
  273. if(this.detail.status==0 || this.detail.dealerScopeFlag==0){
  274. uni.showToast({
  275. title: '此商品已'+(this.detail.status==0?'下架':'售罄'),
  276. icon: 'none'
  277. })
  278. }else{
  279. // 打开数量选择弹框
  280. if(!this.showPopu){
  281. this.showPopu = true
  282. }else{
  283. // 提交
  284. this.submitOrder()
  285. }
  286. }
  287. }
  288. }else{
  289. toLogin()
  290. }
  291. },
  292. // 去结算
  293. submitOrder(){
  294. uni.showLoading({
  295. title: '提交中...',
  296. mask: true
  297. })
  298. const _this = this
  299. purchaseCheck({detailList: [{
  300. productSn:this.detail.productSn,
  301. productCode:this.detail.productCode,
  302. qty: this.qty,
  303. price:this.detail.price,
  304. }]}).then(res => {
  305. if(res.status == 200){
  306. const successList = res.data.successList.map(item => {
  307. return {
  308. productSn:item.productSn,
  309. productCode: item.productCode,
  310. qty: item.qty,
  311. price:item.price
  312. }
  313. })
  314. const removeList = res.data.removeList.map(item => item.productCode)
  315. const selloutList = res.data.selloutList.map(item => item.productCode)
  316. // 有已下架或已售罄产品提示
  317. if(removeList.length || selloutList.length){
  318. uni.showModal({
  319. title: '提示',
  320. content: (removeList.length ? `产品${removeList.join(',')}已下架,`:'')+(selloutList.length?`产品${selloutList.join(',')}已售罄,`:'')+`不可采购。`+(successList.length?'是否继续采购其他产品?':''),
  321. showCancel: successList.length,
  322. confirmText: successList.length?'确定':'知道了',
  323. success(ret) {
  324. uni.hideLoading()
  325. if(ret.confirm && successList.length){
  326. _this.submitForm(successList)
  327. }
  328. }
  329. })
  330. }else{
  331. // 直接提交
  332. _this.submitForm(successList)
  333. }
  334. }else{
  335. uni.hideLoading()
  336. uni.showToast({
  337. title: res.message,
  338. icon: 'none'
  339. })
  340. }
  341. })
  342. },
  343. submitForm(detailList){
  344. purchaseSave({
  345. detailList: detailList
  346. }).then(res => {
  347. uni.hideLoading()
  348. if(res.status == 200){
  349. res.data.detailList = []
  350. this.$store.state.vuex_tempData = res.data
  351. this.showPopu = false
  352. this.submitOk = true
  353. }else{
  354. uni.showToast({
  355. title: res.message,
  356. icon: 'none'
  357. })
  358. }
  359. })
  360. },
  361. // 关闭后
  362. closePopu(){
  363. this.showPopu = false
  364. this.qty = 1
  365. uni.hideLoading()
  366. // 提交成功
  367. if(this.submitOk){
  368. uni.navigateTo({
  369. url: "/pagesB/procureOrder"
  370. })
  371. }
  372. },
  373. }
  374. }
  375. </script>
  376. <style lang="less">
  377. .pages {
  378. height: 100vh;
  379. display: flex;
  380. flex-direction: column;
  381. .scrollPage-header{
  382. z-index: 1;
  383. width: 100%;
  384. position:fixed;
  385. left: 0;
  386. top: 0;
  387. .header-title{
  388. display: flex;
  389. align-items: center;
  390. justify-content: space-between;
  391. padding: 0 10px;
  392. height: 44px;
  393. .header-left{
  394. display: flex;
  395. align-items: center;
  396. text{
  397. font-size: 14px;
  398. color: #333333;
  399. }
  400. background-color: rgba(255,255,255,0.6);
  401. box-shadow: 0px 1px 0px 0px #E6E6E6;
  402. border-radius: 50px;
  403. padding: 3px 6px 3px;
  404. }
  405. .header-right{
  406. width: 50px;
  407. }
  408. }
  409. }
  410. .copyText{
  411. background-color: #efefef;
  412. border-radius: 100rpx;
  413. padding: 0 20rpx;
  414. color: #03A9F4;
  415. font-size: 20rpx;
  416. display: inline-block;
  417. margin-left: 20rpx;
  418. height: 44rpx;
  419. line-height: 44rpx;
  420. }
  421. .scrollPage-content{
  422. flex: 1;
  423. overflow-y: auto;
  424. .product-info{
  425. background:#fff;
  426. margin-bottom: 10px;
  427. .product-info-text{
  428. padding: 10px;
  429. .product-info-text-title{
  430. font-weight: bold;
  431. color: #333333;
  432. line-height: 22px;
  433. margin-bottom: 5px;
  434. }
  435. .product-info-text-attr{
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. .product-info-price{
  440. color: red;
  441. display: flex;
  442. align-items: baseline;
  443. font-size: 12px;
  444. text{
  445. font-size: 38rpx;
  446. }
  447. }
  448. .rebate-tag{
  449. background: #ffe7df;
  450. color: #E91E63;
  451. padding: 2px 5px;
  452. font-size: 10px;
  453. border-radius: 3px;
  454. margin-left: 6px;
  455. }
  456. .tejia-tag{
  457. color: #E91E63;
  458. margin-left: 6px;
  459. font-size: 12px;
  460. text{
  461. font-size: 12px;
  462. color: #999;
  463. margin-left: 5px;
  464. }
  465. }
  466. .product-info-nums{
  467. font-size: 12px;
  468. color: #999999;
  469. >view{
  470. display: flex;
  471. align-items: center;
  472. }
  473. .share{
  474. button{
  475. width: auto;
  476. padding: 0;
  477. border: 0;
  478. background: none;
  479. line-height: normal;
  480. margin: 0;
  481. display: inline;
  482. font-size: 12px;
  483. color: #999;
  484. &::after{
  485. border:none;
  486. }
  487. /deep/ .u-icon{
  488. margin-right: 3px;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. .product-info-guige{
  497. display: flex;
  498. flex-wrap: wrap;
  499. justify-content: space-between;
  500. background:#fff;
  501. margin: 10px 0;
  502. padding: 10px;
  503. line-height: 28px;
  504. .row{
  505. width: 100%;
  506. }
  507. .row-ban{
  508. width: 50%;
  509. }
  510. >view{
  511. color: #999;
  512. text{
  513. color: #333333;
  514. }
  515. }
  516. }
  517. .product-info-content{
  518. background:#fff;
  519. margin-bottom: 10px;
  520. padding: 10px;
  521. line-height: 28px;
  522. }
  523. }
  524. .scrollPage-footer{
  525. background-color: #FFFFFF;
  526. width: 100%;
  527. position: fixed;
  528. left: 0;
  529. bottom: 0;
  530. .scrollPage-footer-box{
  531. display: flex;
  532. align-items: center;
  533. justify-content: space-between;
  534. height: 50px;
  535. }
  536. .footer-left{
  537. display: flex;
  538. align-items: center;
  539. justify-content: space-between;
  540. width: 35%;
  541. .footer-left-item{
  542. display: flex;
  543. flex-direction: column;
  544. align-items: center;
  545. justify-content: center;
  546. padding: 0 15px;
  547. position: relative;
  548. .footer-left-item-text{
  549. font-size: 12px;
  550. color: #666666;
  551. }
  552. .badge{
  553. background: #f44336;
  554. color: #fff;
  555. position: absolute;
  556. right: 5px;
  557. top: -8px;
  558. font-size: 12px;
  559. display: flex;
  560. align-items: center;
  561. justify-content: center;
  562. border-radius: 50rpx;
  563. padding: 0 10rpx;
  564. }
  565. }
  566. }
  567. .footer-right{
  568. width: 60%;
  569. height: 100%;
  570. display: flex;
  571. align-items: center;
  572. .footer-right-item{
  573. height: 100%;
  574. display: flex;
  575. flex-direction: column;
  576. align-items: center;
  577. justify-content: center;
  578. width: 50%;
  579. font-size: 14px;
  580. color: #FFFFFF;
  581. }
  582. .footer-right-item:first-child{
  583. background-color: #FF9900;
  584. }
  585. .footer-right-item:last-child{
  586. background-color: #FF0000;
  587. }
  588. }
  589. }
  590. .popu-content{
  591. display: flex;
  592. flex-direction: column;
  593. align-items: center;
  594. padding: 10px;
  595. .popu-close{
  596. padding: 10px;
  597. position: absolute;
  598. right: 0;
  599. top: 0;
  600. }
  601. .pupu-box{
  602. display: flex;
  603. align-items: center;
  604. justify-content: space-between;
  605. margin-top: 25px;
  606. }
  607. .popu-content-img{
  608. border-radius: 10px;
  609. border: 1px solid #eee;
  610. }
  611. .popu-content-info{
  612. padding: 0 0 0 10px;
  613. .popu-content-info-title{
  614. font-size: 14px;
  615. font-weight: bold;
  616. }
  617. }
  618. .popu-content-box{
  619. display: flex;
  620. align-items: center;
  621. justify-content: space-between;
  622. margin-top: 10px;
  623. .popu-content-price{
  624. font-size: 14px;
  625. color: #d50e0e;
  626. .price-red{
  627. font-size: 24px;
  628. }
  629. }
  630. .popu-content-num{
  631. font-size: 12px;
  632. color: #999999;
  633. padding: 0 10px;
  634. }
  635. }
  636. .popu-content-btn{
  637. width: 100%;
  638. display: flex;
  639. align-items: center;
  640. justify-content: center;
  641. margin-top: 20px;
  642. .popu-content-btn-item{
  643. width: 60%;
  644. height: 40px;
  645. background-color: #f70000;
  646. color: #FFFFFF;
  647. font-size: 14px;
  648. display: flex;
  649. align-items: center;
  650. justify-content: center;
  651. border-radius: 100px;
  652. }
  653. }
  654. }
  655. }
  656. </style>