productDetail.vue 14 KB

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