checkout.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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>
  6. <view class="title">
  7. 立即发货
  8. <view class="close" @click="close">
  9. <text class="cuIcon-close"></text>
  10. </view>
  11. </view>
  12. </view>
  13. <view>
  14. <view class="paddingY10" v-if="goods2">
  15. <scroll-view scroll-x class="scroll-wrapper" v-if="goods2.length > 4">
  16. <view class="item" v-for="(goods, index) in goods2" :key="index">
  17. <image
  18. class="super-image translateX"
  19. mode="aspectFit"
  20. :src="goods.data.cover"
  21. />
  22. <view
  23. class="bg-title bold"
  24. :style="'background-image:url(' + ossurl.welfare.detail.numBg + ')'"
  25. >
  26. <text class="">x</text>
  27. {{ goods.total }}
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <view v-else class="flex-align-around">
  32. <view class="item" v-for="(goods, index) in goods2" :key="index">
  33. <image
  34. class="super-image translateX"
  35. mode="aspectFit"
  36. :src="goods.data.cover"
  37. />
  38. <view
  39. class="bg-title bold"
  40. :style="'background-image:url(' + ossurl.welfare.detail.numBg + ')'"
  41. >
  42. <text class="">x</text>
  43. {{ goods.total }}
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <view v-if="expressAmount" class="flex-align paddingY8">
  49. <view class="flex1 font4">运费</view>
  50. <view class="font2 color-theme marginR5">¥{{ expressAmount }}</view>
  51. </view>
  52. <view v-if="expressAmount && cash && hide" class="flex-align paddingY8">
  53. <view class="flex1 font4">
  54. 使用钱包支付
  55. <text class="color-theme">(余额:¥{{ cash.balance }})</text>
  56. </view>
  57. <switch
  58. class="purple"
  59. :checked="cashChecked"
  60. @change="changeCashChecked"
  61. ></switch>
  62. </view>
  63. <view
  64. class="flex-align-between paddingY10"
  65. @click="$router.push('address', { type: 1 })"
  66. >
  67. <text v-if="!address" class="font-8 bold">请填写收货地址</text>
  68. <view v-else>
  69. <view class="font4">{{ address.contactName }} {{ address.contactNo }}</view>
  70. <view class="font3">
  71. {{ address.province }}{{ address.city }}{{ address.district
  72. }}{{ address.address }}
  73. </view>
  74. </view>
  75. <text class="cuIcon-right font4 marginL5"></text>
  76. </view>
  77. </view>
  78. <cm-button ::height="44" @click="pay()">确定发货</cm-button>
  79. <view class="fill"></view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import cmButton from '../../components/cm-button.vue'
  85. import { throttle } from '@/utils'
  86. import { LEVEL_MAP } from '@/utils/config'
  87. import ossurl from '@/utils/ossurl'
  88. import { baseEncode } from '../../utils/utils'
  89. export default {
  90. components: { cmButton },
  91. data() {
  92. return {
  93. ossurl,
  94. LEVEL_MAP,
  95. visible: false,
  96. address: null,
  97. expressAmount: null,
  98. goods2: [],
  99. cash: null,
  100. cashChecked: false
  101. }
  102. },
  103. computed: {
  104. payInfo() {
  105. return this.$store.state.payInfo
  106. }
  107. },
  108. watch: {
  109. payInfo(val) {
  110. if (val && val.payResult == 'SUCCESS') {
  111. this.paySuccess(val)
  112. } else if (val && val.payResult !== 'SUCCESS') {
  113. }
  114. }
  115. },
  116. mounted() {
  117. this.$event.on(this.$event.key.ADDRESS_SET, (data) => {
  118. this.address = data
  119. })
  120. this.getAddress()
  121. },
  122. beforeDestroy() {
  123. this.$event.off(this.$event.key.ADDRESS_SET)
  124. },
  125. computed: {
  126. hide() {
  127. return !this.$store.state.hide
  128. }
  129. },
  130. methods: {
  131. async getAddress() {
  132. const res = await this.$service.address.default()
  133. this.address = res
  134. },
  135. show(data = {}, goods) {
  136. this.generateGoods2(goods)
  137. this.expressAmount = data.expressAmount || 0
  138. if (data.cash && data.cash.balance > data.expressAmount) {
  139. this.cash = data.cash
  140. this.cashChecked = true
  141. } else {
  142. this.cash = null
  143. this.cashChecked = false
  144. }
  145. this.visible = true
  146. },
  147. generateGoods2(goods) {
  148. this.goods = goods
  149. let goodsMap = {}
  150. goods.forEach((item) => {
  151. let key = item.spuId + '_' + item.level
  152. let obj = goodsMap[key]
  153. if (obj) {
  154. goodsMap[key] = {
  155. total: obj.total + 1,
  156. data: obj.data
  157. }
  158. } else {
  159. goodsMap[key] = {
  160. total: 1,
  161. data: item
  162. }
  163. }
  164. })
  165. this.goods2 = Object.values(goodsMap)
  166. },
  167. close() {
  168. this.visible = false
  169. this.$emit('close', false)
  170. },
  171. changeCashChecked(e) {
  172. this.cashChecked = e.detail.value
  173. },
  174. async pay() {
  175. if (!this.address) {
  176. this.$message.warn('请选择地址')
  177. return
  178. }
  179. this.realPay()
  180. },
  181. async realPay() {
  182. const ids = this.goods.map((item) => item.id)
  183. const res = await this.$service.award.takeApply(ids, this.address.id,'ALIPAY_APP')
  184. //判断是否是微信支付
  185. if (res) {
  186. if (res.paySuccess) {
  187. this.close()
  188. this.$emit('success')
  189. return
  190. }
  191. let self = this
  192. // 支付宝支付
  193. uni.requestPayment({
  194. provider: 'alipay',
  195. orderInfo: res.payInfo,
  196. success: function (res) {
  197. self.close()
  198. self.$emit('success')
  199. },
  200. fail: function (err) {
  201. console.log('fail:' + JSON.stringify(err));
  202. }
  203. });
  204. }
  205. },
  206. wechatPay(data) {
  207. let payInfo = data.payInfo
  208. wx.requestPayment({
  209. timeStamp: payInfo.timeStamp,
  210. nonceStr: payInfo.nonceStr,
  211. package: payInfo.packageValue,
  212. signType: payInfo.signType,
  213. paySign: payInfo.paySign,
  214. success: (res) => {
  215. this.close()
  216. this.$emit('success')
  217. },
  218. fail: (res) => {}
  219. })
  220. },
  221. thirdPay(data) {
  222. let self = this
  223. let redirectUrl = data.redirectUrl
  224. let requestId = data.requestId
  225. const base64Url = encodeURIComponent(baseEncode(redirectUrl))
  226. wx.openEmbeddedMiniProgram({
  227. path: 'pages/pay/order', // 启动目标页面
  228. appId: 'wx0448557563ffc600', // 启动的小程序
  229. envVersion: 'release', // develop | trial | release
  230. verify: 'binding',
  231. extraData: {
  232. title: '订单付款', // 导航Title
  233. tip: `待支付订单付款`, // 支付提示内容
  234. requestId: requestId, // 本次请求ID
  235. action: 'epPay', // 支付模式
  236. payUrl: base64Url // 支付地址, 需要进行Base64转换
  237. },
  238. success: (res) => {
  239. console.info('启动成功', res)
  240. },
  241. fail: (err) => {
  242. console.info('启动失败', err)
  243. }
  244. })
  245. },
  246. paySuccess(payInfo) {
  247. this.close()
  248. this.$emit('success')
  249. this.$store.state.payInfo = null
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .mask {
  256. position: absolute;
  257. left: 0;
  258. right: 0;
  259. top: 0;
  260. bottom: 0;
  261. }
  262. .wrapper {
  263. padding: 0 28rpx;
  264. background: #fff;
  265. border-radius: 15px 15px 2px 2px !important;
  266. .title {
  267. text-align: center;
  268. font-size: 32rpx;
  269. font-family: Source Han Sans, Source Han Sans;
  270. font-weight: 700;
  271. color: #000000;
  272. padding: 44rpx 0 10rpx 0;
  273. position: relative;
  274. }
  275. .close {
  276. position: absolute;
  277. right: 0;
  278. width: 48rpx;
  279. height: 48rpx;
  280. background: #ebebeb;
  281. border-radius: 48rpx;
  282. color: #a2a2a2;
  283. top: 30rpx;
  284. line-height: 48rpx;
  285. }
  286. .fill {
  287. height: 50rpx;
  288. }
  289. }
  290. .scroll-wrapper {
  291. padding-left: 28rpx;
  292. overflow: hidden;
  293. height: 182rpx;
  294. white-space: nowrap;
  295. width: 100%;
  296. .item {
  297. display: inline-block;
  298. margin-right: 8rpx;
  299. }
  300. }
  301. .item {
  302. width: 158rpx;
  303. height: 206rpx;
  304. background: #ffffff;
  305. border-radius: 12rpx 12rpx 12rpx 12rpx;
  306. opacity: 1;
  307. border: 2rpx solid #eaeaea;
  308. position: relative;
  309. .super {
  310. position: absolute;
  311. z-index: 0;
  312. left: 0;
  313. top: 0;
  314. width: 120rpx;
  315. height: 182rpx;
  316. }
  317. .super-image {
  318. width: 146rpx;
  319. height: 170rpx;
  320. }
  321. .bg-title {
  322. width: 36rpx;
  323. height: 32rpx;
  324. background-size: 100% 100%;
  325. font-size: 20rpx;
  326. font-family: Arial, Arial;
  327. font-weight: 400;
  328. color: #ffffff;
  329. line-height: 32rpx;
  330. text-align: center;
  331. position: absolute;
  332. right: 0;
  333. top: 0;
  334. }
  335. }
  336. </style>