order_pay.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="pageBg" v-if="waitShow">
  3. <block v-if="emptyType==0">
  4. <view class="order_pay_info">
  5. <view class="item_info_box">
  6. <text class="type_name">订单编号</text>
  7. <text class="type_value">{{orderSns}}</text>
  8. </view>
  9. <view class="item_info_box">
  10. <text class="type_name">有效时间</text>
  11. <text class="type_value">{{prePayOrder.expireDate}} 后自动取消</text>
  12. </view>
  13. <view class="item_info_box">
  14. <text class="type_name">支付金额</text>
  15. <text class="type_value">¥{{prePayOrder.amount}}</text>
  16. </view>
  17. </view>
  18. <view class="order_pay_methods">
  19. <view class="item_info_box" v-for="(item,index) in prePayOrder.payWays" :key="index">
  20. <view class="type_name">
  21. <image :src="item.logo" class="wx_pay_icon" mode="aspectFit"></image>
  22. <text>{{item.name}}</text>
  23. </view>
  24. <image class="operation_icon" src="http://139.9.103.171:1888/img/image/selected_icon.png"></image>
  25. </view>
  26. </view>
  27. <view class="bottomHeight" :style="footSafe"></view>
  28. <view class="bottom" :style="footSafe">
  29. <view class="bottomLeft">
  30. <text class="money_text">合计: <text class="money"><text class="unit">¥</text>{{prePayOrder.amount}}</text></text>
  31. </view>
  32. <view class="bottomRight">
  33. <view class="orderConfirm" @tap="payOrder">立即支付</view>
  34. </view>
  35. </view>
  36. </block>
  37. <DtEmpty :type="emptyType"/>
  38. </view>
  39. </template>
  40. <script>
  41. import DtEmpty from '../comps/dt_empty.vue'
  42. export default {
  43. components:{
  44. DtEmpty
  45. },
  46. data() {
  47. return {
  48. orderSns: [],
  49. prePayOrder: {},
  50. waitShow: false,
  51. payFlag:'',
  52. }
  53. },
  54. computed: {
  55. footSafe() {
  56. return `padding-bottom:${this.safeAreaBottom}px`;
  57. }
  58. },
  59. methods: {
  60. async wxappGo() {
  61. try{
  62. let data = {}
  63. data._isShowLoading = true
  64. data._isReject = true
  65. data.orderSns = this.orderSns;
  66. data.memberId = this.$auth.getMemberId();
  67. let resp = await this.$api.wxappGo(data)
  68. this.emptyType=0
  69. this.prePayOrder = resp;
  70. this.waitShow = true;
  71. }catch(err){
  72. this.emptyType=0
  73. this.$dialog.alert({
  74. content:err.errmsg||'暂无数据~'
  75. })
  76. }
  77. },
  78. async payOrder() {
  79. if (this.prePayOrder.expireDate) {
  80. let time = (this.$util.createDate(this.prePayOrder.expireDate)).getTime();
  81. let now = new Date().getTime();
  82. if (now >= time) {
  83. this.$dialog.alert({
  84. content: '支付已经过期,请重新购买',
  85. confirmText: '我知道了',
  86. success: (res) => {
  87. console.log(res);
  88. if (res.confirm) {
  89. uni.navigateBack({ delta: 1 })
  90. }
  91. }
  92. });
  93. return
  94. }
  95. }
  96. let data = {};
  97. data.orderSns = this.prePayOrder.orderSns;
  98. let res = await this.$api.wxappUnifiedOrder(data);
  99. let tradeNo = res.tradeNo;
  100. let wxPayRes = await this.$api.wxPay(res.payData);
  101. console.log(wxPayRes);
  102. let params = {
  103. amount: this.prePayOrder.amount,
  104. tradeNo: tradeNo,
  105. orderSns: this.prePayOrder.orderSns[0],
  106. payFlag: this.payFlag
  107. }
  108. if (wxPayRes.errMsg == "requestPayment:ok") {
  109. this.$util.refreshPage(['pages/mine','pages/mine_order_list'])
  110. //支付成功
  111. params.state = 1;
  112. uni.redirectTo({
  113. url: "/pagesM/pages/pay_success?" + this.$util.serialize(params)
  114. });
  115. } else {
  116. params.state = 0;
  117. uni.redirectTo({
  118. url: "/pagesM/pages/pay_success?" + this.$util.serialize(params)
  119. });
  120. }
  121. },
  122. onLoadPage(options) {
  123. wx.hideShareMenu();
  124. this.orderSns = options.orderSns ? JSON.parse(options.orderSns) : [];
  125. this.payFlag=options.payFlag;
  126. this.wxappGo();
  127. },
  128. },
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .item_info_box {
  133. display: flex;
  134. flex-direction: row;
  135. justify-content: space-between;
  136. padding: 30upx;
  137. align-items: center;
  138. box-sizing: border-box;
  139. border-top: 1upx solid #e5e5e5;
  140. .type_name {
  141. color: #666666;
  142. font-size: 28upx;
  143. display: flex;
  144. flex-direction: row;
  145. align-items: center;
  146. .wx_pay_icon {
  147. width: 50upx;
  148. height: 50upx;
  149. margin-right: 20upx;
  150. }
  151. }
  152. .type_value {
  153. color: #333;
  154. font-size: 28upx;
  155. flex: 1;
  156. text-align: right;
  157. margin-left: 40upx;
  158. }
  159. .operation_icon {
  160. width: 40upx;
  161. height: 40upx;
  162. }
  163. }
  164. .order_pay_info {
  165. background: #fff;
  166. .item_info_box:first-child {
  167. border-top: none;
  168. }
  169. }
  170. .order_pay_methods {
  171. background: #fff;
  172. margin-top: 20upx;
  173. .item_info_box:first-child {
  174. border-top: none;
  175. }
  176. }
  177. .bottomHeight {
  178. height: 120upx;
  179. }
  180. .bottom {
  181. height: 98upx;
  182. background: white;
  183. position: fixed;
  184. bottom: 0;
  185. width: 100%;
  186. font-size: 30upx;
  187. display: flex;
  188. flex-direction: row;
  189. justify-content: space-between;
  190. align-items: center;
  191. border-top: 2upx solid rgb(238, 238, 238);
  192. .bottomLeft {
  193. display: flex;
  194. flex-direction: row;
  195. align-items: center;
  196. font-size: 26upx;
  197. .money_text {
  198. color: #333333;
  199. padding-left: 30upx;
  200. }
  201. .money {
  202. color: #d32222;
  203. font-size: 40upx;
  204. .unit {
  205. font-size: 26upx;
  206. }
  207. }
  208. }
  209. .bottomRight {
  210. display: flex;
  211. flex-direction: row;
  212. align-items: center;
  213. box-sizing: border-box;
  214. .orderConfirm {
  215. background: $dt-color-primary;
  216. width: 210upx;
  217. text-align: center;
  218. height: 98upx;
  219. line-height: 98upx;
  220. color: white;
  221. box-sizing: border-box;
  222. font-size: 30upx;
  223. }
  224. }
  225. }
  226. </style>