productDetail.vue 16 KB

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