index.vue 7.4 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 class="money">{{totalPrice}}</span></span></view>
  23. <view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>{{$t(`去付款`)}}</view>
  24. </view>
  25. <view class="mask" @click='close' v-if="pay_close"></view>
  26. <view v-show="false" v-html="formContent"></view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. orderPay
  32. } from '@/api/order.js';
  33. import colors from '@/mixins/color.js';
  34. export default {
  35. props: {
  36. payMode: {
  37. type: Array,
  38. default: function() {
  39. return [];
  40. }
  41. },
  42. pay_close: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. order_id: {
  47. type: String,
  48. default: ''
  49. },
  50. totalPrice: {
  51. type: String,
  52. default: '0'
  53. },
  54. isCall: {
  55. type: Boolean,
  56. default: false
  57. },
  58. friendPay: {
  59. type: Boolean,
  60. default: false
  61. }
  62. },
  63. mixins: [colors],
  64. data() {
  65. return {
  66. description: '下单后,需要确认收货完成订单,才能收到积分.',
  67. formContent: '',
  68. active: 0,
  69. paytype: '',
  70. number: 0
  71. };
  72. },
  73. watch: {
  74. payMode: {
  75. handler(newV, oldValue) {
  76. let newPayList = [];
  77. newV.forEach((item, index) => {
  78. if (item.payStatus) {
  79. item.index = index;
  80. newPayList.push(item)
  81. }
  82. });
  83. this.active = newPayList[0].index;
  84. this.paytype = newPayList[0].value;
  85. this.number = newPayList[0].number || 0;
  86. },
  87. immediate: true,
  88. deep: true
  89. }
  90. },
  91. methods: {
  92. payType(number, paytype, index) {
  93. this.active = index;
  94. this.paytype = paytype;
  95. this.number = number;
  96. this.$emit('changePayType', paytype)
  97. },
  98. close: function() {
  99. this.$emit('onChangeFun', {
  100. action: 'payClose'
  101. });
  102. },
  103. goPay: function(number, paytype) {
  104. if (this.isCall) {
  105. return this.$emit('onChangeFun', {
  106. action: 'payCheck',
  107. value: paytype
  108. });
  109. }
  110. let that = this;
  111. if (!that.order_id) return that.$util.Tips({
  112. title: that.$t(`请选择要支付的订单`)
  113. });
  114. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  115. title: that.$t(`余额不足`)
  116. });
  117. uni.showLoading({
  118. title: that.$t(`支付中`)
  119. });
  120. if (paytype == 'friend' && that.order_id) {
  121. return uni.navigateTo({
  122. url: '/pages/users/payment_on_behalf/index?order_id=' + that.order_id + '&spread=' +
  123. this.$store.state.app.uid,
  124. success: res => {},
  125. fail: () => {},
  126. complete: () => {}
  127. });
  128. }
  129. orderPay({
  130. uni: that.order_id,
  131. paytype: paytype,
  132. type: that.friendPay ? 1 : 0,
  133. // #ifdef MP
  134. 'from': 'routine',
  135. // #endif
  136. }).then(res => {
  137. let jsConfig = res.data.result.jsConfig;
  138. switch (paytype) {
  139. case 'weixin':
  140. if (res.data.result === undefined) return that.$util.Tips({
  141. title: that.$t(`缺少支付参数`)
  142. });
  143. // #ifdef MP
  144. let mp_pay_name=''
  145. if(uni.requestOrderPayment){
  146. mp_pay_name='requestOrderPayment'
  147. }else{
  148. mp_pay_name='requestPayment'
  149. }
  150. uni[mp_pay_name]({
  151. timeStamp: jsConfig.timestamp,
  152. nonceStr: jsConfig.nonceStr,
  153. package: jsConfig.package,
  154. signType: jsConfig.signType,
  155. paySign: jsConfig.paySign,
  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>