productDetail.vue 32 KB

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