productDetail.vue 17 KB

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