productDetail.vue 19 KB

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