payModal.vue 5.4 KB

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