index.vue 7.2 KB

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