index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="payment" :class="pay_close ? 'on' : ''">
  4. <view class="title acea-row row-center-wrapper">
  5. {{ $t(`选择付款方式`) }}<text class="iconfont icon-guanbi" @click='close'></text>
  6. </view>
  7. <u-alert title="积分赠送方式" type="warning" :description="description"></u-alert>
  8. <view class="item acea-row row-between-wrapper" v-for="(item, index) in payMode" :key="index"
  9. v-if='item.payStatus' @click="payType(item.number || 0, item.value, index)">
  10. <view class="left acea-row row-between-wrapper">
  11. <view class="iconfont" :class="item.icon"></view>
  12. <view class="text">
  13. <view class="name">{{ item.name }}</view>
  14. <view class="info" v-if="item.value == 'yue'">
  15. {{ item.title }} <span class="money">{{ $t(`¥`) }}{{ item.number }}</span>
  16. </view>
  17. <view class="info" v-else>{{ item.title }}</view>
  18. </view>
  19. </view>
  20. <view class="iconfont" :class="active == index ? 'icon-xuanzhong11 font-num' : 'icon-weixuan'"></view>
  21. </view>
  22. <view class="payMoney">{{ $t(`支付金额`) }}<span class="font-color">{{ $t(`¥`) }}<span
  23. class="money">{{ totalPrice }}</span></span></view>
  24. <view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>{{ $t(`去付款`) }}
  25. </view>
  26. </view>
  27. <view class="mask" @click='close' v-if="pay_close"></view>
  28. <view v-show="false" v-html="formContent"></view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. OPENID
  34. } from '@/config/cache';
  35. import Cache from '@/utils/cache';
  36. import {
  37. postJsapiPay
  38. } from '@/api/home.js';
  39. import {
  40. orderPay
  41. } from '@/api/order.js';
  42. import colors from '@/mixins/color.js';
  43. export default {
  44. props: {
  45. payMode: {
  46. type: Array,
  47. default: function () {
  48. return [];
  49. }
  50. },
  51. pay_close: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. order_id: {
  56. type: String,
  57. default: ''
  58. },
  59. totalPrice: {
  60. type: String,
  61. default: '0'
  62. },
  63. isCall: {
  64. type: Boolean,
  65. default: false
  66. },
  67. friendPay: {
  68. type: Boolean,
  69. default: false
  70. }
  71. },
  72. mixins: [colors],
  73. data() {
  74. return {
  75. description: '下单后,需要确认收货完成订单,才能收到积分.',
  76. formContent: '',
  77. active: 0,
  78. paytype: '',
  79. number: 0
  80. };
  81. },
  82. watch: {
  83. payMode: {
  84. handler(newV, oldValue) {
  85. let newPayList = [];
  86. newV.forEach((item, index) => {
  87. if (item.payStatus) {
  88. item.index = index;
  89. newPayList.push(item)
  90. }
  91. });
  92. this.active = newPayList[0].index;
  93. this.paytype = newPayList[0].value;
  94. this.number = newPayList[0].number || 0;
  95. },
  96. immediate: true,
  97. deep: true
  98. }
  99. },
  100. methods: {
  101. payType(number, paytype, index) {
  102. this.active = index;
  103. this.paytype = paytype;
  104. this.number = number;
  105. this.$emit('changePayType', paytype)
  106. },
  107. close: function () {
  108. this.$emit('onChangeFun', {
  109. action: 'payClose'
  110. });
  111. },
  112. goPay: function (number, paytype) {
  113. if (this.isCall) {
  114. return this.$emit('onChangeFun', {
  115. action: 'payCheck',
  116. value: paytype
  117. });
  118. }
  119. let that = this;
  120. if (!that.order_id) return that.$util.Tips({
  121. title: that.$t(`请选择要支付的订单`)
  122. });
  123. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  124. title: that.$t(`余额不足`)
  125. });
  126. uni.showLoading({
  127. title: that.$t(`支付中`)
  128. });
  129. if (paytype == 'friend' && that.order_id) {
  130. return uni.navigateTo({
  131. url: '/pages/users/payment_on_behalf/index?order_id=' + that.order_id + '&spread=' +
  132. this.$store.state.app.uid,
  133. success: res => { },
  134. fail: () => { },
  135. complete: () => { }
  136. });
  137. }
  138. postJsapiPay({
  139. openId: Cache.get(OPENID),
  140. outTradeNo: that.order_id,
  141. }).then(res => {
  142. switch (paytype) {
  143. case 'weixin':
  144. if (res.data === undefined) return that.$util.Tips({
  145. title: that.$t(`缺少支付参数`)
  146. });
  147. // #ifdef MP
  148. let mp_pay_name = 'requestPayment'
  149. uni[mp_pay_name]({
  150. provider: 'wxpay',
  151. timeStamp: res.data.timestamp + '',
  152. nonceStr: res.data.noncestr,
  153. package: res.data.prepayid,
  154. signType: 'MD5',
  155. paySign: res.data.sign,
  156. success: function (res) {
  157. uni.hideLoading();
  158. return that.$util.Tips({
  159. title: res.msg,
  160. icon: 'success'
  161. }, () => {
  162. that.$emit('onChangeFun', {
  163. action: 'pay_complete'
  164. });
  165. });
  166. },
  167. fail: function (e) {
  168. uni.hideLoading();
  169. return that.$util.Tips({
  170. title: that.$t(`取消支付`)
  171. }, () => {
  172. that.$emit('onChangeFun', {
  173. action: 'pay_fail'
  174. });
  175. });
  176. },
  177. complete: function (e) {
  178. uni.hideLoading();
  179. if (e.errMsg == 'requestPayment:cancel' || e.errMsg == 'requestOrderPayment:cancel') return that.$util
  180. .Tips({
  181. title: that.$t(`取消支付`)
  182. }, () => {
  183. that.$emit('onChangeFun', {
  184. action: 'pay_fail'
  185. });
  186. });
  187. },
  188. });
  189. // #endif
  190. break;
  191. }
  192. }).catch(err => {
  193. uni.hideLoading();
  194. return that.$util.Tips({
  195. title: err
  196. }, () => {
  197. that.$emit('onChangeFun', {
  198. action: 'pay_fail'
  199. });
  200. });
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style scoped lang="scss">
  207. .bgcolor {
  208. background-color: var(--view-theme)
  209. }
  210. .payment {
  211. position: fixed;
  212. bottom: 0;
  213. left: 0;
  214. width: 100%;
  215. border-radius: 16rpx 16rpx 0 0;
  216. background-color: #fff;
  217. padding-bottom: 60rpx;
  218. z-index: 999;
  219. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  220. transform: translate3d(0, 100%, 0);
  221. .payMoney {
  222. font-size: 28rpx;
  223. color: #333333;
  224. text-align: center;
  225. margin-top: 50rpx;
  226. .font-color {
  227. margin-left: 10rpx;
  228. .money {
  229. font-size: 40rpx;
  230. }
  231. }
  232. }
  233. .button {
  234. width: 690rpx;
  235. height: 90rpx;
  236. border-radius: 45rpx;
  237. color: #FFFFFF;
  238. margin: 20rpx auto 0 auto;
  239. }
  240. }
  241. .payment.on {
  242. transform: translate3d(0, 0, 0);
  243. }
  244. .payment .title {
  245. text-align: center;
  246. height: 123rpx;
  247. font-size: 32rpx;
  248. color: #282828;
  249. font-weight: bold;
  250. padding-right: 30rpx;
  251. margin-left: 30rpx;
  252. position: relative;
  253. border-bottom: 1rpx solid #eee;
  254. }
  255. .payment .title .iconfont {
  256. position: absolute;
  257. right: 30rpx;
  258. top: 50%;
  259. transform: translateY(-50%);
  260. font-size: 38rpx;
  261. color: #8a8a8a;
  262. font-weight: normal;
  263. }
  264. .payment .item {
  265. border-bottom: 1rpx solid #eee;
  266. height: 130rpx;
  267. margin-left: 30rpx;
  268. padding-right: 30rpx;
  269. }
  270. .payment .item .left {
  271. width: 610rpx;
  272. }
  273. .payment .item .left .text {
  274. width: 540rpx;
  275. }
  276. .payment .item .left .text .name {
  277. font-size: 32rpx;
  278. color: #282828;
  279. }
  280. .payment .item .left .text .info {
  281. font-size: 24rpx;
  282. color: #999;
  283. }
  284. .payment .item .left .text .info .money {
  285. color: #ff9900;
  286. }
  287. .payment .item .left .iconfont {
  288. font-size: 45rpx;
  289. color: #09bb07;
  290. }
  291. .payment .item .left .iconfont.icon-zhifubao {
  292. color: #00aaea;
  293. }
  294. .payment .item .left .iconfont.icon-yuezhifu {
  295. color: #ff9900;
  296. }
  297. .payment .item .left .iconfont.icon-yuezhifu1 {
  298. color: #eb6623;
  299. }
  300. .payment .item .iconfont {
  301. font-size: 40rpx;
  302. color: #ccc;
  303. }
  304. .icon-haoyoudaizhifu {
  305. color: #F34C3E !important;
  306. }
  307. </style>