index.vue 7.3 KB

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