productDetail.vue 16 KB

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