productDetail.vue 32 KB

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