productDetail.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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. this.$store.state.vuex_tempOrderData.billStatus = 'WAIT_PAY'
  573. uni.hideLoading()
  574. })
  575. }else{
  576. // 未开通支付,创建成功,跳转到订单详情页
  577. this.showPopu = false
  578. this.submitOk = true
  579. uni.hideLoading()
  580. }
  581. }else{
  582. uni.hideLoading()
  583. uni.showToast({
  584. title: res.message,
  585. icon: 'none'
  586. })
  587. }
  588. })
  589. },
  590. // 关闭之前
  591. beforeClosePopu(){
  592. console.log(this.showPay,this.submitOk,this.cacelOk)
  593. // 正在支付
  594. if(this.showPay&&!this.submitOk&&!this.cacelOk){
  595. this.showPay = false
  596. this.cancelPay()
  597. }
  598. },
  599. // 关闭确定订单弹窗后
  600. closePopu(){
  601. this.showPopu = false
  602. // 刷新页面
  603. if(this.refashOk){
  604. this.qty = 1
  605. this.getDetail()
  606. }else{
  607. // 开通了支付
  608. if(this.hasPay){
  609. // 付款
  610. if(this.showPay){
  611. // 确定取消付款或付款失败
  612. if(this.cacelOk){
  613. this.cacelOk = false
  614. }
  615. // 确定付款成功
  616. if(this.submitOk){
  617. this.submitOk = false
  618. }
  619. // 去订单详情页
  620. this.toOrderDetial()
  621. }else{
  622. // 取消立即购买
  623. this.resetPage()
  624. }
  625. }else{
  626. // 未开通支付
  627. // 去订单详情页
  628. if(this.submitOk){
  629. this.submitOk = false
  630. this.toOrderDetial()
  631. }else{
  632. // 取消采购
  633. this.resetPage()
  634. }
  635. }
  636. }
  637. },
  638. // 确认付款
  639. confirmPay(){
  640. const _this = this
  641. // 确认付款
  642. const data = _this.payData
  643. console.log(data)
  644. if(data){
  645. uni.requestPayment({
  646. provider: 'wxpay',
  647. timeStamp: data.timeStamp,
  648. nonceStr: data.nonceStr,
  649. package: data.package,
  650. signType: data.signType,
  651. paySign: data.paySign,
  652. success: (res) =>{
  653. _this.payComplete(1,true)
  654. _this.$store.state.vuex_tempOrderData.billStatus = 'WAIT_AUDIT'
  655. },
  656. fail: (err)=> {
  657. console.log('fail:',err);
  658. _this.payComplete(err.errMsg.indexOf("cancel")>=0 ? 2 : 0,false)
  659. _this.$store.state.vuex_tempOrderData.billStatus = 'WAIT_PAY'
  660. }
  661. });
  662. }else{
  663. _this.payComplete(0,false)
  664. }
  665. },
  666. payComplete(type,data){
  667. uni.showToast({
  668. mask: true,
  669. title: type==1 ? '支付成功' : (type==2?'支付取消':'支付失败'),
  670. icon: 'none'
  671. })
  672. this.showPopu = false
  673. this.submitOk = true
  674. },
  675. // 确认取消付款弹框
  676. cancelPay(){
  677. const _this = this
  678. uni.showModal({
  679. title: '确定取消支付吗?',
  680. content: '您的订单在30分钟内未支付将被取消,请尽快完成支付。',
  681. confirmText: '继续支付',
  682. cancelText: '取消支付',
  683. success(ret) {
  684. // 确定取消,跳转到订单详情页
  685. if(ret.cancel){
  686. // 支付弹框打开中
  687. if(_this.showPopu){
  688. console.log(0)
  689. _this.showPopu = false
  690. _this.cacelOk = true
  691. }else{
  692. console.log(1)
  693. // 未打开直接跳转
  694. _this.toOrderDetial()
  695. }
  696. }
  697. if(ret.confirm){
  698. console.log(2)
  699. // 继续支付
  700. _this.showPopu = true
  701. _this.showPay = true
  702. _this.cacelOk = false
  703. }
  704. }
  705. })
  706. },
  707. // 重置页面
  708. resetPage(){
  709. this.qty = 1
  710. this.isAddCart = false
  711. this.showPopu = false
  712. this.showPay = false
  713. this.cacelOk = false
  714. this.submitOk = false
  715. setTimeout(()=>{
  716. uni.hideLoading()
  717. },300)
  718. },
  719. // 订单详情页
  720. toOrderDetial(){
  721. this.resetPage()
  722. // 跳转到订单详情页面
  723. uni.navigateTo({
  724. url: "/pagesB/procureOrder/orderDetail"
  725. })
  726. }
  727. }
  728. }
  729. </script>
  730. <style lang="less">
  731. .pages {
  732. height: 100vh;
  733. display: flex;
  734. flex-direction: column;
  735. .scrollPage-header{
  736. z-index: 1;
  737. width: 100%;
  738. position:fixed;
  739. left: 0;
  740. top: 0;
  741. .header-title{
  742. display: flex;
  743. align-items: center;
  744. justify-content: space-between;
  745. padding: 0 10px;
  746. height: 44px;
  747. .header-left{
  748. display: flex;
  749. align-items: center;
  750. text{
  751. font-size: 14px;
  752. color: #333333;
  753. }
  754. background-color: rgba(255,255,255,0.6);
  755. box-shadow: 0px 1px 0px 0px #E6E6E6;
  756. border-radius: 50px;
  757. padding: 3px 6px 3px;
  758. }
  759. .header-right{
  760. width: 50px;
  761. }
  762. }
  763. }
  764. .copyText{
  765. background-color: #efefef;
  766. border-radius: 100rpx;
  767. padding: 0 20rpx;
  768. color: #03A9F4;
  769. font-size: 20rpx;
  770. display: inline-block;
  771. margin-left: 20rpx;
  772. height: 44rpx;
  773. line-height: 44rpx;
  774. }
  775. .scrollPage-content{
  776. flex: 1;
  777. overflow-y: auto;
  778. .product-info{
  779. background:#fff;
  780. margin-bottom: 10px;
  781. .product-info-text{
  782. padding: 10px;
  783. .product-info-text-title{
  784. font-weight: bold;
  785. color: #333333;
  786. line-height: 22px;
  787. margin-bottom: 5px;
  788. }
  789. .product-info-text-attr{
  790. display: flex;
  791. align-items: center;
  792. justify-content: space-between;
  793. .product-info-price{
  794. color: red;
  795. display: flex;
  796. align-items: baseline;
  797. font-size: 12px;
  798. text{
  799. font-size: 38rpx;
  800. }
  801. }
  802. .product-info-nums{
  803. font-size: 12px;
  804. color: #999999;
  805. >view{
  806. display: flex;
  807. align-items: center;
  808. }
  809. .share{
  810. button{
  811. width: auto;
  812. padding: 0;
  813. border: 0;
  814. background: none;
  815. line-height: normal;
  816. margin: 0;
  817. display: inline;
  818. font-size: 12px;
  819. color: #999;
  820. &::after{
  821. border:none;
  822. }
  823. /deep/ .u-icon{
  824. margin-right: 3px;
  825. }
  826. }
  827. }
  828. }
  829. }
  830. }
  831. }
  832. .product-info-guige{
  833. display: flex;
  834. flex-wrap: wrap;
  835. justify-content: space-between;
  836. background:#fff;
  837. margin: 10px 0;
  838. padding: 10px;
  839. line-height: 28px;
  840. .row{
  841. width: 100%;
  842. }
  843. .row-ban{
  844. width: 50%;
  845. }
  846. >view{
  847. color: #999;
  848. text{
  849. color: #333333;
  850. }
  851. }
  852. }
  853. .product-info-content{
  854. background:#fff;
  855. margin-bottom: 10px;
  856. padding: 10px;
  857. line-height: 28px;
  858. }
  859. }
  860. .rebate-tag{
  861. background: #ffe7df;
  862. color: #E91E63;
  863. padding: 2px 5px;
  864. font-size: 10px;
  865. border-radius: 3px;
  866. margin-left: 6px;
  867. }
  868. .tejia-tag{
  869. color: #E91E63;
  870. margin-left: 6px;
  871. font-size: 12px;
  872. text{
  873. font-size: 12px;
  874. color: #999;
  875. margin-left: 5px;
  876. text-decoration: line-through;
  877. }
  878. }
  879. .scrollPage-footer{
  880. background-color: #FFFFFF;
  881. width: 100%;
  882. position: fixed;
  883. left: 0;
  884. bottom: 0;
  885. .scrollPage-footer-box{
  886. display: flex;
  887. align-items: center;
  888. justify-content: space-between;
  889. height: 45px;
  890. }
  891. .footer-left{
  892. display: flex;
  893. align-items: center;
  894. justify-content: space-between;
  895. width: 35%;
  896. .footer-left-item{
  897. display: flex;
  898. flex-direction: column;
  899. align-items: center;
  900. justify-content: center;
  901. padding: 0 15px;
  902. position: relative;
  903. .footer-left-item-text{
  904. font-size: 12px;
  905. color: #666666;
  906. }
  907. .badge{
  908. background: #f44336;
  909. color: #fff;
  910. position: absolute;
  911. right: 5px;
  912. top: -8px;
  913. font-size: 12px;
  914. display: flex;
  915. align-items: center;
  916. justify-content: center;
  917. border-radius: 50rpx;
  918. padding: 0 10rpx;
  919. }
  920. }
  921. }
  922. .footer-right{
  923. width: 60%;
  924. height: 80%;
  925. display: flex;
  926. align-items: center;
  927. border-radius: 50px;
  928. overflow: hidden;
  929. margin: 0 5px;
  930. .footer-right-item{
  931. height: 100%;
  932. display: flex;
  933. flex-direction: column;
  934. align-items: center;
  935. justify-content: center;
  936. width: 50%;
  937. font-size: 14px;
  938. color: #FFFFFF;
  939. }
  940. .footer-right-item:first-child{
  941. background-color: #FF9900;
  942. }
  943. .footer-right-item:last-child{
  944. background-color: #FF0000;
  945. }
  946. }
  947. }
  948. .popu-nums-content{
  949. background-color: #FFFFFF;
  950. border-radius: 10px;
  951. width: 300px;
  952. display: flex;
  953. flex-direction: column;
  954. align-items: center;
  955. padding: 10px 15px;
  956. .popu-close{
  957. padding: 10px;
  958. position: absolute;
  959. right: 0;
  960. top: 0;
  961. z-index: 1000;
  962. }
  963. .popu-content-title{
  964. padding: 10px;
  965. font-size: 16px;
  966. }
  967. .popu-content-num{
  968. font-size: 24rpx;
  969. color: #999999;
  970. padding: 10px 0;
  971. > text{
  972. margin-right: 10px;
  973. font-size: 10px;
  974. }
  975. }
  976. .popu-content-btn{
  977. width: 100%;
  978. display: flex;
  979. align-items: center;
  980. justify-content: space-around;
  981. margin: 20px 0 10px;
  982. .popu-content-btn-item{
  983. width: 40%;
  984. height: 32px;
  985. font-size: 14px;
  986. display: flex;
  987. align-items: center;
  988. justify-content: center;
  989. border-radius: 100px;
  990. }
  991. .cancelBtn{
  992. background-color: #f8f8f8;
  993. color: #666;
  994. }
  995. .okbtn{
  996. background-color: #f70000;
  997. color: #FFFFFF;
  998. }
  999. }
  1000. }
  1001. .popu-content{
  1002. display: flex;
  1003. flex-direction: column;
  1004. align-items: center;
  1005. padding: 10px 15px;
  1006. .popu-close{
  1007. padding: 10px;
  1008. position: absolute;
  1009. right: 0;
  1010. top: 0;
  1011. z-index: 1000;
  1012. }
  1013. .qty-box{
  1014. display: flex;
  1015. .qty-btn{
  1016. display: flex;
  1017. align-items: center;
  1018. justify-content: center;
  1019. width: 22px;
  1020. height: 20px;
  1021. border-radius: 50px;
  1022. font-size: 18px;
  1023. color: #066cff;
  1024. &.qty-disabled{
  1025. color: #999;
  1026. }
  1027. }
  1028. .qty-num{
  1029. width: 24px;
  1030. height: 20px;
  1031. line-height: 20px;
  1032. text-align: center;
  1033. background-color: #efefef;
  1034. margin: 0 3px;
  1035. border-radius: 3px;
  1036. font-size: 12px;
  1037. input{
  1038. width: 100%;
  1039. height: 100%;
  1040. text-align: center;
  1041. color: #333;
  1042. }
  1043. }
  1044. }
  1045. .pupu-box{
  1046. display: flex;
  1047. justify-content: space-between;
  1048. margin-top: 35px;
  1049. width: 100%;
  1050. }
  1051. .popu-content-img{
  1052. border-radius: 6px;
  1053. border: 1px solid #eee;
  1054. overflow: hidden;
  1055. width: 80px;
  1056. height: 80px;
  1057. }
  1058. .popu-content-info{
  1059. padding: 0 0 0 10px;
  1060. flex-grow: 1;
  1061. overflow: hidden;
  1062. width: 50%;
  1063. .popu-content-info-title{
  1064. font-size: 14px;
  1065. }
  1066. .popu-content-info-code{
  1067. font-size: 12px;
  1068. color: #00aaff;
  1069. margin-top: 5px;
  1070. }
  1071. }
  1072. .gift-box{
  1073. padding-left: 8%;
  1074. margin-top: 10px;
  1075. border-top: 1px solid #eee;
  1076. padding-top: 10px;
  1077. .popu-content-img{
  1078. width: 58px;
  1079. height: 58px;
  1080. }
  1081. .popu-content-info-title{
  1082. font-size: 12px;
  1083. color: #666;
  1084. }
  1085. .popu-content-box{
  1086. margin-top: 0;
  1087. }
  1088. .popu-content-num{
  1089. padding:5px 15px;
  1090. >text{
  1091. font-size: 10px;
  1092. }
  1093. }
  1094. .rebate-tag{
  1095. margin: 0 5px 0 0;
  1096. background: #ff0000;
  1097. color: #fff;
  1098. flex-grow: 1;
  1099. display: flex;
  1100. justify-content: center;
  1101. }
  1102. .ellipsis-two{
  1103. width: 80%;
  1104. flex-grow: 1;
  1105. }
  1106. }
  1107. .popu-content-box{
  1108. display: flex;
  1109. align-items: baseline;
  1110. margin-top: 5px;
  1111. .popu-content-price{
  1112. color: red;
  1113. display: flex;
  1114. align-items: baseline;
  1115. font-size: 12px;
  1116. text{
  1117. font-size: 38rpx;
  1118. }
  1119. }
  1120. }
  1121. .pupu-box-item,.pupu-box-pay-item{
  1122. width: 100%;
  1123. padding-top: 20px;
  1124. > view{
  1125. padding: 10px 0;
  1126. }
  1127. }
  1128. .pupu-box-pay-item{
  1129. > view{
  1130. padding: 6px 0;
  1131. }
  1132. .popu-content-amount{
  1133. font-size: 28px;
  1134. color: red;
  1135. }
  1136. .popu-content-title{
  1137. font-weight: bold;
  1138. }
  1139. }
  1140. .popu-content-num{
  1141. > text{
  1142. margin-right: 10px;
  1143. }
  1144. }
  1145. .popu-content-btn{
  1146. width: 100%;
  1147. display: flex;
  1148. align-items: center;
  1149. justify-content: space-around;
  1150. margin: 30px 0 20px;
  1151. .popu-content-btn-item{
  1152. width: 30%;
  1153. height: 34px;
  1154. font-size: 14px;
  1155. display: flex;
  1156. align-items: center;
  1157. justify-content: center;
  1158. border-radius: 100px;
  1159. }
  1160. .cancelBtn{
  1161. background-color: #f8f8f8;
  1162. color: #666;
  1163. }
  1164. .okbtn{
  1165. background-color: #f70000;
  1166. color: #FFFFFF;
  1167. width: 65%;
  1168. .payAmount{
  1169. margin-left: 5px;
  1170. }
  1171. }
  1172. .cartbtn{
  1173. background-color: #ffa60c;
  1174. color: #FFFFFF;
  1175. width: 65%;
  1176. }
  1177. }
  1178. }
  1179. }
  1180. </style>