payModal.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <page-container
  3. :show="showModal"
  4. :round="true"
  5. :z-index="100"
  6. position="bottom"
  7. customStyle="border-radius:15px 15px 0 0;"
  8. @beforeleave="beforeClose"
  9. @afterleave="closePopu">
  10. <view class="popu-content" v-if="payInfo">
  11. <view class="popu-close" @click="cancelPay">
  12. <uni-icons size="26" type="closeempty"></uni-icons>
  13. </view>
  14. <view class="pupu-box-pay-item">
  15. <view class="popu-content-amount flex align_center justify_center">
  16. <view>¥{{payInfo.totalAmount}}</view>
  17. </view>
  18. <view class="flex align_center justify_between" v-if="payInfo.totalSpecialGiveAmount>0">
  19. <text>总优惠</text>
  20. <view class="popu-content-price">¥{{payInfo.totalSpecialGiveAmount}}</view>
  21. </view>
  22. <view class="flex align_center justify_between" v-if="payInfo.totalTicketGiveAmount>0">
  23. <text>代金券</text>
  24. <view class="popu-content-price">¥{{payInfo.totalTicketGiveAmount}}</view>
  25. </view>
  26. <view style="height: 10px;"></view>
  27. <view class="popu-content-title flex align_center justify_between">
  28. <text>付款方式</text>
  29. <view></view>
  30. </view>
  31. <view class="popu-content-pay flex align_center justify_between">
  32. <view class="flex align_center"><uni-icons size="20" type="weixin" color="#4CAF50"></uni-icons> <text style="margin-left: 5px;">微信支付</text></view>
  33. <view><uni-icons size="22" type="checkbox-filled" color="red"></uni-icons></view>
  34. </view>
  35. </view>
  36. <view class="popu-content-btn">
  37. <view class="popu-content-btn-item okbtn" @click="confirmPay">确定付款</view>
  38. </view>
  39. </view>
  40. </page-container>
  41. </template>
  42. <script>
  43. export default {
  44. props: {
  45. showPopu: {
  46. type: Boolean,
  47. default: false
  48. },
  49. payInfo: {
  50. type: Object,
  51. default: ()=>{
  52. return null
  53. }
  54. },
  55. payData: {
  56. type: Object,
  57. default: ()=>{
  58. return null
  59. }
  60. },
  61. cancelPayMessage: {
  62. type: String,
  63. default: '您的订单在30分钟内未支付将被取消,请尽快完成支付。'
  64. },
  65. closeCurPage:{
  66. type: Boolean,
  67. default: false
  68. }
  69. },
  70. data() {
  71. return {
  72. submitOk: false,
  73. showModal: this.showPopu
  74. }
  75. },
  76. watch: {
  77. showPopu(val){
  78. this.showModal = val
  79. if(val){
  80. this.submitOk = false
  81. }
  82. },
  83. showModal(val){
  84. if(!val){
  85. this.$emit('close', val)
  86. }
  87. }
  88. },
  89. methods: {
  90. beforeClose(){
  91. if(this.showModal){
  92. this.cancelPay()
  93. }
  94. },
  95. // 关闭确定订单弹窗后
  96. closePopu(){
  97. if(!this.showModal){
  98. if(this.closeCurPage){
  99. uni.navigateBack()
  100. }
  101. // 付款成功
  102. if(this.submitOk){
  103. this.$emit('payComplete',this.payInfo, true)
  104. }else{
  105. // 付款失败或取消
  106. this.$emit('payComplete',this.payInfo, false)
  107. }
  108. }
  109. this.showModal = false
  110. },
  111. // 确认取消付款弹框
  112. cancelPay(){
  113. const _this = this
  114. uni.showModal({
  115. title: '确定取消支付吗?',
  116. content: _this.cancelPayMessage,
  117. confirmText: '继续支付',
  118. cancelText: '取消支付',
  119. success(ret) {
  120. // 确定取消,跳转到订单详情页
  121. if(ret.cancel){
  122. if(_this.showModal){
  123. _this.showModal = false
  124. _this.submitOk = false
  125. }else{
  126. if(_this.closeCurPage){
  127. uni.navigateBack()
  128. }
  129. _this.$emit('payComplete',_this.payInfo, false)
  130. }
  131. }
  132. // 继续支付
  133. if(ret.confirm){
  134. // 继续支付
  135. if(!_this.showModal){
  136. _this.showModal = true
  137. _this.submitOk = false
  138. }
  139. }
  140. }
  141. })
  142. },
  143. // 确认付款
  144. confirmPay(){
  145. const _this = this
  146. // 确认付款
  147. const data = _this.payData
  148. console.log(data)
  149. if(data){
  150. uni.requestPayment({
  151. provider: 'wxpay',
  152. timeStamp: data.timeStamp,
  153. nonceStr: data.nonceStr,
  154. package: data.package,
  155. signType: data.signType,
  156. paySign: data.paySign,
  157. success: (res) =>{
  158. _this.payComplete(1,true)
  159. },
  160. fail: (err)=> {
  161. _this.payComplete(err.errMsg.indexOf("cancel")>=0 ? 2 : 0,false)
  162. }
  163. });
  164. }else{
  165. _this.payComplete(0,false)
  166. }
  167. },
  168. payComplete(type,data){
  169. uni.showToast({
  170. mask: true,
  171. title: type==1 ? '支付成功' : (type==2?'支付取消':'支付失败'),
  172. icon: 'none'
  173. })
  174. this.showModal = false
  175. this.submitOk = data
  176. },
  177. }
  178. }
  179. </script>
  180. <style lang="less">
  181. .popu-content{
  182. display: flex;
  183. flex-direction: column;
  184. align-items: center;
  185. padding: 10px 15px;
  186. .popu-close{
  187. padding: 10px;
  188. position: absolute;
  189. right: 0;
  190. top: 0;
  191. z-index: 1000;
  192. }
  193. .pupu-box-item,.pupu-box-pay-item{
  194. width: 100%;
  195. > view{
  196. padding: 10px 0;
  197. }
  198. }
  199. .pupu-box-pay-item{
  200. > view{
  201. padding: 6px 0;
  202. }
  203. .popu-content-amount{
  204. font-size: 28px;
  205. color: red;
  206. padding-top: 30px;
  207. }
  208. .popu-content-title{
  209. font-weight: bold;
  210. }
  211. }
  212. .popu-content-btn{
  213. width: 100%;
  214. display: flex;
  215. align-items: center;
  216. justify-content: space-around;
  217. margin: 30px 0 20px;
  218. .popu-content-btn-item{
  219. width: 30%;
  220. height: 34px;
  221. font-size: 14px;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. border-radius: 100px;
  226. }
  227. .cancelBtn{
  228. background-color: #f8f8f8;
  229. color: #666;
  230. }
  231. .okbtn{
  232. background-color: #f70000;
  233. color: #FFFFFF;
  234. width: 65%;
  235. .payAmount{
  236. margin-left: 5px;
  237. }
  238. }
  239. }
  240. }
  241. </style>