productDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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"></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. // 产品详情
  186. getDetail(){
  187. uni.showLoading({
  188. title: '加载中'
  189. })
  190. const storeShelf = this.$store.state.vuex_storeShelf
  191. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1'&&storeShelf ? storeShelf.dealerSn : ''
  192. // 获取产品详情
  193. getShopDetail({
  194. shopProductSn: this.shopProductSn,
  195. dealerSn: dealerSn
  196. }).then(res => {
  197. if(res.status == 200){
  198. this.detail = res.data
  199. if(res.data && res.data.productPicList){
  200. res.data.productPicList.forEach(item => {
  201. this.imgList.push(item.imageUrl||'/static/def_imgs.png')
  202. })
  203. }else{
  204. this.imgList.push(res.data.productMsg||'/static/def_imgs.png')
  205. }
  206. }
  207. uni.hideLoading()
  208. })
  209. },
  210. // 购物车数量
  211. cartCount(){
  212. getCartCount({}).then(res => {
  213. if(res.status == 200){
  214. this.totalNum = res.data?res.data.qty:0
  215. }
  216. })
  217. },
  218. // 加入购物车
  219. addCart(){
  220. if(this.hasLogin){
  221. // 游客未认证
  222. if(this.userInfo.sysUserFlag == '0'){
  223. toAuthStore()
  224. }else{
  225. uni.showLoading({
  226. title: '加入中...',
  227. mask: true
  228. })
  229. // 加入购物车
  230. addCart({
  231. qty: 1,
  232. price: this.detail.price,
  233. productSn: this.detail.productSn
  234. }).then(res => {
  235. if(res.status == 200){
  236. this.cartCount()
  237. uni.hideLoading()
  238. }
  239. })
  240. }
  241. }else{
  242. toLogin()
  243. }
  244. },
  245. // 打开购物车
  246. toCart(){
  247. if(this.hasLogin){
  248. // 游客未认证
  249. if(this.userInfo.sysUserFlag == '0'){
  250. toAuthStore()
  251. }else{
  252. uni.navigateTo({
  253. url: '/pagesB/cart/index'
  254. })
  255. }
  256. }else{
  257. toLogin()
  258. }
  259. },
  260. // 立即购买
  261. toBuy(){
  262. if(this.hasLogin){
  263. // 游客未认证
  264. if(this.userInfo.sysUserFlag == '0'){
  265. toAuthStore()
  266. }else{
  267. if(this.detail.status==0 || this.detail.dealerScopeFlag==0){
  268. uni.showToast({
  269. title: '此商品已'+(this.detail.status==0?'下架':'售罄'),
  270. icon: 'none'
  271. })
  272. }else{
  273. // 打开数量选择弹框
  274. if(!this.showPopu){
  275. this.showPopu = true
  276. }else{
  277. // 提交
  278. this.submitOrder()
  279. }
  280. }
  281. }
  282. }else{
  283. toLogin()
  284. }
  285. },
  286. // 去结算
  287. submitOrder(){
  288. uni.showLoading({
  289. title: '提交中...',
  290. mask: true
  291. })
  292. const _this = this
  293. purchaseCheck({detailList: [{
  294. productSn:this.detail.productSn,
  295. productCode:this.detail.productCode,
  296. qty: this.qty,
  297. price:this.detail.price,
  298. }]}).then(res => {
  299. if(res.status == 200){
  300. const successList = res.data.successList.map(item => {
  301. return {
  302. productSn:item.productSn,
  303. productCode: item.productCode,
  304. qty: item.qty,
  305. price:item.price
  306. }
  307. })
  308. const removeList = res.data.removeList.map(item => item.productCode)
  309. const selloutList = res.data.selloutList.map(item => item.productCode)
  310. // 有已下架或已售罄产品提示
  311. if(removeList.length || selloutList.length){
  312. uni.showModal({
  313. title: '提示',
  314. content: (removeList.length ? `产品${removeList.join(',')}已下架,`:'')+(selloutList.length?`产品${selloutList.join(',')}已售罄,`:'')+`不可采购。`+(successList.length?'是否继续采购其他产品?':''),
  315. showCancel: successList.length,
  316. confirmText: successList.length?'确定':'知道了',
  317. success(ret) {
  318. uni.hideLoading()
  319. if(ret.confirm && successList.length){
  320. _this.submitForm(successList)
  321. }
  322. }
  323. })
  324. }else{
  325. // 直接提交
  326. _this.submitForm(successList)
  327. }
  328. }else{
  329. uni.hideLoading()
  330. uni.showToast({
  331. title: res.message,
  332. icon: 'none'
  333. })
  334. }
  335. })
  336. },
  337. submitForm(detailList){
  338. purchaseSave({
  339. detailList: detailList
  340. }).then(res => {
  341. uni.hideLoading()
  342. if(res.status == 200){
  343. res.data.detailList = []
  344. this.$store.state.vuex_tempData = res.data
  345. this.showPopu = false
  346. this.submitOk = true
  347. }else{
  348. uni.showToast({
  349. title: res.message,
  350. icon: 'none'
  351. })
  352. }
  353. })
  354. },
  355. // 关闭后
  356. closePopu(){
  357. this.showPopu = false
  358. this.qty = 1
  359. uni.hideLoading()
  360. // 提交成功
  361. if(this.submitOk){
  362. uni.navigateTo({
  363. url: "/pagesB/procureOrder"
  364. })
  365. }
  366. },
  367. }
  368. }
  369. </script>
  370. <style lang="less">
  371. .pages {
  372. height: 100vh;
  373. display: flex;
  374. flex-direction: column;
  375. .scrollPage-header{
  376. z-index: 1;
  377. width: 100%;
  378. position:fixed;
  379. left: 0;
  380. top: 0;
  381. .header-title{
  382. display: flex;
  383. align-items: center;
  384. justify-content: space-between;
  385. padding: 0 10px;
  386. height: 44px;
  387. .header-left{
  388. display: flex;
  389. align-items: center;
  390. text{
  391. font-size: 14px;
  392. color: #333333;
  393. }
  394. background-color: rgba(255,255,255,0.6);
  395. box-shadow: 0px 1px 0px 0px #E6E6E6;
  396. border-radius: 50px;
  397. padding: 3px 6px 3px;
  398. }
  399. .header-right{
  400. width: 50px;
  401. }
  402. }
  403. }
  404. .copyText{
  405. background-color: #efefef;
  406. border-radius: 100rpx;
  407. padding: 0 20rpx;
  408. color: #03A9F4;
  409. font-size: 20rpx;
  410. display: inline-block;
  411. margin-left: 20rpx;
  412. height: 44rpx;
  413. line-height: 44rpx;
  414. }
  415. .scrollPage-content{
  416. flex: 1;
  417. overflow-y: auto;
  418. .product-info{
  419. background:#fff;
  420. margin-bottom: 10px;
  421. .product-info-text{
  422. padding: 10px;
  423. .product-info-text-title{
  424. font-weight: bold;
  425. color: #333333;
  426. line-height: 22px;
  427. margin-bottom: 5px;
  428. }
  429. .product-info-text-attr{
  430. display: flex;
  431. align-items: center;
  432. justify-content: space-between;
  433. .product-info-price{
  434. font-size: 14px;
  435. color: #FF0000;
  436. .price-red{
  437. font-size: 24px;
  438. }
  439. }
  440. .product-info-nums{
  441. font-size: 12px;
  442. color: #999999;
  443. >view{
  444. display: flex;
  445. align-items: center;
  446. }
  447. .share{
  448. button{
  449. width: auto;
  450. padding: 0;
  451. border: 0;
  452. background: none;
  453. line-height: normal;
  454. margin: 0;
  455. display: inline;
  456. font-size: 12px;
  457. color: #999;
  458. &::after{
  459. border:none;
  460. }
  461. /deep/ .u-icon{
  462. margin-right: 3px;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. .product-info-guige{
  471. display: flex;
  472. flex-wrap: wrap;
  473. justify-content: space-between;
  474. background:#fff;
  475. margin: 10px 0;
  476. padding: 10px;
  477. line-height: 28px;
  478. .row{
  479. width: 100%;
  480. }
  481. .row-ban{
  482. width: 50%;
  483. }
  484. >view{
  485. color: #999;
  486. text{
  487. color: #333333;
  488. }
  489. }
  490. }
  491. .product-info-content{
  492. background:#fff;
  493. margin-bottom: 10px;
  494. padding: 10px;
  495. line-height: 28px;
  496. }
  497. }
  498. .scrollPage-footer{
  499. background-color: #FFFFFF;
  500. width: 100%;
  501. position: fixed;
  502. left: 0;
  503. bottom: 0;
  504. .scrollPage-footer-box{
  505. display: flex;
  506. align-items: center;
  507. justify-content: space-between;
  508. height: 50px;
  509. }
  510. .footer-left{
  511. display: flex;
  512. align-items: center;
  513. justify-content: space-between;
  514. width: 35%;
  515. .footer-left-item{
  516. display: flex;
  517. flex-direction: column;
  518. align-items: center;
  519. justify-content: center;
  520. padding: 0 15px;
  521. position: relative;
  522. .footer-left-item-text{
  523. font-size: 12px;
  524. color: #666666;
  525. }
  526. .badge{
  527. background: #f44336;
  528. color: #fff;
  529. position: absolute;
  530. right: 5px;
  531. top: -8px;
  532. font-size: 12px;
  533. display: flex;
  534. align-items: center;
  535. justify-content: center;
  536. border-radius: 50rpx;
  537. padding: 0 10rpx;
  538. }
  539. }
  540. }
  541. .footer-right{
  542. width: 60%;
  543. height: 100%;
  544. display: flex;
  545. align-items: center;
  546. .footer-right-item{
  547. height: 100%;
  548. display: flex;
  549. flex-direction: column;
  550. align-items: center;
  551. justify-content: center;
  552. width: 50%;
  553. font-size: 14px;
  554. color: #FFFFFF;
  555. }
  556. .footer-right-item:first-child{
  557. background-color: #FF9900;
  558. }
  559. .footer-right-item:last-child{
  560. background-color: #FF0000;
  561. }
  562. }
  563. }
  564. .popu-content{
  565. display: flex;
  566. flex-direction: column;
  567. align-items: center;
  568. padding: 10px;
  569. .popu-close{
  570. padding: 10px;
  571. position: absolute;
  572. right: 0;
  573. top: 0;
  574. }
  575. .pupu-box{
  576. display: flex;
  577. align-items: center;
  578. justify-content: space-between;
  579. margin-top: 25px;
  580. }
  581. .popu-content-img{
  582. border-radius: 10px;
  583. border: 1px solid #eee;
  584. }
  585. .popu-content-info{
  586. padding: 0 0 0 10px;
  587. .popu-content-info-title{
  588. font-size: 14px;
  589. font-weight: bold;
  590. }
  591. }
  592. .popu-content-box{
  593. display: flex;
  594. align-items: center;
  595. justify-content: space-between;
  596. margin-top: 10px;
  597. .popu-content-price{
  598. font-size: 14px;
  599. color: #d50e0e;
  600. .price-red{
  601. font-size: 24px;
  602. }
  603. }
  604. .popu-content-num{
  605. font-size: 12px;
  606. color: #999999;
  607. padding: 0 10px;
  608. }
  609. }
  610. .popu-content-btn{
  611. width: 100%;
  612. display: flex;
  613. align-items: center;
  614. justify-content: center;
  615. margin-top: 20px;
  616. .popu-content-btn-item{
  617. width: 60%;
  618. height: 40px;
  619. background-color: #f70000;
  620. color: #FFFFFF;
  621. font-size: 14px;
  622. display: flex;
  623. align-items: center;
  624. justify-content: center;
  625. border-radius: 100px;
  626. }
  627. }
  628. }
  629. }
  630. </style>