index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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: 'prepay_id='+res.data.prepayid,
  154. signType: 'RSA',
  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. value: paytype
  165. });
  166. });
  167. },
  168. fail: function (e) {
  169. console.log(e.errMsg);
  170. uni.hideLoading();
  171. return that.$util.Tips({
  172. title: that.$t(`取消支付`)
  173. }, () => {
  174. that.$emit('onChangeFun', {
  175. action: 'pay_fail'
  176. });
  177. });
  178. },
  179. complete: function (e) {
  180. uni.hideLoading();
  181. if (e.errMsg == 'requestPayment:cancel' || e.errMsg == 'requestOrderPayment:cancel') return that.$util
  182. .Tips({
  183. title: that.$t(`取消支付`)
  184. }, () => {
  185. that.$emit('onChangeFun', {
  186. action: 'pay_fail'
  187. });
  188. });
  189. },
  190. });
  191. // #endif
  192. break;
  193. }
  194. }).catch(err => {
  195. uni.hideLoading();
  196. return that.$util.Tips({
  197. title: err
  198. }, () => {
  199. that.$emit('onChangeFun', {
  200. action: 'pay_fail'
  201. });
  202. });
  203. })
  204. }
  205. }
  206. }
  207. </script>
  208. <style scoped lang="scss">
  209. .bgcolor {
  210. background-color: var(--view-theme)
  211. }
  212. .payment {
  213. position: fixed;
  214. bottom: 0;
  215. left: 0;
  216. width: 100%;
  217. border-radius: 16rpx 16rpx 0 0;
  218. background-color: #fff;
  219. padding-bottom: 60rpx;
  220. z-index: 999;
  221. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  222. transform: translate3d(0, 100%, 0);
  223. .payMoney {
  224. font-size: 28rpx;
  225. color: #333333;
  226. text-align: center;
  227. margin-top: 50rpx;
  228. .font-color {
  229. margin-left: 10rpx;
  230. .money {
  231. font-size: 40rpx;
  232. }
  233. }
  234. }
  235. .button {
  236. width: 690rpx;
  237. height: 90rpx;
  238. border-radius: 45rpx;
  239. color: #FFFFFF;
  240. margin: 20rpx auto 0 auto;
  241. }
  242. }
  243. .payment.on {
  244. transform: translate3d(0, 0, 0);
  245. }
  246. .payment .title {
  247. text-align: center;
  248. height: 123rpx;
  249. font-size: 32rpx;
  250. color: #282828;
  251. font-weight: bold;
  252. padding-right: 30rpx;
  253. margin-left: 30rpx;
  254. position: relative;
  255. border-bottom: 1rpx solid #eee;
  256. }
  257. .payment .title .iconfont {
  258. position: absolute;
  259. right: 30rpx;
  260. top: 50%;
  261. transform: translateY(-50%);
  262. font-size: 38rpx;
  263. color: #8a8a8a;
  264. font-weight: normal;
  265. }
  266. .payment .item {
  267. border-bottom: 1rpx solid #eee;
  268. height: 130rpx;
  269. margin-left: 30rpx;
  270. padding-right: 30rpx;
  271. }
  272. .payment .item .left {
  273. width: 610rpx;
  274. }
  275. .payment .item .left .text {
  276. width: 540rpx;
  277. }
  278. .payment .item .left .text .name {
  279. font-size: 32rpx;
  280. color: #282828;
  281. }
  282. .payment .item .left .text .info {
  283. font-size: 24rpx;
  284. color: #999;
  285. }
  286. .payment .item .left .text .info .money {
  287. color: #ff9900;
  288. }
  289. .payment .item .left .iconfont {
  290. font-size: 45rpx;
  291. color: #09bb07;
  292. }
  293. .payment .item .left .iconfont.icon-zhifubao {
  294. color: #00aaea;
  295. }
  296. .payment .item .left .iconfont.icon-yuezhifu {
  297. color: #ff9900;
  298. }
  299. .payment .item .left .iconfont.icon-yuezhifu1 {
  300. color: #eb6623;
  301. }
  302. .payment .item .iconfont {
  303. font-size: 40rpx;
  304. color: #ccc;
  305. }
  306. .icon-haoyoudaizhifu {
  307. color: #F34C3E !important;
  308. }
  309. </style>