checkout.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <view class="cu-modal bottom-modal" :class="{ show: visible }">
  3. <view class="mask" @click="close"></view>
  4. <view class="wrapper cu-dialog">
  5. <view class="paddingY25 flex-align-center relative">
  6. <image :src="resource.pay_title_dart" class="title" />
  7. <image :src="resource.icon_x" class="x" @click="close" />
  8. </view>
  9. <view>
  10. <view class="flex-align paddingB25">
  11. <image :src="data.cover" class="logo flex-shrink0 flex-shrink0" />
  12. <view class="marginL12 flex1 self-stretch flex-column-between">
  13. <view class="top">
  14. <text class="text">{{ data.name }}</text>
  15. <view v-if="data.sellType === 2" class="sale-pre">预售订单</view>
  16. </view>
  17. <view class="color-theme flex-align-between" style="height: 140rpx">
  18. <view class="flex-column-between">
  19. <view>
  20. <view class="bottom">
  21. <view class="price">
  22. ¥
  23. <text class="price-num">
  24. {{
  25. data.subjectPrice
  26. ? data.subjectPrice
  27. : data.price
  28. }}
  29. </text>
  30. </view>
  31. <view v-if="data.sellType === 2" class="deposit">
  32. 定金:¥{{ data.deposit }}
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="counter">
  38. <view class="counter-top">
  39. <view class="reduce" @click="decrement">
  40. <image class="reduce-img" :src="resource.reduce" />
  41. </view>
  42. <view class="number">{{ total }}</view>
  43. <view class="add" :class="subjectId ? 'spike_hiddren' : ''" @click="increment">
  44. <image class="add-img" :src="resource.add" />
  45. </view>
  46. </view>
  47. <view class="total">
  48. <text class="text">{{ total }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- <view class="color-theme font2 line-ellipsis">含预售商品,先到货先发</view> -->
  53. </view>
  54. </view>
  55. <view class="flex-align paddingY15" style="border-top: 2rpx solid #eeeeee">
  56. <view class="flex1 font4 color-1">快递费</view>
  57. <view class="font2 color-theme marginR5">¥{{ expressAmount || 0 }}</view>
  58. </view>
  59. <view class="flex-align paddingY15" style="border-top: 2rpx solid #eeeeee">
  60. <view class="flex1 font4 color-1">优惠券</view>
  61. <view class="font2 color-theme marginR5">-¥{{ couponAmount || 0 }}</view>
  62. </view>
  63. <view v-if="cash && hide" class="flex-align paddingY15"
  64. style="border-top: 2rpx solid #eeeeee; border-bottom: 2rpx solid #eeeeee">
  65. <view class="flex1 font4 color-1">
  66. 使用钱包支付
  67. <text class="color-theme">(余额:¥{{ cash.balance }})</text>
  68. </view>
  69. <switch class="purple" :checked="cashChecked" @change="changeCashChecked"></switch>
  70. </view>
  71. <view v-if="data.sellType === 2"
  72. class="deposit-phone bgcolor-white radius12 flex-align-between paddingY15">
  73. <text class="text">
  74. <text style="color: #dd524d; font-size: 35rpx">*</text>
  75. 尾款提醒手机号
  76. </text>
  77. <input class="phone" style="width: 400rpx" v-model.trim="phone" type="text"
  78. placeholder="尾款支付提醒短信将发至此号码" placeholder-style="color: #ccc" />
  79. </view>
  80. <view class="flex-align-between paddingY25 color-1"
  81. style="border-top: 2rpx solid #eeeeee; border-bottom: 2rpx solid #eeeeee"
  82. @click="$router.push('address', { type: 1 })">
  83. <text v-if="!address" class="font-8">
  84. <text style="color: #dd524d; font-size: 35rpx">*</text>
  85. 请填写收货地址
  86. </text>
  87. <view v-else>
  88. <view class="font4">{{ address.contactName }} {{ address.contactNo }}</view>
  89. <view class="font3">
  90. {{ address.province }}{{ address.city }}{{ address.district
  91. }}{{ address.address }}
  92. </view>
  93. </view>
  94. <text class="cuIcon-right color-2 font4 marginL5"></text>
  95. </view>
  96. <view class="paddingY25 flex-align-between">
  97. <view>
  98. <view class="font4 color-1 flex-align" @click="showWeb">
  99. 同意《会员购服务协议》详情
  100. <text class="cuIcon-right color-2 font2 marginL5"></text>
  101. </view>
  102. </view>
  103. <switch class="purple" :checked="checked" @change="changeChecked"></switch>
  104. </view>
  105. </view>
  106. <cm-button ::height="44" @click="pay">¥{{ lastPrice }} 立即支付</cm-button>
  107. <view class="fill"></view>
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. import cmButton from '../../components/cm-button.vue'
  113. import {
  114. throttle
  115. } from '@/utils'
  116. import {
  117. H5
  118. } from '@/utils/config'
  119. import resource from '@/utils/resource'
  120. import {
  121. baseEncode
  122. } from '../../utils/utils'
  123. export default {
  124. components: {
  125. cmButton
  126. },
  127. props: {
  128. data: Object,
  129. goodsId: String,
  130. subjectId: String
  131. },
  132. data() {
  133. return {
  134. resource,
  135. visible: false,
  136. checked: true,
  137. address: null,
  138. expressAmount: null,
  139. couponAmount: null,
  140. cash: null,
  141. cashChecked: false,
  142. lastPrice: null, //最终金额
  143. count: 1,
  144. maxCount: 5,
  145. unitPrice: 1,
  146. phone: ''
  147. }
  148. },
  149. mounted() {
  150. this.$event.on(this.$event.key.ADDRESS_SET, (data) => {
  151. this.address = data
  152. })
  153. },
  154. beforeDestroy() {
  155. this.$event.off(this.$event.key.ADDRESS_SET)
  156. },
  157. computed: {
  158. total() {
  159. return this.count * this.unitPrice
  160. },
  161. hide() {
  162. return !this.$store.state.hide
  163. },
  164. payInfo() {
  165. return this.$store.state.payInfo
  166. }
  167. },
  168. watch: {
  169. payInfo(val) {
  170. if (val && val.payResult == 'SUCCESS') {
  171. this.paySuccess(val)
  172. } else if (val && val.payResult !== 'SUCCESS') {}
  173. }
  174. },
  175. methods: {
  176. async getAddress() {
  177. const res = await this.$service.address.default()
  178. this.address = res
  179. },
  180. show(data = {}) {
  181. this.expressAmount = data.expressAmount || null
  182. this.couponAmount = data.couponAmount || null
  183. this.lastPrice = data.type === 1 ? data.paymentAmount : data.depositAmount
  184. if (data.cash && data.cash.balance > data.paymentAmount) {
  185. this.cash = data.cash
  186. this.cashChecked = true
  187. } else {
  188. this.cash = null
  189. this.cashChecked = false
  190. }
  191. this.visible = true
  192. this.getAddress()
  193. },
  194. close() {
  195. this.visible = false
  196. },
  197. changeCashChecked(e) {
  198. this.cashChecked = e.detail.value
  199. },
  200. changeChecked(e) {
  201. this.checked = e.detail.value
  202. },
  203. async pay() {
  204. if (!this.address) {
  205. this.$message.warn('请选择地址')
  206. return
  207. }
  208. if (!this.phone && this.data.sellType === 2) {
  209. this.$message.warn('请填写尾款提醒手机号')
  210. return
  211. }
  212. console.log(this.checked)
  213. if (!this.checked) {
  214. this.$message.warn('请勾选协议')
  215. return
  216. }
  217. this.realPay()
  218. },
  219. async realPay() {
  220. // let paymentType = this.cashChecked ? 'WALLET' : 'WXPAY_JSAPI'
  221. let self = this
  222. const res = await this.$service.mall.apply({
  223. goodsId: this.data.id,
  224. paymentType: 'ALIPAY_APP',
  225. addressBookId: this.address.id,
  226. quantity: this.total,
  227. restNotifyMobile: this.phone,
  228. subjectId: this.subjectId
  229. })
  230. //判断是否是微信支付
  231. console.log(res)
  232. if (res) {
  233. if (res.paySuccess) {
  234. this.close()
  235. this.$router.push('order_product')
  236. return
  237. }
  238. // 支付宝支付
  239. uni.requestPayment({
  240. provider: 'alipay',
  241. orderInfo: res.payInfo,
  242. success: function(res) {
  243. self.close()
  244. self.$router.push('order_product')
  245. self.$store.state.payInfo = null
  246. },
  247. fail: function(err) {
  248. console.log('fail:' + JSON.stringify(err));
  249. }
  250. });
  251. // if(res.redirectUrl){
  252. // this.thirdPay(res)
  253. // }else{
  254. // this.wechatPay(res)
  255. // }
  256. return
  257. }
  258. },
  259. wechatPay(data) {
  260. let payInfo = data.payInfo
  261. wx.requestPayment({
  262. timeStamp: payInfo.timeStamp,
  263. nonceStr: payInfo.nonceStr,
  264. package: payInfo.packageValue,
  265. signType: payInfo.signType,
  266. paySign: payInfo.paySign,
  267. success: (res) => {
  268. this.close()
  269. this.$router.push('order_product')
  270. this.$store.state.payInfo = null
  271. },
  272. fail: (res) => {}
  273. })
  274. },
  275. thirdPay(res) {
  276. let redirectUrl = res.redirectUrl
  277. let requestId = res.requestId
  278. const base64Url = encodeURIComponent(baseEncode(redirectUrl))
  279. wx.openEmbeddedMiniProgram({
  280. path: 'pages/pay/order', // 启动目标页面
  281. appId: 'wx0448557563ffc600', // 启动的小程序
  282. envVersion: 'release', // develop | trial | release
  283. verify: 'binding',
  284. extraData: {
  285. title: '订单支付', // 导航Title
  286. tip: `待支付订单支付`, // 支付提示内容
  287. requestId: requestId, // 本次请求ID
  288. action: 'epPay', // 支付模式
  289. payUrl: base64Url // 支付地址, 需要进行Base64转换
  290. },
  291. success: (res) => {
  292. console.info('启动成功', res)
  293. },
  294. fail: (err) => {
  295. console.info('启动失败', err)
  296. }
  297. })
  298. },
  299. paySuccess(payInfo) {
  300. this.close()
  301. this.$router.push('order_product')
  302. this.$store.state.payInfo = null
  303. },
  304. showWeb() {
  305. this.$router.web(H5.mall.url, H5.mall.title)
  306. },
  307. async getDetail() {
  308. const res = await this.$service.mall.previewSubmit({
  309. goodsId: this.goodsId,
  310. quantity: this.total
  311. })
  312. this.show(res)
  313. },
  314. increment() {
  315. if (this.subjectId) return
  316. if (this.count >= this.maxCount) {
  317. return
  318. }
  319. this.count += 1
  320. this.getDetail()
  321. },
  322. decrement() {
  323. if (this.count <= 1) {
  324. return
  325. }
  326. this.count -= 1
  327. this.getDetail()
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="scss" scoped>
  333. .mask {
  334. position: absolute;
  335. left: 0;
  336. right: 0;
  337. top: 0;
  338. bottom: 0;
  339. }
  340. .wrapper {
  341. padding: 0 28rpx;
  342. background: #fff;
  343. overflow: hidden;
  344. border-top-left-radius: 30rpx !important;
  345. border-top-right-radius: 30rpx !important;
  346. .title {
  347. width: 172rpx;
  348. height: 28rpx;
  349. }
  350. .x {
  351. position: absolute;
  352. right: 28rpx;
  353. top: 50%;
  354. margin-top: -16rpx;
  355. width: 32rpx;
  356. height: 32rpx;
  357. }
  358. .logo {
  359. width: 180rpx;
  360. height: 180rpx;
  361. border-radius: 8rpx;
  362. }
  363. .fill {
  364. height: env(safe-area-inset-bottom);
  365. }
  366. .top {
  367. display: flex;
  368. .text {
  369. font-size: 28rpx;
  370. width: 323rpx;
  371. overflow: hidden;
  372. white-space: nowrap;
  373. text-overflow: ellipsis;
  374. }
  375. .sale-pre {
  376. color: #fff;
  377. font-size: 24rpx;
  378. font-weight: 400;
  379. width: 128rpx;
  380. height: 44rpx;
  381. background: $color-theme;
  382. border-radius: 32rpx;
  383. text-align: center;
  384. line-height: 44rpx;
  385. }
  386. }
  387. .bottom {
  388. display: flex;
  389. .price {
  390. color: $color-theme;
  391. font-size: 22rpx;
  392. margin-right: 12rpx;
  393. .price-num {
  394. font-size: 32rpx;
  395. }
  396. }
  397. .deposit {
  398. color: #fff;
  399. font-size: 24rpx;
  400. font-weight: 400;
  401. width: 157rpx;
  402. height: 40rpx;
  403. background: linear-gradient(270deg, #d070ff 0%, #8b3dff 100%);
  404. border-radius: 32rpx;
  405. text-align: center;
  406. line-height: 40rpx;
  407. }
  408. }
  409. .counter {
  410. display: flex;
  411. flex-direction: column;
  412. width: 190rpx;
  413. height: 80rpx;
  414. .counter-top {
  415. display: flex;
  416. vertical-align: middle;
  417. .reduce {
  418. .reduce-img {
  419. width: 48rpx;
  420. height: 48rpx;
  421. }
  422. }
  423. .number {
  424. color: #000;
  425. height: 45rpx;
  426. margin: 0 32rpx;
  427. line-height: 45rpx;
  428. }
  429. .add {
  430. .add-img {
  431. width: 48rpx;
  432. height: 48rpx;
  433. }
  434. }
  435. .spike_hiddren {
  436. opacity: 0.3;
  437. }
  438. }
  439. .total {
  440. margin-top: 18rpx;
  441. text-align: end;
  442. margin-right: 20rpx;
  443. font-size: 26rpx;
  444. .text {
  445. margin: 0 5rpx;
  446. color: #ff8040;
  447. }
  448. }
  449. }
  450. }
  451. </style>