productDetail.vue 17 KB

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