productDetail.vue 32 KB

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