productDetail.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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. <uni-icons type="arrowleft" size="20"></uni-icons>
  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>{{detail.priceStr[0]}}</text>.{{detail.priceStr[1]}}
  32. </view>
  33. <view class="flex align_center rebate-tag" v-if="detail.promoType=='BUY_PROD_GIVE_VALID'">
  34. 返<text>{{detail.resultValue}}</text>元
  35. </view>
  36. <view class="flex align_center rebate-tag" v-if="detail.promoType=='BUY_PROD_GIVE_PROD'">
  37. 买{{detail.conditionValue}}赠{{detail.resultValue}}
  38. </view>
  39. <view class="flex align_center tejia-tag" v-if="detail.promoType=='PROMO_PROD'">
  40. 特价<text>¥{{detail.orginPrice}}</text>
  41. </view>
  42. <view class="flex align_center rebate-tag" v-if="detail.shopProductSubsidy&&!detail.shopPromoProduct">
  43. 可抵扣<text>¥{{detail.shopProductSubsidy.subsidyAmount}}</text>
  44. </view>
  45. </view>
  46. <view class="product-info-nums">
  47. <view class="share">
  48. <button open-type="share"><u-icon :size='24' name="zhuanfa"></u-icon> 分享</button>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <u-divider bg-color="">商品详情</u-divider>
  55. <view class="product-info-guige" v-if="detail&&detail.product">
  56. <view class="row">品牌:<text>{{detail.product.productBrandName||'--'}}</text></view>
  57. <view class="row">原厂编码:<text>{{detail.product.origCode||'--'}} </text> <view class="copyText" v-if="detail.product.origCode" @click="copy(detail.product.origCode)">复制</view></view>
  58. <view class="row">产品编码:<text>{{detail.product.code||'--'}}</text> <view class="copyText" v-if="detail.product.code" @click="copy(detail.product.code)">复制</view></view>
  59. <view class="row">条形码:<text>{{detail.product.qrCode||'--'}}</text> <view class="copyText" v-if="detail.product.qrCode" @click="copy(detail.product.qrCode)">复制</view></view>
  60. <view class="row">商品尺寸:<text>{{detail.product.size||'--'}}</text></view>
  61. <view class="row-ban">计量单位:<text>{{detail.product.unit||'--'}}</text></view>
  62. <view class="row-ban">重量:<text>{{detail.product.weight||'--'}}</text></view>
  63. <view class="row-ban">包装数:<text>{{ (detail.product.packQty) || '--' }}{{ detail.product.packQty ? detail.product.unit : '' }}/{{ detail.product.packQtyUnit||'--' }}</text></view>
  64. </view>
  65. <view class="flex align_center row-info">
  66. <view class="flex"><u-icon :size='24' name="checkbox-mark"></u-icon> <view class="txt">由汽配商发货</view></view>
  67. <view class="flex"><u-icon :size='24' name="checkbox-mark"></u-icon> <view class="txt">退换货及售后请联系汽配商</view></view>
  68. </view>
  69. <view class="product-info-content">
  70. <rich-text v-if="detail && detail.product && detail.product.description" :nodes="detail.product.description"></rich-text>
  71. <view v-else style="font-size: 12px;color: #999;text-align: center;">暂无产品介绍</view>
  72. </view>
  73. </view>
  74. <!-- 底部栏 -->
  75. <view class="scrollPage-footer">
  76. <view class="scrollPage-footer-box">
  77. <view class="footer-left">
  78. <view v-if="isShare" class="footer-left-item" @click="goBack">
  79. <u-icon :size='50' color="#666" name="home"></u-icon>
  80. <text class="footer-left-item-text">首页</text>
  81. </view>
  82. <view class="footer-left-item" @click="toCart">
  83. <u-icon :size='50' color="#666" name="shopping-cart"></u-icon>
  84. <text class="footer-left-item-text">购物车</text>
  85. <text class="badge" v-if="totalNum">{{totalNum>99?'99+':totalNum}}</text>
  86. </view>
  87. </view>
  88. <view class="footer-right">
  89. <view class="footer-right-item" @click="toAddCart">
  90. <text>加入购物车</text>
  91. </view>
  92. <view class="footer-right-item" @click="toBuy">
  93. <text>立即购买</text>
  94. </view>
  95. </view>
  96. </view>
  97. <view :style="{height:safeAreaBottom+'px'}"></view>
  98. </view>
  99. <!-- 购物车动画 -->
  100. <uni-cart-animation ref="cartAnimation" @animationfinish="animationfinish"></uni-cart-animation>
  101. <!-- 立即购买和付款 -->
  102. <page-container
  103. :show="showPopu"
  104. :round="true"
  105. :z-index="100"
  106. position="bottom"
  107. customStyle="border-radius:15px 15px 0 0;"
  108. @beforeleave="beforeClosePopu"
  109. @afterleave="closePopu">
  110. <!-- 确认订单 -->
  111. <view class="popu-content" v-if="detail&&!showPay">
  112. <view class="popu-close" @click="cancelBuy">
  113. <uni-icons size="26" type="closeempty"></uni-icons>
  114. </view>
  115. <view class="pupu-box">
  116. <view class="popu-content-img">
  117. <image style="width: 80px; height: 80px;" mode="aspectFit" :src="detail.productMsg||'/static/def_imgs.png'"></image>
  118. </view>
  119. <view class="popu-content-info">
  120. <view class="popu-content-info-title">
  121. <text class="ellipsis-two">{{detail.productName}}</text>
  122. </view>
  123. <view class="popu-content-info-code">
  124. <text class="ellipsis-two">{{detail.product.code}}</text>
  125. </view>
  126. <view class="popu-content-box">
  127. <view class="popu-content-price" v-if="hasLogin">
  128. ¥<text>{{detail.priceStr[0]}}</text>.{{detail.priceStr[1]}}
  129. </view>
  130. <view class="popu-content-price" v-else>¥***</view>
  131. <view class="flex align_center rebate-tag" v-if="hasLogin&&detail.promoType=='BUY_PROD_GIVE_VALID'">
  132. 返<text>{{detail.resultValue}}</text>元
  133. </view>
  134. <view class="flex align_center rebate-tag" v-if="hasLogin&&detail.promoType=='BUY_PROD_GIVE_PROD'">
  135. 买{{detail.conditionValue}}赠{{detail.resultValue}}
  136. </view>
  137. <view class="flex align_center tejia-tag" v-if="hasLogin&&detail.promoType=='PROMO_PROD'">
  138. 特价<text>¥{{detail.orginPrice}}</text>
  139. </view>
  140. <view class="flex align_center rebate-tag"
  141. v-if="hasLogin&&detail.shopProductSubsidy&&detail.shopProductSubsidy.subsidyAmount<detail.price&&!detail.shopPromoProduct">
  142. 可抵扣<text>¥{{detail.shopProductSubsidy.subsidyAmount}}</text>
  143. </view>
  144. </view>
  145. <view style="margin-top: 10px;" class="popu-content-num flex align_center justify_end">
  146. <text>数量</text>
  147. <view class="flex align_center qty-box">
  148. <view class="qty-btn" @click="changeQty(qty-1)" :class="(qty <= 1)?'qty-disabled':''">-</view>
  149. <view class="qty-num" @click="$refs.showPopu.open()" :style="{width:Number(qty).toString().length*8+10+'px'}">
  150. {{qty}}
  151. </view>
  152. <view class="qty-btn" @click="changeQty(qty+1)" :class="(qty >= 999)?'qty-disabled':''">+</view>
  153. </view>
  154. </view>
  155. </view>
  156. </view>
  157. <view class="pupu-box gift-box" v-if="giftNum">
  158. <view class="popu-content-img">
  159. <image style="width: 58px; height: 58px;" mode="aspectFit" :src="detail.productMsg||'/static/def_imgs.png'"></image>
  160. </view>
  161. <view class="popu-content-info">
  162. <view class="popu-content-info-title flex align_center">
  163. <view class="flex align_center rebate-tag">
  164. 赠品
  165. </view>
  166. <view class="ellipsis-two">{{detail.productName}}</view>
  167. </view>
  168. <view class="popu-content-box">
  169. <view class="popu-content-num flex align_center">
  170. <text>X</text> {{giftNum}}
  171. </view>
  172. </view>
  173. </view>
  174. </view>
  175. <view class="pupu-box-item">
  176. <view class="flex align_center justify_between" v-if="shelfInfo">
  177. <text>配送商:{{shelfInfo.dealerName}}</text>
  178. <view @click="callPhone()"><uni-icons size="18" type="phone" color="dodgerblue"></uni-icons><text style="font-size:12px;">拨打</text></view>
  179. </view>
  180. <view v-if="hasBalancePay&&!isAddCart">
  181. <view class="totalBar-box">
  182. <view class="flex align_center justify_between">
  183. <view>总金额</view>
  184. <view><text class="pf">¥</text>{{totalAmount}}</view>
  185. </view>
  186. <view class="flex align_center justify_between">
  187. <view v-if="storeAccount">抵扣(余额:<text class="pf">¥</text>{{storeAccount.giveBalance}})</view>
  188. <view class="flex align_center" v-if="!disKdk" @click="hasKdk=!hasKdk">
  189. <uni-icons size="18" :type="hasKdk?'checkbox-filled':'checkbox'" color="#2196f3"></uni-icons>
  190. <text class="pf">¥</text>{{detail.shopProductSubsidy.subsidyAmount}}
  191. </view>
  192. <view class="flex align_center" v-else>
  193. <text class="pf">¥</text>{{detail.shopProductSubsidy.subsidyAmount}}
  194. </view>
  195. </view>
  196. <view class="flex align_center justify_end" v-if="detail.shopProductSubsidy">
  197. <view>合计:</view>
  198. <view><text class="pf">¥</text>{{payAmount}}</view>
  199. </view>
  200. </view>
  201. <payOptions v-model="payType" :hasBalancePay="hasBalancePay" :hasPay="hasPay" @change="v=>hasKdk=v!=2" :balance="storeAccount?storeAccount.rechargeBalance:0"></payOptions>
  202. </view>
  203. </view>
  204. <view class="popu-content-btn">
  205. <view class="popu-content-btn-item cartbtn" v-if="isAddCart" @click="submitCart($event)">加入购物车</view>
  206. <view class="popu-content-btn-item okbtn" v-if="!isAddCart" @click="toBuy">
  207. {{hasPay?'立即支付':'确定采购'}}
  208. <text class="payAmount">¥{{payAmount}}</text>
  209. </view>
  210. </view>
  211. </view>
  212. <!-- 确认付款 -->
  213. <view class="popu-content" v-if="payInfo&&showPay&&payData">
  214. <view class="popu-close" @click="cancelPay">
  215. <uni-icons size="26" type="closeempty"></uni-icons>
  216. </view>
  217. <view class="pupu-box-pay-item">
  218. <view class="popu-content-amount flex align_center justify_center">
  219. <view>¥{{payInfo.totalAmount}}</view>
  220. </view>
  221. <view class="flex align_center justify_between" v-if="payInfo.totalSpecialGiveAmount>0">
  222. <text>总优惠</text>
  223. <view class="popu-content-price">¥{{payInfo.totalSpecialGiveAmount}}</view>
  224. </view>
  225. <view class="flex align_center justify_between" v-if="payInfo.totalTicketGiveAmount>0">
  226. <text>代金券</text>
  227. <view class="popu-content-price">¥{{payInfo.totalTicketGiveAmount}}</view>
  228. </view>
  229. <view style="height: 10px;"></view>
  230. <view class="popu-content-title flex align_center justify_between">
  231. <text>付款方式</text>
  232. <view></view>
  233. </view>
  234. <view class="popu-content-pay flex align_center justify_between">
  235. <view class="flex align_center">
  236. <uni-icons size="20" type="weixin" color="#4CAF50"></uni-icons>
  237. <text style="margin-left: 5px;">微信支付</text>
  238. </view>
  239. <view><uni-icons size="22" type="checkbox-filled" color="#2196f3"></uni-icons></view>
  240. </view>
  241. </view>
  242. <view class="popu-content-btn">
  243. <view class="popu-content-btn-item okbtn" @click="confirmPay">确定付款</view>
  244. </view>
  245. </view>
  246. </page-container>
  247. <!-- 修改数量弹框 -->
  248. <uni-popup ref="showPopu" type="center" style="z-index: 1500;" :maskClick="false">
  249. <view class="popu-nums-content">
  250. <view class="popu-close" @click="$refs.showPopu.close()">
  251. <uni-icons size="26" type="closeempty"></uni-icons>
  252. </view>
  253. <view class="popu-content-title flex align_center justify_center"><text>修改商品数量</text></view>
  254. <view class="popu-content-num flex align_center justify_center">
  255. <uni-number-box v-model="qty" :size="28" :input-width="280" :input-height="70" :min="1" :max="999"></uni-number-box>
  256. </view>
  257. <view class="popu-content-btn">
  258. <view class="popu-content-btn-item okbtn" @click="$refs.showPopu.close()">确定</view>
  259. </view>
  260. </view>
  261. </uni-popup>
  262. </view>
  263. </template>
  264. <script>
  265. import {
  266. mapState,
  267. mapMutations,
  268. } from 'vuex'
  269. import { addCart, getCartCount } from '@/api/cart.js'
  270. import { getShopDetail } from '@/api/shop.js'
  271. import { purchaseSave, purchaseCheck, purchasePay } from '@/api/purchase.js'
  272. import { toAuthStore, toLogin } from "@/utils/index.js"
  273. import payOptions from '../components/payOptions.vue'
  274. export default {
  275. components: {
  276. payOptions
  277. },
  278. data() {
  279. return {
  280. loading: false,
  281. showPopu: false, // 弹框
  282. statusBarHeight: 0, // 状态栏高度
  283. safeAreaBottom: 0, // 底部安全区域高度
  284. imgList: [],
  285. shopProductSn: null,
  286. detail: null,
  287. qty: 1,// 数量
  288. isShare: false ,// 是否从分享打开的
  289. busPos:{
  290. x: 10,
  291. y:uni.getSystemInfoSync().windowHeight - 30
  292. },
  293. submitOk: false, // 是否成功
  294. cacelOk: false, // 是否取消
  295. refashOk: false, // 是否刷新页面
  296. showPay: false, // 是否显示付款信息
  297. isAddCart: false, // 是否加入购物车
  298. payData: null, // 支付参数
  299. payType: 0, // 支付方式,0抵扣、1微信,2线下
  300. hasKdk: false,
  301. }
  302. },
  303. onLoad(option) {
  304. this.isShare = !!option.share
  305. // 计算安全区域
  306. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  307. this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
  308. this.shopProductSn = option.sn
  309. // 获取产品详情
  310. this.getDetail()
  311. },
  312. // 分享
  313. onShareAppMessage(e){
  314. return {
  315. title: this.detail ? this.detail.productName : '商品名称',
  316. path: '/pagesB/shopiing/productDetail?sn='+this.shopProductSn+'&share=1',
  317. imageUrl:this.detail ? this.detail.productMsg : '',
  318. type: '1'
  319. }
  320. },
  321. computed: {
  322. ...mapState(['hasLogin']),
  323. // 登录用户信息
  324. userInfo(){
  325. return this.$store.state.vuex_userInfo
  326. },
  327. // 货架经销商信息
  328. shelfInfo(){
  329. return this.$store.state.vuex_storeShelf
  330. },
  331. //是否开启线上支付,支付方式不是线下支付
  332. hasPay(){
  333. const shelfInfo = this.shelfInfo
  334. return shelfInfo&&shelfInfo.payOnlineFlag&&shelfInfo.payOnlineFlag=='1'&&this.payType!=2
  335. },
  336. // 最小支付金额
  337. minPayAmount(){
  338. const shelfInfo = this.shelfInfo
  339. return shelfInfo&&shelfInfo.minAmount ? shelfInfo.minAmount : 0
  340. },
  341. // 抵扣余额支付是否可用,有【余额支付权限】且该产品有抵扣金额
  342. hasBalancePay(){
  343. return this.$store.state.vuex_showBalanceAuth&&this.storeAccount.giveBalance&&this.detail&&!this.detail.shopPromoProduct
  344. },
  345. storeAccount(){
  346. return this.$store.state.vuex_storeAccount
  347. },
  348. // 禁用抵扣金额
  349. disKdk(){
  350. const kdk = this.detail&&this.detail.shopProductSubsidy&&this.storeAccount&&this.detail.shopProductSubsidy.subsidyAmount>0&&this.detail.shopProductSubsidy.subsidyAmount<this.storeAccount.giveBalance
  351. return this.payType==2 || !kdk
  352. },
  353. // 经销商电话
  354. dealerPhone(){
  355. const shelfInfo = this.shelfInfo
  356. return shelfInfo&&shelfInfo.contactMobile ? shelfInfo.contactMobile : ''
  357. },
  358. totalNum(){
  359. return this.hasLogin&&this.userInfo.sysUserFlag == '1' ? this.$store.state.vuex_cartTotal : 0
  360. },
  361. // 总金额
  362. totalAmount(){
  363. return this.hasLogin&&this.detail&&this.detail.price * this.qty
  364. },
  365. // 支付合计,结算金额
  366. payAmount(){
  367. return Number(this.totalAmount-(this.hasKdk&&this.detail&&this.detail.shopProductSubsidy?this.detail.shopProductSubsidy.subsidyAmount:0)).toFixed(2)
  368. },
  369. // 赠品数量
  370. giftNum(){
  371. return this.detail && this.detail.promoType=='BUY_PROD_GIVE_PROD' ? Math.floor(this.qty / this.detail.conditionValue)*this.detail.resultValue : 0
  372. },
  373. // 付款信息
  374. payInfo(){
  375. return this.$store.state.vuex_tempOrderData
  376. }
  377. },
  378. methods: {
  379. // 返回
  380. goBack(){
  381. if(this.isShare){
  382. uni.reLaunch({
  383. url: '/pages/index/index'
  384. })
  385. }else{
  386. uni.navigateBack()
  387. }
  388. },
  389. // 复制
  390. copy(text){
  391. uni.setClipboardData({
  392. data: text,
  393. success: function () {
  394. uni.showToast({
  395. title: '复制成功'
  396. })
  397. }
  398. })
  399. },
  400. viewImg(index){
  401. uni.previewImage({
  402. urls: this.imgList
  403. })
  404. },
  405. // 联系经销商
  406. callPhone() {
  407. if(this.dealerPhone!=''){
  408. uni.makePhoneCall({
  409. phoneNumber: this.dealerPhone
  410. })
  411. }
  412. },
  413. // 产品详情
  414. getDetail(){
  415. uni.showLoading({
  416. title: '加载中'
  417. })
  418. const storeShelf = this.$store.state.vuex_storeShelf
  419. const dealerSn = this.hasLogin && this.userInfo && this.userInfo.sysUserFlag == '1'&&storeShelf ? storeShelf.dealerSn : ''
  420. // 获取产品详情
  421. getShopDetail({
  422. shopProductSn: this.shopProductSn,
  423. dealerSn: dealerSn
  424. }).then(res => {
  425. if(res.status == 200){
  426. this.detail = res.data
  427. if(res.data){
  428. if(res.data.productPicList){
  429. res.data.productPicList.forEach(item => {
  430. this.imgList.push(item.imageUrl||'/static/def_imgs.png')
  431. })
  432. }else{
  433. this.imgList.push(res.data.productMsg||'/static/def_imgs.png')
  434. }
  435. const a = res.data.shopPromoProduct
  436. let bprice = res.data.price
  437. if(a){
  438. res.data.promoType = a.promoType
  439. res.data.resultValue = a.resultValue
  440. res.data.conditionValue = a.conditionValue
  441. res.data.discountType = a.discountType
  442. res.data.promoProductSn = a.promoProductSn
  443. res.data.promoSn = a.promoSn
  444. res.data.orginPrice = res.data.price
  445. // 特价
  446. if(res.data.promoType=='PROMO_PROD'){
  447. bprice =res.data.conditionValue
  448. }
  449. }
  450. res.data.priceStr = Number(bprice).toFixed(2).toString().split('.')
  451. // 可抵扣金额小于抵扣金额且大于0
  452. const kdk = res.data.shopProductSubsidy&&res.data.shopProductSubsidy.subsidyAmount>0&&res.data.shopProductSubsidy.subsidyAmount<this.storeAccount.giveBalance
  453. this.hasKdk = kdk
  454. }
  455. }
  456. uni.hideLoading()
  457. })
  458. },
  459. animationfinish(){
  460. this.loading = false
  461. },
  462. changeQty(value) {
  463. const max = 999
  464. const v = value > max ? max : (value==''||value==0?1:value)
  465. this.qty = v
  466. },
  467. // 加入购物车
  468. toAddCart(){
  469. // 未登录
  470. if(this.hasLogin){
  471. // 游客未认证
  472. if(this.userInfo.sysUserFlag == '0'){
  473. toAuthStore()
  474. }else{
  475. // 打开确认数量弹框
  476. this.isAddCart = true
  477. this.showPopu = true
  478. }
  479. }else{
  480. toLogin()
  481. }
  482. },
  483. // 确定加入购物车
  484. submitCart(event){
  485. if(this.loading){
  486. return
  487. }
  488. this.loading = true
  489. this.$refs.cartAnimation.touchOnGoods(event,this.busPos);
  490. // 加入购物车
  491. addCart({
  492. qty: this.qty,
  493. price: this.detail.price,
  494. productSn: this.detail.productSn
  495. }).then(res => {
  496. if(res.status == 200){
  497. uni.$emit('refashCart')
  498. this.showPopu = false
  499. }
  500. })
  501. },
  502. // 打开购物车页面
  503. toCart(){
  504. if(this.hasLogin){
  505. // 游客未认证
  506. if(this.userInfo.sysUserFlag == '0'){
  507. toAuthStore()
  508. }else{
  509. uni.navigateTo({
  510. url: '/pagesB/cart/index'
  511. })
  512. }
  513. }else{
  514. toLogin()
  515. }
  516. },
  517. // 立即购买
  518. toBuy(){
  519. if(this.hasLogin){
  520. // 游客未认证
  521. if(this.userInfo.sysUserFlag == '0'){
  522. toAuthStore()
  523. }else{
  524. if(this.detail.status==0 || this.detail.dealerScopeFlag==0){
  525. uni.showModal({
  526. content: '此商品已'+(this.detail.status==0?'下架':'售罄'),
  527. showCancel:false,
  528. confirmText:'知道了'
  529. })
  530. }else{
  531. // 打开数量选择弹框
  532. if(!this.showPopu){
  533. this.showPopu = true
  534. this.payType = this.hasBalancePay ? 0 : (this.hasPay ? 1 : 2)
  535. this.hasKdk = this.detail.shopProductSubsidy&&this.detail.shopProductSubsidy.subsidyAmount>0&&this.detail.shopProductSubsidy.subsidyAmount<this.storeAccount.giveBalance
  536. }else{
  537. if(this.hasPay && this.minPayAmount>this.payAmount){
  538. uni.showModal({
  539. content: '支付金额不能小于'+this.minPayAmount+'元!',
  540. showCancel:false,
  541. confirmText:'知道了'
  542. })
  543. }else{
  544. // 去结算生产订单
  545. this.creatOrder()
  546. }
  547. }
  548. }
  549. }
  550. }else{
  551. toLogin()
  552. }
  553. },
  554. // 取消立即购买
  555. cancelBuy(){
  556. this.resetPage()
  557. },
  558. // 去结算
  559. creatOrder(){
  560. uni.showLoading({
  561. title: '提交中...',
  562. mask: true
  563. })
  564. const _this = this
  565. purchaseCheck({detailList: [{
  566. productSn:this.detail.productSn,
  567. productCode:this.detail.productCode,
  568. qty: this.qty,
  569. price:this.detail.price,
  570. promoSn: this.detail.promoSn
  571. }]}).then(res => {
  572. uni.hideLoading()
  573. if(res.status == 200){
  574. const successList = res.data.successList ? res.data.successList.map(item => {
  575. return {
  576. productSn:item.productSn,
  577. productCode: item.productCode,
  578. qty: item.qty,
  579. price:item.price,
  580. promoSn: item.promoSn
  581. }
  582. }) : []
  583. const removeList = res.data.removeList ? res.data.removeList.map(item => item.productCode) : []
  584. const selloutList = res.data.selloutList ? res.data.selloutList.map(item => item.productCode) : []
  585. // 有已下架或已售罄产品提示
  586. if(removeList.length || selloutList.length){
  587. uni.showModal({
  588. title: '提示',
  589. content: (removeList.length ? `产品${removeList.join(',')}已下架,`:'')+(selloutList.length?`产品${selloutList.join(',')}已售罄,`:'')+`不可采购。`+(successList.length?'是否继续采购其他产品?':''),
  590. showCancel: successList.length,
  591. confirmText: successList.length?'确定':'知道了',
  592. success(ret) {
  593. if(ret.confirm && successList.length){
  594. _this.submitForm(successList)
  595. }
  596. }
  597. })
  598. }else{
  599. const promoChangeFlag = res.data.promoChangeFlag
  600. // 活动变更
  601. if(promoChangeFlag){
  602. uni.showModal({
  603. title: '提示',
  604. content: '促销活动已变更,请刷新?',
  605. confirmText:'确定刷新',
  606. success(ret) {
  607. if(ret.confirm){
  608. _this.showPopu = false
  609. _this.refashOk = true
  610. }
  611. }
  612. })
  613. return
  614. }
  615. // 直接提交
  616. _this.submitForm(successList)
  617. }
  618. }else{
  619. uni.showToast({
  620. title: res.message,
  621. icon: 'none'
  622. })
  623. }
  624. })
  625. },
  626. // 创建订单
  627. submitForm(detailList){
  628. uni.showLoading({
  629. title: '提交中...',
  630. mask: true
  631. })
  632. purchaseSave({
  633. detailList: detailList
  634. }).then(res => {
  635. if(res.status == 200){
  636. res.data.detailList = []
  637. this.$store.state.vuex_tempOrderData = res.data
  638. // 这里判断是否开通支付,如果开通打开确认付款弹框
  639. if(this.hasPay){
  640. // 计算待付款剩余倒计时
  641. res.data.timestamp = (new Date(res.data.createDate.replace(/-/g,'/')).getTime() + 1800000 - new Date().getTime())/1000
  642. purchasePay({
  643. bizSn:res.data.purchaseSn,
  644. bizNo:res.data.purchaseNo,
  645. bizType:'SETTLE_BILL',
  646. payUserOpenId: this.$store.state.vuex_openid || uni.getStorageSync('openid'),
  647. settleType: this.payType == 0 ? 'RECHARGE_BALANCE' : 'WXPAY_ONLINE'
  648. }).then(res=>{
  649. // 微信支付
  650. if(this.payType == 1){
  651. this.showPay = true
  652. this.payData = res.data?res.data.payRequestRest:null
  653. }else{
  654. // 余额支付
  655. this.showPay = true
  656. this.showPopu = false
  657. this.submitOk = true
  658. }
  659. uni.hideLoading()
  660. })
  661. }else{
  662. // 未开通支付,创建成功,跳转到订单详情页
  663. this.showPopu = false
  664. this.submitOk = true
  665. uni.hideLoading()
  666. }
  667. }else{
  668. uni.hideLoading()
  669. uni.showToast({
  670. title: res.message,
  671. icon: 'none'
  672. })
  673. }
  674. })
  675. },
  676. // 关闭之前
  677. beforeClosePopu(){
  678. console.log(this.showPay,this.submitOk,this.cacelOk)
  679. // 正在支付
  680. if(this.showPay&&!this.submitOk&&!this.cacelOk){
  681. this.showPay = false
  682. this.cancelPay()
  683. }
  684. },
  685. // 关闭确定订单弹窗后
  686. closePopu(){
  687. this.showPopu = false
  688. // 刷新页面
  689. if(this.refashOk){
  690. this.qty = 1
  691. this.getDetail()
  692. }else{
  693. // 开通了支付
  694. if(this.hasPay){
  695. // 付款
  696. if(this.showPay){
  697. // 确定取消付款或付款失败
  698. if(this.cacelOk){
  699. this.cacelOk = false
  700. }
  701. // 确定付款成功
  702. if(this.submitOk){
  703. this.submitOk = false
  704. }
  705. // 去订单详情页
  706. this.toOrderDetial()
  707. }else{
  708. // 取消立即购买
  709. this.resetPage()
  710. }
  711. }else{
  712. // 未开通支付
  713. // 去订单详情页
  714. if(this.submitOk){
  715. this.submitOk = false
  716. this.toOrderDetial()
  717. }else{
  718. // 取消采购
  719. this.resetPage()
  720. }
  721. }
  722. }
  723. },
  724. // 确认付款
  725. confirmPay(){
  726. const _this = this
  727. // 确认付款
  728. const data = _this.payData
  729. console.log(data)
  730. if(data){
  731. uni.requestPayment({
  732. provider: 'wxpay',
  733. timeStamp: data.timeStamp,
  734. nonceStr: data.nonceStr,
  735. package: data.package,
  736. signType: data.signType,
  737. paySign: data.paySign,
  738. success: (res) =>{
  739. _this.payComplete(1,true)
  740. },
  741. fail: (err)=> {
  742. console.log('fail:',err);
  743. _this.payComplete(err.errMsg.indexOf("cancel")>=0 ? 2 : 0,false)
  744. }
  745. });
  746. }else{
  747. _this.payComplete(0,false)
  748. }
  749. },
  750. payComplete(type,data){
  751. uni.showToast({
  752. mask: true,
  753. title: type==1 ? '支付成功' : (type==2?'支付取消':'支付失败'),
  754. icon: 'none'
  755. })
  756. this.showPopu = false
  757. this.submitOk = true
  758. },
  759. // 确认取消付款弹框
  760. cancelPay(){
  761. const _this = this
  762. uni.showModal({
  763. title: '确定取消支付吗?',
  764. content: '您的订单在30分钟内未支付将被取消,请尽快完成支付。',
  765. confirmText: '继续支付',
  766. cancelText: '取消支付',
  767. success(ret) {
  768. // 确定取消,跳转到订单详情页
  769. if(ret.cancel){
  770. // 支付弹框打开中
  771. if(_this.showPopu){
  772. console.log(0)
  773. _this.showPopu = false
  774. _this.cacelOk = true
  775. }else{
  776. console.log(1)
  777. // 未打开直接跳转
  778. _this.toOrderDetial()
  779. }
  780. }
  781. if(ret.confirm){
  782. console.log(2)
  783. // 继续支付
  784. _this.showPopu = true
  785. _this.showPay = true
  786. _this.cacelOk = false
  787. }
  788. }
  789. })
  790. },
  791. // 重置页面
  792. resetPage(){
  793. this.qty = 1
  794. this.isAddCart = false
  795. this.showPopu = false
  796. this.showPay = false
  797. this.cacelOk = false
  798. this.submitOk = false
  799. setTimeout(()=>{
  800. uni.hideLoading()
  801. },300)
  802. },
  803. // 订单详情页
  804. toOrderDetial(){
  805. this.resetPage()
  806. // 跳转到订单详情页面
  807. uni.navigateTo({
  808. url: "/pagesB/procureOrder/orderDetail?purchaseSn="+this.$store.state.vuex_tempOrderData.purchaseSn
  809. })
  810. }
  811. }
  812. }
  813. </script>
  814. <style lang="less">
  815. .pages {
  816. height: 100vh;
  817. display: flex;
  818. flex-direction: column;
  819. .scrollPage-header{
  820. z-index: 1;
  821. width: 100%;
  822. position:fixed;
  823. left: 0;
  824. top: 0;
  825. .header-title{
  826. display: flex;
  827. align-items: center;
  828. justify-content: space-between;
  829. padding: 0 10px;
  830. height: 44px;
  831. .header-left{
  832. display: flex;
  833. align-items: center;
  834. text{
  835. font-size: 14px;
  836. color: #333333;
  837. }
  838. background-color: rgba(255,255,255,0.6);
  839. box-shadow: 0px 1px 0px 0px #E6E6E6;
  840. border-radius: 50px;
  841. padding: 3px 6px 3px;
  842. }
  843. .header-right{
  844. width: 50px;
  845. }
  846. }
  847. }
  848. .copyText{
  849. background-color: #efefef;
  850. border-radius: 100rpx;
  851. padding: 0 20rpx;
  852. color: #03A9F4;
  853. font-size: 20rpx;
  854. display: inline-block;
  855. margin-left: 20rpx;
  856. height: 44rpx;
  857. line-height: 44rpx;
  858. }
  859. .scrollPage-content{
  860. flex: 1;
  861. overflow-y: auto;
  862. .product-info{
  863. background:#fff;
  864. margin-bottom: 10px;
  865. .product-info-text{
  866. padding: 10px;
  867. .product-info-text-title{
  868. font-weight: bold;
  869. color: #333333;
  870. line-height: 22px;
  871. margin-bottom: 5px;
  872. }
  873. .product-info-text-attr{
  874. display: flex;
  875. align-items: center;
  876. justify-content: space-between;
  877. .product-info-price{
  878. color: red;
  879. display: flex;
  880. align-items: baseline;
  881. font-size: 12px;
  882. text{
  883. font-size: 38rpx;
  884. }
  885. }
  886. .product-info-nums{
  887. font-size: 12px;
  888. color: #999999;
  889. >view{
  890. display: flex;
  891. align-items: center;
  892. }
  893. .share{
  894. button{
  895. width: auto;
  896. padding: 0;
  897. border: 0;
  898. background: none;
  899. line-height: normal;
  900. margin: 0;
  901. display: inline;
  902. font-size: 12px;
  903. color: #999;
  904. &::after{
  905. border:none;
  906. }
  907. ::v-deep .u-icon{
  908. margin-right: 3px;
  909. }
  910. }
  911. }
  912. }
  913. }
  914. }
  915. }
  916. .product-info-guige{
  917. display: flex;
  918. flex-wrap: wrap;
  919. justify-content: space-between;
  920. background:#fff;
  921. margin: 10px 0 0;
  922. padding: 10px;
  923. line-height: 28px;
  924. .row{
  925. width: 100%;
  926. }
  927. .row-ban{
  928. width: 50%;
  929. }
  930. >view{
  931. color: #999;
  932. text{
  933. color: #333333;
  934. }
  935. }
  936. }
  937. .row-info{
  938. width: 100%;
  939. background: #fff;
  940. font-size: 24rpx;
  941. text-align: center;
  942. margin: 20rpx 0;
  943. padding: 15rpx;
  944. .txt{
  945. margin-left: 10rpx;
  946. color: #666;
  947. font-weight: bold;
  948. }
  949. > view{
  950. padding: 0 10px;
  951. }
  952. }
  953. .product-info-content{
  954. background:#fff;
  955. margin-bottom: 10px;
  956. padding: 10px;
  957. line-height: 28px;
  958. }
  959. }
  960. .rebate-tag{
  961. background: #ffe7df;
  962. color: #E91E63;
  963. padding: 2px 5px;
  964. font-size: 10px;
  965. border-radius: 3px;
  966. margin-left: 6px;
  967. }
  968. .tejia-tag{
  969. color: #E91E63;
  970. margin-left: 6px;
  971. font-size: 12px;
  972. text{
  973. font-size: 12px;
  974. color: #999;
  975. margin-left: 5px;
  976. text-decoration: line-through;
  977. }
  978. }
  979. .scrollPage-footer{
  980. background-color: #FFFFFF;
  981. width: 100%;
  982. position: fixed;
  983. left: 0;
  984. bottom: 0;
  985. .scrollPage-footer-box{
  986. display: flex;
  987. align-items: center;
  988. justify-content: space-between;
  989. height: 45px;
  990. }
  991. .footer-left{
  992. display: flex;
  993. align-items: center;
  994. justify-content: space-between;
  995. width: 35%;
  996. .footer-left-item{
  997. display: flex;
  998. flex-direction: column;
  999. align-items: center;
  1000. justify-content: center;
  1001. padding: 0 15px;
  1002. position: relative;
  1003. .footer-left-item-text{
  1004. font-size: 12px;
  1005. color: #666666;
  1006. }
  1007. .badge{
  1008. background: #f44336;
  1009. color: #fff;
  1010. position: absolute;
  1011. right: 5px;
  1012. top: -8px;
  1013. font-size: 12px;
  1014. display: flex;
  1015. align-items: center;
  1016. justify-content: center;
  1017. border-radius: 50rpx;
  1018. padding: 0 10rpx;
  1019. }
  1020. }
  1021. }
  1022. .footer-right{
  1023. width: 60%;
  1024. height: 80%;
  1025. display: flex;
  1026. align-items: center;
  1027. border-radius: 50px;
  1028. overflow: hidden;
  1029. margin: 0 5px;
  1030. .footer-right-item{
  1031. height: 100%;
  1032. display: flex;
  1033. flex-direction: column;
  1034. align-items: center;
  1035. justify-content: center;
  1036. width: 50%;
  1037. font-size: 14px;
  1038. color: #FFFFFF;
  1039. }
  1040. .footer-right-item:first-child{
  1041. background-color: #FF9900;
  1042. }
  1043. .footer-right-item:last-child{
  1044. background-color: #FF0000;
  1045. }
  1046. }
  1047. }
  1048. .popu-nums-content{
  1049. background-color: #FFFFFF;
  1050. border-radius: 10px;
  1051. width: 300px;
  1052. display: flex;
  1053. flex-direction: column;
  1054. align-items: center;
  1055. padding: 10px 15px;
  1056. .popu-close{
  1057. padding: 10px;
  1058. position: absolute;
  1059. right: 0;
  1060. top: 0;
  1061. z-index: 1000;
  1062. }
  1063. .popu-content-title{
  1064. padding: 10px;
  1065. font-size: 16px;
  1066. }
  1067. .popu-content-num{
  1068. font-size: 24rpx;
  1069. color: #999999;
  1070. padding: 10px 0;
  1071. > text{
  1072. margin-right: 10px;
  1073. font-size: 10px;
  1074. }
  1075. }
  1076. .popu-content-btn{
  1077. width: 100%;
  1078. display: flex;
  1079. align-items: center;
  1080. justify-content: space-around;
  1081. margin: 20px 0 10px;
  1082. .popu-content-btn-item{
  1083. width: 40%;
  1084. height: 32px;
  1085. font-size: 14px;
  1086. display: flex;
  1087. align-items: center;
  1088. justify-content: center;
  1089. border-radius: 100px;
  1090. }
  1091. .cancelBtn{
  1092. background-color: #f8f8f8;
  1093. color: #666;
  1094. }
  1095. .okbtn{
  1096. background-color: #f70000;
  1097. color: #FFFFFF;
  1098. }
  1099. }
  1100. }
  1101. .popu-content{
  1102. display: flex;
  1103. flex-direction: column;
  1104. align-items: center;
  1105. padding: 10px 15px;
  1106. .popu-close{
  1107. padding: 10px;
  1108. position: absolute;
  1109. right: 0;
  1110. top: 0;
  1111. z-index: 1000;
  1112. }
  1113. .qty-box{
  1114. display: flex;
  1115. .qty-btn{
  1116. display: flex;
  1117. align-items: center;
  1118. justify-content: center;
  1119. width: 22px;
  1120. height: 20px;
  1121. border-radius: 50px;
  1122. font-size: 18px;
  1123. color: #066cff;
  1124. &.qty-disabled{
  1125. color: #999;
  1126. }
  1127. }
  1128. .qty-num{
  1129. width: 24px;
  1130. height: 20px;
  1131. line-height: 20px;
  1132. text-align: center;
  1133. background-color: #efefef;
  1134. margin: 0 3px;
  1135. border-radius: 3px;
  1136. font-size: 12px;
  1137. input{
  1138. width: 100%;
  1139. height: 100%;
  1140. text-align: center;
  1141. color: #333;
  1142. }
  1143. }
  1144. }
  1145. .pupu-box{
  1146. display: flex;
  1147. justify-content: space-between;
  1148. margin-top: 35px;
  1149. width: 100%;
  1150. }
  1151. .popu-content-img{
  1152. border-radius: 6px;
  1153. border: 1px solid #eee;
  1154. overflow: hidden;
  1155. width: 80px;
  1156. height: 80px;
  1157. }
  1158. .popu-content-info{
  1159. padding: 0 0 0 10px;
  1160. flex-grow: 1;
  1161. overflow: hidden;
  1162. width: 50%;
  1163. .popu-content-info-title{
  1164. font-size: 14px;
  1165. }
  1166. .popu-content-info-code{
  1167. font-size: 12px;
  1168. color: #00aaff;
  1169. margin-top: 5px;
  1170. }
  1171. }
  1172. .gift-box{
  1173. padding-left: 8%;
  1174. margin-top: 10px;
  1175. border-top: 1px solid #eee;
  1176. padding-top: 10px;
  1177. .popu-content-img{
  1178. width: 58px;
  1179. height: 58px;
  1180. }
  1181. .popu-content-info-title{
  1182. font-size: 12px;
  1183. color: #666;
  1184. }
  1185. .popu-content-box{
  1186. margin-top: 0;
  1187. }
  1188. .popu-content-num{
  1189. padding:5px 15px;
  1190. >text{
  1191. font-size: 10px;
  1192. }
  1193. }
  1194. .rebate-tag{
  1195. margin: 0 5px 0 0;
  1196. background: #ff0000;
  1197. color: #fff;
  1198. flex-grow: 1;
  1199. display: flex;
  1200. justify-content: center;
  1201. }
  1202. .ellipsis-two{
  1203. width: 80%;
  1204. flex-grow: 1;
  1205. }
  1206. }
  1207. .popu-content-box{
  1208. display: flex;
  1209. align-items: baseline;
  1210. margin-top: 5px;
  1211. .popu-content-price{
  1212. color: red;
  1213. display: flex;
  1214. align-items: baseline;
  1215. font-size: 12px;
  1216. text{
  1217. font-size: 38rpx;
  1218. }
  1219. }
  1220. }
  1221. .pupu-box-item,.pupu-box-pay-item{
  1222. width: 100%;
  1223. padding-top: 20px;
  1224. > view{
  1225. padding: 5px 0;
  1226. }
  1227. .totalBar-box{
  1228. margin-bottom: 20rpx;
  1229. > view{
  1230. padding: 5px 0;
  1231. }
  1232. .pf{
  1233. font-size: 20rpx;
  1234. }
  1235. }
  1236. }
  1237. .pupu-box-pay-item{
  1238. > view{
  1239. padding: 6px 0;
  1240. }
  1241. .popu-content-amount{
  1242. font-size: 28px;
  1243. color: red;
  1244. }
  1245. .popu-content-title{
  1246. font-weight: bold;
  1247. }
  1248. }
  1249. .popu-content-num{
  1250. > text{
  1251. margin-right: 10px;
  1252. }
  1253. }
  1254. .popu-content-btn{
  1255. width: 100%;
  1256. display: flex;
  1257. align-items: center;
  1258. justify-content: space-around;
  1259. margin: 30px 0 20px;
  1260. .popu-content-btn-item{
  1261. width: 30%;
  1262. height: 34px;
  1263. font-size: 14px;
  1264. display: flex;
  1265. align-items: center;
  1266. justify-content: center;
  1267. border-radius: 100px;
  1268. }
  1269. .cancelBtn{
  1270. background-color: #f8f8f8;
  1271. color: #666;
  1272. }
  1273. .okbtn{
  1274. background-color: #f70000;
  1275. color: #FFFFFF;
  1276. width: 65%;
  1277. .payAmount{
  1278. margin-left: 5px;
  1279. }
  1280. }
  1281. .cartbtn{
  1282. background-color: #ffa60c;
  1283. color: #FFFFFF;
  1284. width: 65%;
  1285. }
  1286. }
  1287. }
  1288. }
  1289. </style>