productDetail.vue 17 KB

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