index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view>
  3. <view class="payment" :class="pay_close ? 'on' : ''">
  4. <view class="title acea-row row-center-wrapper">
  5. 选择付款方式<text class="iconfont icon-guanbi" @click='close'></text>
  6. </view>
  7. <view class="item acea-row row-between-wrapper" v-for="(item,index) in payMode" :key="index" v-if='item.payStatus' @click="payType(item.number || 0 , item.value,index)">
  8. <view class="left acea-row row-between-wrapper">
  9. <view class="iconfont" :class="item.icon"></view>
  10. <view class="text">
  11. <view class="name">{{item.name}}</view>
  12. <view class="info" v-if="item.value == 'yue'">
  13. {{item.title}} <span class="money">¥{{ item.number }}</span>
  14. </view>
  15. <view class="info" v-else>{{item.title}}</view>
  16. </view>
  17. </view>
  18. <view class="iconfont" :class="active==index?'icon-xuanzhong11 font-color':'icon-weixuan'"></view>
  19. </view>
  20. <view class="payMoney">支付<span class="font-color">¥<span class="money">{{totalPrice}}</span></span></view>
  21. <view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>去付款</view>
  22. </view>
  23. <view class="mask" @click='close' v-if="pay_close"></view>
  24. <view v-show="false" v-html="formContent"></view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. orderPay
  30. } from '@/api/order.js';
  31. export default {
  32. props: {
  33. payMode: {
  34. type: Array,
  35. default: function() {
  36. return [];
  37. }
  38. },
  39. pay_close: {
  40. type: Boolean,
  41. default: false,
  42. },
  43. order_id: {
  44. type: String,
  45. default: ''
  46. },
  47. totalPrice: {
  48. type: String,
  49. default: '0'
  50. },
  51. isCall: {
  52. type: Boolean,
  53. default: false
  54. }
  55. },
  56. data() {
  57. return {
  58. formContent: '',
  59. active:0,
  60. paytype:'',
  61. number:''
  62. };
  63. },
  64. watch:{
  65. payMode:{
  66. deep:true,
  67. immediate: true,
  68. handler:function(newV,oldV){
  69. let newPayList = [];
  70. newV.forEach((item,index)=>{
  71. if(item.payStatus){
  72. item.index = index;
  73. newPayList.push(item)
  74. }
  75. });
  76. this.active = newPayList[0].index;
  77. this.paytype = newPayList[0].value;
  78. this.number = newPayList[0].number || 0;
  79. }
  80. }
  81. },
  82. mounted: function() {},
  83. methods: {
  84. payType(number, paytype, index){
  85. this.active = index;
  86. this.paytype = paytype;
  87. this.number = number;
  88. },
  89. close: function() {
  90. this.$emit('onChangeFun', {
  91. action: 'payClose'
  92. });
  93. },
  94. goPay: function(number, paytype) {
  95. if (this.isCall) {
  96. return this.$emit('onChangeFun', {
  97. action: 'payCheck',
  98. value: paytype
  99. });
  100. }
  101. let that = this;
  102. if (!that.order_id) return that.$util.Tips({
  103. title: '请选择要支付的订单'
  104. });
  105. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  106. title: '余额不足!'
  107. });
  108. uni.showLoading({
  109. title: '支付中'
  110. });
  111. orderPay({
  112. uni: that.order_id,
  113. paytype: paytype,
  114. // #ifdef MP
  115. 'from': 'routine',
  116. // #endif
  117. // #ifdef H5 || APP-PLUS
  118. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  119. // #endif
  120. // #ifdef H5
  121. quitUrl: location.port ? location.protocol + '//' + location.hostname + ':' + location.port + '/pages/users/order_details/index?order_id=' + this.order_id : location.protocol + '//' + location.hostname +
  122. '/pages/users/order_details/index?order_id=' + this.order_id
  123. // #endif
  124. }).then(res => {
  125. switch (paytype) {
  126. case 'weixin':
  127. if (res.data.result === undefined) return that.$util.Tips({
  128. title: '缺少支付参数'
  129. });
  130. // #ifdef MP || APP-PLUS
  131. let jsConfig = res.data.result.jsConfig;
  132. uni.requestPayment({
  133. timeStamp: jsConfig.timestamp,
  134. nonceStr: jsConfig.nonceStr,
  135. package: jsConfig.package,
  136. signType: jsConfig.signType,
  137. paySign: jsConfig.paySign,
  138. success: function(res) {
  139. uni.hideLoading();
  140. return that.$util.Tips({
  141. title: res.msg,
  142. icon: 'success'
  143. }, () => {
  144. that.$emit('onChangeFun', {
  145. action: 'pay_complete'
  146. });
  147. });
  148. },
  149. fail: function(e) {
  150. uni.hideLoading();
  151. return that.$util.Tips({
  152. title: '取消支付'
  153. }, () => {
  154. that.$emit('onChangeFun', {
  155. action: 'pay_fail'
  156. });
  157. });
  158. },
  159. complete: function(e) {
  160. uni.hideLoading();
  161. if (e.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  162. title: '取消支付'
  163. }, () => {
  164. that.$emit('onChangeFun', {
  165. action: 'pay_fail'
  166. });
  167. });
  168. },
  169. });
  170. // #endif
  171. // #ifdef H5
  172. let data = res.data;
  173. if (data.status == "WECHAT_H5_PAY") {
  174. uni.hideLoading();
  175. location.replace(data.result.jsConfig.mweb_url);
  176. return that.$util.Tips({
  177. title: "支付成功",
  178. icon: 'success'
  179. }, () => {
  180. that.$emit('onChangeFun', {
  181. action: 'pay_complete'
  182. });
  183. });
  184. } else {
  185. that.$wechat.pay(data.result.jsConfig)
  186. .finally(() => {
  187. return that.$util.Tips({
  188. title: "支付成功",
  189. icon: 'success'
  190. }, () => {
  191. that.$emit('onChangeFun', {
  192. action: 'pay_complete'
  193. });
  194. });
  195. })
  196. .catch(function() {
  197. return that.$util.Tips({
  198. title: '支付失败'
  199. });
  200. });
  201. }
  202. // #endif
  203. break;
  204. case 'yue':
  205. uni.hideLoading();
  206. return that.$util.Tips({
  207. title: res.msg,
  208. icon: 'success'
  209. }, () => {
  210. that.$emit('onChangeFun', {
  211. action: 'pay_complete'
  212. });
  213. });
  214. break;
  215. case 'offline':
  216. uni.hideLoading();
  217. return that.$util.Tips({
  218. title: res.msg,
  219. icon: 'success'
  220. }, () => {
  221. that.$emit('onChangeFun', {
  222. action: 'pay_complete'
  223. });
  224. });
  225. break;
  226. case 'alipay':
  227. uni.hideLoading();
  228. //#ifdef H5
  229. if (this.$wechat.isWeixin()) {
  230. uni.redirectTo({
  231. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&pay_key=${res.data.result.pay_key}`
  232. });
  233. // uni.navigateTo({
  234. // url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.resjsConfig.qrCode}`
  235. // });
  236. } else {
  237. uni.hideLoading();
  238. that.formContent = res.data.result.jsConfig;
  239. that.$nextTick(() => {
  240. document.getElementById('alipaysubmit').submit();
  241. });
  242. }
  243. //#endif
  244. // #ifdef MP
  245. uni.navigateTo({
  246. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.jsConfig.qrCode}`
  247. });
  248. // #endif
  249. break;
  250. }
  251. }).catch(err => {
  252. uni.hideLoading();
  253. return that.$util.Tips({
  254. title: err
  255. }, () => {
  256. that.$emit('onChangeFun', {
  257. action: 'pay_fail'
  258. });
  259. });
  260. })
  261. }
  262. }
  263. }
  264. </script>
  265. <style scoped lang="scss">
  266. .payment {
  267. position: fixed;
  268. bottom: 0;
  269. left: 0;
  270. width: 100%;
  271. border-radius: 16rpx 16rpx 0 0;
  272. background-color: #fff;
  273. padding-bottom: 60rpx;
  274. z-index: 99;
  275. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  276. transform: translate3d(0, 100%, 0);
  277. .payMoney{
  278. font-size: 28rpx;
  279. color: #333333;
  280. text-align: center;
  281. margin-top: 50rpx;
  282. .font-color{
  283. margin-left: 10rpx;
  284. .money{
  285. font-size: 40rpx;
  286. }
  287. }
  288. }
  289. .button{
  290. width: 690rpx;
  291. height: 90rpx;
  292. border-radius: 45rpx;
  293. color: #FFFFFF;
  294. margin: 20rpx auto 0 auto;
  295. }
  296. }
  297. .payment.on {
  298. transform: translate3d(0, 0, 0);
  299. }
  300. .payment .title {
  301. text-align: center;
  302. height: 123rpx;
  303. font-size: 32rpx;
  304. color: #282828;
  305. font-weight: bold;
  306. padding-right: 30rpx;
  307. margin-left: 30rpx;
  308. position: relative;
  309. border-bottom: 1rpx solid #eee;
  310. }
  311. .payment .title .iconfont {
  312. position: absolute;
  313. right: 30rpx;
  314. top: 50%;
  315. transform: translateY(-50%);
  316. font-size: 38rpx;
  317. color: #8a8a8a;
  318. font-weight: normal;
  319. }
  320. .payment .item {
  321. border-bottom: 1rpx solid #eee;
  322. height: 130rpx;
  323. margin-left: 30rpx;
  324. padding-right: 30rpx;
  325. }
  326. .payment .item .left {
  327. width: 610rpx;
  328. }
  329. .payment .item .left .text {
  330. width: 540rpx;
  331. }
  332. .payment .item .left .text .name {
  333. font-size: 32rpx;
  334. color: #282828;
  335. }
  336. .payment .item .left .text .info {
  337. font-size: 24rpx;
  338. color: #999;
  339. }
  340. .payment .item .left .text .info .money {
  341. color: #ff9900;
  342. }
  343. .payment .item .left .iconfont {
  344. font-size: 45rpx;
  345. color: #09bb07;
  346. }
  347. .payment .item .left .iconfont.icon-zhifubao {
  348. color: #00aaea;
  349. }
  350. .payment .item .left .iconfont.icon-yuezhifu {
  351. color: #ff9900;
  352. }
  353. .payment .item .left .iconfont.icon-yuezhifu1 {
  354. color: #eb6623;
  355. }
  356. .payment .item .iconfont {
  357. font-size: 40rpx;
  358. color: #ccc;
  359. }
  360. </style>