productDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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" @click="copy(detail.product.origCode)">复制</view></view>
  41. <view class="row">产品编码:<text>{{detail.product.code||'--'}}</text> <view class="copyText" @click="copy(detail.product.origCode)">复制</view></view>
  42. <view class="row">条形码:<text>{{detail.product.qrCode||'--'}}</text> <view class="copyText" @click="copy(detail.product.origCode)">复制</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="99"></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. </view>
  108. </template>
  109. <script>
  110. import {
  111. mapState,
  112. mapMutations,
  113. } from 'vuex'
  114. import { addCart, getCartCount } from '@/api/cart.js'
  115. import { getShopDetail } from '@/api/shop.js'
  116. import { purchaseSave } from '@/api/purchase.js'
  117. export default {
  118. data() {
  119. return {
  120. showPopu: false, // 弹框
  121. statusBarHeight: 0, // 状态栏高度
  122. safeAreaBottom: 0, // 底部安全区域高度
  123. imgList: [],
  124. totalNum: 0 ,// 购物车总数
  125. shopProductSn: null,
  126. detail: null,
  127. qty: 1,// 数量
  128. }
  129. },
  130. onLoad(option) {
  131. // 计算安全区域
  132. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  133. this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
  134. this.shopProductSn = option.sn
  135. // 获取产品详情
  136. this.getDetail()
  137. },
  138. onShow(){
  139. if(this.hasLogin){
  140. // 购物车数量
  141. this.cartCount()
  142. }
  143. },
  144. // 分享
  145. onShareAppMessage(e){
  146. return {
  147. title: this.detail ? this.detail.productName : '商品名称',
  148. path: '/pagesB/shopiing/productDetail?sn='+this.shopProductSn,
  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. },
  160. methods: {
  161. // 返回
  162. goBack(){
  163. uni.navigateBack()
  164. },
  165. // 复制
  166. copy(text){
  167. uni.setClipboardData({
  168. data: text,
  169. })
  170. },
  171. // 产品详情
  172. getDetail(){
  173. uni.showLoading({
  174. title: '加载中'
  175. })
  176. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_storeShelf.dealerSn : ''
  177. // 获取产品详情
  178. getShopDetail({
  179. shopProductSn: this.shopProductSn,
  180. dealerSn: dealerSn
  181. }).then(res => {
  182. if(res.status == 200){
  183. this.detail = res.data
  184. if(res.data && res.data.productPicList){
  185. res.data.productPicList.forEach(item => {
  186. this.imgList.push(item.imageUrl)
  187. })
  188. }else{
  189. this.imgList.push(res.data.productMsg)
  190. }
  191. }
  192. uni.hideLoading()
  193. })
  194. },
  195. // 购物车数量
  196. cartCount(){
  197. getCartCount({}).then(res => {
  198. if(res.status == 200){
  199. this.totalNum = res.data?res.data.qty:0
  200. }
  201. })
  202. },
  203. // 加入购物车
  204. addCart(){
  205. if(this.hasLogin){
  206. uni.showLoading({
  207. title: '加入中...',
  208. mask: true
  209. })
  210. // 加入购物车
  211. addCart({
  212. qty: 1,
  213. price: this.detail.price,
  214. productSn: this.detail.productSn
  215. }).then(res => {
  216. if(res.status == 200){
  217. this.cartCount()
  218. uni.hideLoading()
  219. }
  220. })
  221. }else{
  222. uni.navigateTo({
  223. url: '/pages/login/login'
  224. })
  225. }
  226. },
  227. // 打开购物车
  228. toCart(){
  229. if(this.hasLogin){
  230. uni.navigateTo({
  231. url: '/pagesB/cart/index'
  232. })
  233. }else{
  234. uni.navigateTo({
  235. url: '/pages/login/login'
  236. })
  237. }
  238. },
  239. // 立即购买
  240. toBuy(){
  241. if(this.hasLogin){
  242. if(this.detail.status==0 || this.detail.dealerScopeFlag==0){
  243. uni.showToast({
  244. title: '此商品已'+(this.detail.status==0?'下架':'售罄'),
  245. icon: 'none'
  246. })
  247. }else{
  248. // 打开数量选择弹框
  249. if(!this.showPopu){
  250. this.showPopu = true
  251. }else{
  252. // 提交
  253. this.submitOrder()
  254. }
  255. }
  256. }else{
  257. uni.navigateTo({
  258. url: '/pages/login/login'
  259. })
  260. }
  261. },
  262. // 去结算
  263. submitOrder(){
  264. uni.showLoading({
  265. title: '提交中...',
  266. mask: true
  267. })
  268. const detailList = [{
  269. productSn:this.detail.productSn,
  270. productCode:this.detail.productCode,
  271. qty: this.qty,
  272. price:this.detail.price,
  273. }]
  274. purchaseSave({
  275. detailList: detailList
  276. }).then(res => {
  277. if(res.status == 200){
  278. res.data.detailList = []
  279. this.$store.state.vuex_tempData = res.data
  280. this.showPopu = false
  281. this.submitOk = true
  282. }else{
  283. uni.showToast({
  284. title: res.message,
  285. icon: 'none'
  286. })
  287. }
  288. })
  289. },
  290. // 关闭后
  291. closePopu(){
  292. this.showPopu = false
  293. this.qty = 1
  294. uni.hideLoading()
  295. // 提交成功
  296. if(this.submitOk){
  297. uni.navigateTo({
  298. url: "/pagesB/procureOrder"
  299. })
  300. }
  301. },
  302. }
  303. }
  304. </script>
  305. <style lang="less">
  306. .pages {
  307. height: 100vh;
  308. display: flex;
  309. flex-direction: column;
  310. .scrollPage-header{
  311. z-index: 1;
  312. width: 100%;
  313. position:fixed;
  314. left: 0;
  315. top: 0;
  316. .header-title{
  317. display: flex;
  318. align-items: center;
  319. justify-content: space-between;
  320. padding: 0 10px;
  321. height: 44px;
  322. .header-left{
  323. display: flex;
  324. align-items: center;
  325. text{
  326. font-size: 14px;
  327. color: #333333;
  328. }
  329. background-color: rgba(255,255,255,0.6);
  330. box-shadow: 0px 1px 0px 0px #E6E6E6;
  331. border-radius: 50px;
  332. padding: 3px 6px 3px;
  333. }
  334. .header-right{
  335. width: 50px;
  336. }
  337. }
  338. }
  339. .copyText{
  340. background-color: #efefef;
  341. border-radius: 100rpx;
  342. padding: 0 20rpx;
  343. color: #03A9F4;
  344. font-size: 20rpx;
  345. display: inline-block;
  346. margin-left: 20rpx;
  347. height: 44rpx;
  348. line-height: 44rpx;
  349. }
  350. .scrollPage-content{
  351. flex: 1;
  352. overflow-y: auto;
  353. .product-info{
  354. background:#fff;
  355. margin-bottom: 10px;
  356. .product-info-text{
  357. padding: 10px;
  358. .product-info-text-title{
  359. font-weight: bold;
  360. color: #333333;
  361. line-height: 22px;
  362. margin-bottom: 5px;
  363. }
  364. .product-info-text-attr{
  365. display: flex;
  366. align-items: center;
  367. justify-content: space-between;
  368. .product-info-price{
  369. font-size: 14px;
  370. color: #FF0000;
  371. .price-red{
  372. font-size: 24px;
  373. }
  374. }
  375. .product-info-nums{
  376. font-size: 12px;
  377. color: #999999;
  378. >view{
  379. display: flex;
  380. align-items: center;
  381. }
  382. .share{
  383. button{
  384. width: auto;
  385. padding: 0;
  386. border: 0;
  387. background: none;
  388. line-height: normal;
  389. margin: 0;
  390. display: inline;
  391. font-size: 12px;
  392. color: #999;
  393. &::after{
  394. border:none;
  395. }
  396. /deep/ .u-icon{
  397. margin-right: 3px;
  398. }
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. .product-info-guige{
  406. display: flex;
  407. flex-wrap: wrap;
  408. justify-content: space-between;
  409. background:#fff;
  410. margin: 10px 0;
  411. padding: 10px;
  412. line-height: 28px;
  413. .row{
  414. width: 100%;
  415. }
  416. .row-ban{
  417. width: 50%;
  418. }
  419. >view{
  420. color: #999;
  421. text{
  422. color: #333333;
  423. }
  424. }
  425. }
  426. .product-info-content{
  427. background:#fff;
  428. margin-bottom: 10px;
  429. padding: 10px;
  430. line-height: 28px;
  431. }
  432. }
  433. .scrollPage-footer{
  434. background-color: #FFFFFF;
  435. width: 100%;
  436. position: fixed;
  437. left: 0;
  438. bottom: 0;
  439. .scrollPage-footer-box{
  440. display: flex;
  441. align-items: center;
  442. justify-content: space-between;
  443. height: 50px;
  444. }
  445. .footer-left{
  446. display: flex;
  447. align-items: center;
  448. justify-content: space-between;
  449. width: 35%;
  450. .footer-left-item{
  451. display: flex;
  452. flex-direction: column;
  453. align-items: center;
  454. justify-content: center;
  455. padding: 0 15px;
  456. position: relative;
  457. .footer-left-item-text{
  458. font-size: 12px;
  459. color: #666666;
  460. }
  461. .badge{
  462. background: #f44336;
  463. color: #fff;
  464. position: absolute;
  465. right: 0;
  466. top: -8px;
  467. font-size: 12px;
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. border-radius: 50rpx;
  472. padding: 0 10rpx;
  473. }
  474. }
  475. }
  476. .footer-right{
  477. width: 60%;
  478. height: 100%;
  479. display: flex;
  480. align-items: center;
  481. .footer-right-item{
  482. height: 100%;
  483. display: flex;
  484. flex-direction: column;
  485. align-items: center;
  486. justify-content: center;
  487. width: 50%;
  488. font-size: 14px;
  489. color: #FFFFFF;
  490. }
  491. .footer-right-item:first-child{
  492. background-color: #FF9900;
  493. }
  494. .footer-right-item:last-child{
  495. background-color: #FF0000;
  496. }
  497. }
  498. }
  499. .popu-content{
  500. display: flex;
  501. flex-direction: column;
  502. align-items: center;
  503. padding: 10px;
  504. .popu-close{
  505. padding: 10px;
  506. position: absolute;
  507. right: 0;
  508. top: 0;
  509. }
  510. .pupu-box{
  511. display: flex;
  512. align-items: center;
  513. justify-content: space-between;
  514. margin-top: 25px;
  515. }
  516. .popu-content-img{
  517. border-radius: 10px;
  518. border: 1px solid #eee;
  519. }
  520. .popu-content-info{
  521. padding: 0 0 0 10px;
  522. .popu-content-info-title{
  523. font-size: 14px;
  524. font-weight: bold;
  525. }
  526. }
  527. .popu-content-box{
  528. display: flex;
  529. align-items: center;
  530. justify-content: space-between;
  531. margin-top: 10px;
  532. .popu-content-price{
  533. font-size: 14px;
  534. color: #d50e0e;
  535. .price-red{
  536. font-size: 24px;
  537. }
  538. }
  539. .popu-content-num{
  540. font-size: 12px;
  541. color: #999999;
  542. padding: 0 10px;
  543. }
  544. }
  545. .popu-content-btn{
  546. width: 100%;
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. margin-top: 20px;
  551. .popu-content-btn-item{
  552. width: 50%;
  553. height: 40px;
  554. background-color: #d50e0e;
  555. color: #FFFFFF;
  556. font-size: 14px;
  557. display: flex;
  558. align-items: center;
  559. justify-content: center;
  560. border-radius: 10px;
  561. }
  562. }
  563. }
  564. }
  565. </style>