productDetail.vue 17 KB

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