payModal.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. },
  66. data() {
  67. return {
  68. submitOk: false,
  69. showModal: this.showPopu
  70. }
  71. },
  72. watch: {
  73. showPopu(val){
  74. this.showModal = val
  75. if(val){
  76. this.submitOk = false
  77. }
  78. },
  79. showModal(val){
  80. if(!val){
  81. this.$emit('close', val)
  82. }
  83. }
  84. },
  85. methods: {
  86. beforeClose(){
  87. if(this.showModal){
  88. this.cancelPay()
  89. }
  90. },
  91. // 关闭确定订单弹窗后
  92. closePopu(){
  93. if(!this.showModal){
  94. // 付款成功
  95. if(this.submitOk){
  96. this.$emit('payComplete',this.payInfo, true)
  97. }else{
  98. // 付款失败或取消
  99. this.$emit('payComplete',this.payInfo, false)
  100. }
  101. }
  102. this.showModal = false
  103. },
  104. // 确认取消付款弹框
  105. cancelPay(){
  106. const _this = this
  107. uni.showModal({
  108. title: '确定取消支付吗?',
  109. content: _this.cancelPayMessage,
  110. confirmText: '继续支付',
  111. cancelText: '取消支付',
  112. success(ret) {
  113. // 确定取消,跳转到订单详情页
  114. if(ret.cancel){
  115. if(_this.showModal){
  116. _this.showModal = false
  117. _this.submitOk = false
  118. }else{
  119. _this.$emit('payComplete',_this.payInfo, false)
  120. }
  121. }
  122. // 继续支付
  123. if(ret.confirm){
  124. // 继续支付
  125. if(!_this.showModal){
  126. _this.showModal = true
  127. _this.submitOk = false
  128. }
  129. }
  130. }
  131. })
  132. },
  133. // 确认付款
  134. confirmPay(){
  135. const _this = this
  136. // 确认付款
  137. const data = _this.payData
  138. console.log(data)
  139. if(data){
  140. uni.requestPayment({
  141. provider: 'wxpay',
  142. timeStamp: data.timeStamp,
  143. nonceStr: data.nonceStr,
  144. package: data.package,
  145. signType: data.signType,
  146. paySign: data.paySign,
  147. success: (res) =>{
  148. _this.payComplete(1)
  149. },
  150. fail: (err)=> {
  151. _this.payComplete(err.errMsg.indexOf("cancel")>=0 ? 2 : 0)
  152. }
  153. });
  154. }else{
  155. _this.payComplete(0,false)
  156. }
  157. },
  158. payComplete(type){
  159. uni.showToast({
  160. mask: true,
  161. title: type==1 ? '支付成功' : (type==2?'支付取消':'支付失败'),
  162. icon: 'none'
  163. })
  164. this.showModal = false
  165. this.submitOk = type==1
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="less">
  171. .popu-content{
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. padding: 10px 15px;
  176. .popu-close{
  177. padding: 10px;
  178. position: absolute;
  179. right: 0;
  180. top: 0;
  181. z-index: 1000;
  182. }
  183. .pupu-box-item,.pupu-box-pay-item{
  184. width: 100%;
  185. > view{
  186. padding: 10px 0;
  187. }
  188. }
  189. .pupu-box-pay-item{
  190. > view{
  191. padding: 6px 0;
  192. }
  193. .popu-content-amount{
  194. font-size: 28px;
  195. color: red;
  196. padding-top: 30px;
  197. }
  198. .popu-content-title{
  199. font-weight: bold;
  200. }
  201. }
  202. .popu-content-btn{
  203. width: 100%;
  204. display: flex;
  205. align-items: center;
  206. justify-content: space-around;
  207. margin: 30px 0 20px;
  208. .popu-content-btn-item{
  209. width: 30%;
  210. height: 34px;
  211. font-size: 14px;
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. border-radius: 100px;
  216. }
  217. .cancelBtn{
  218. background-color: #f8f8f8;
  219. color: #666;
  220. }
  221. .okbtn{
  222. background-color: #f70000;
  223. color: #FFFFFF;
  224. width: 65%;
  225. .payAmount{
  226. margin-left: 5px;
  227. }
  228. }
  229. }
  230. }
  231. </style>