czPayModal.vue 5.3 KB

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