productDetail.vue 32 KB

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