czPayModal.vue 5.3 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.rechargeAmount}}</view>
  17. </view>
  18. <view class="flex align_center justify_center">
  19. 充值{{ payInfo.rechargeAmount }}元送{{ payInfo.giveAmount }}元抵扣</text>
  20. </view>
  21. <view style="height: 10px;"></view>
  22. <view class="flex align_center justify_between" v-if="shelfInfo">
  23. <text>配送商:{{shelfInfo.dealerName}}</text>
  24. <view @click="callPhone()"><uni-icons size="18" type="phone" color="dodgerblue"></uni-icons><text style="font-size:12px;">拨打</text></view>
  25. </view>
  26. <view class="popu-content-title flex align_center justify_between">
  27. <text>付款方式</text>
  28. <view></view>
  29. </view>
  30. <view class="popu-content-pay flex align_center justify_between">
  31. <view class="flex align_center"><uni-icons size="20" type="weixin" color="#4CAF50"></uni-icons> <text style="margin-left: 5px;">微信支付</text></view>
  32. <view><uni-icons size="22" type="checkbox-filled" color="red"></uni-icons></view>
  33. </view>
  34. </view>
  35. <view class="popu-content-btn">
  36. <view class="popu-content-btn-item okbtn" @click="confirmPay">立即支付</view>
  37. </view>
  38. </view>
  39. </page-container>
  40. </template>
  41. <script>
  42. export default {
  43. props: {
  44. showPopu: {
  45. type: Boolean,
  46. default: false
  47. },
  48. payInfo: {
  49. type: Object,
  50. default: ()=>{
  51. return null
  52. }
  53. },
  54. shelfInfo:{
  55. type: Object,
  56. default: ()=>{
  57. return null
  58. }
  59. },
  60. payData: {
  61. type: Object,
  62. default: ()=>{
  63. return null
  64. }
  65. },
  66. },
  67. data() {
  68. return {
  69. submitOk: false,
  70. showModal: this.showPopu
  71. }
  72. },
  73. watch: {
  74. showPopu(val){
  75. this.showModal = val
  76. if(val){
  77. this.submitOk = false
  78. }
  79. },
  80. showModal(val){
  81. if(!val){
  82. this.$emit('close', val)
  83. }
  84. }
  85. },
  86. methods: {
  87. // 联系经销商
  88. callPhone() {
  89. if(this.dealerPhone!=''){
  90. uni.makePhoneCall({
  91. phoneNumber: this.dealerPhone
  92. })
  93. }
  94. },
  95. beforeClose(){
  96. if(this.showModal){
  97. this.cancelPay()
  98. }
  99. },
  100. // 关闭确定订单弹窗后
  101. closePopu(){
  102. if(!this.showModal){
  103. // 付款成功
  104. if(this.submitOk){
  105. this.$emit('payComplete',this.payInfo, true)
  106. }else{
  107. // 付款失败或取消
  108. this.$emit('payComplete',this.payInfo, false)
  109. }
  110. }
  111. this.showModal = false
  112. },
  113. // 确认取消付款弹框
  114. cancelPay(){
  115. const _this = this
  116. uni.showModal({
  117. title: '确定取消支付吗?',
  118. content: '',
  119. confirmText: '继续支付',
  120. cancelText: '取消支付',
  121. success(ret) {
  122. // 确定取消,跳转到订单详情页
  123. if(ret.cancel){
  124. if(_this.showModal){
  125. _this.showModal = false
  126. _this.submitOk = false
  127. }else{
  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)
  158. },
  159. fail: (err)=> {
  160. _this.payComplete(err.errMsg.indexOf("cancel")>=0 ? 2 : 0)
  161. }
  162. });
  163. }else{
  164. _this.payComplete(0,false)
  165. }
  166. },
  167. payComplete(type){
  168. uni.showToast({
  169. mask: true,
  170. title: type==1 ? '支付成功' : (type==2?'支付取消':'支付失败'),
  171. icon: 'none'
  172. })
  173. this.showModal = false
  174. this.submitOk = type==1
  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 20px;
  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: 28px;
  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: 30px 0 20px;
  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>