recharge.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <view>
  3. <u-navbar title="充值"></u-navbar>
  4. <view class="recharge">
  5. <view class="title">选择充值金额</view>
  6. <p>当前余额{{detail.balance}}</p>
  7. <view class="rechargeMain">
  8. <view class="recharge-item" :class="otherNum&&moneyActiveClass == item.id ? 'active' : ''"
  9. v-for="(item,index) in moneyList" :key="item.id" @click="moneyClick(item.id,item)">
  10. {{item.rechargeAmount}}
  11. <view class="amount">赠20元</view>
  12. </view>
  13. </view>
  14. <p>其他充值金额</p>
  15. <view
  16. @click="moneyClick(-1)"
  17. :class="!otherNum&&moneyActiveClass == -1? 'active' : ''"
  18. class="recharge-input self-stop">
  19. <u-input v-model="otherNum" @input="ckInput" type="text" :border="true" />
  20. </view>
  21. <view class="title">选择支付方式</view>
  22. <view class="recharge-radio">
  23. <u-radio-group v-model="value2" @change="radioGroupChange" :wrap="true" width="100%">
  24. <u-radio active-color="#00B962" @change="radioChange" v-for="(item, index) in list" :key="index"
  25. :name="item.name" :disabled="item.disabled" width="100%">
  26. <view class="recharge-radio-item">
  27. <u-icon :name="item.icon" custom-prefix="custom-icon" :color="item.color" size="48">
  28. </u-icon>
  29. <view class="recharge-radio-name">
  30. {{item.name}}
  31. </view>
  32. </view>
  33. </u-radio>
  34. </u-radio-group>
  35. </view>
  36. <view class="recharge-btn">
  37. <u-checkbox-group>
  38. <u-checkbox v-model="checked" shape="circle" @change="checkboxChange()">我已阅读并同意《充值协议》</u-checkbox>
  39. </u-checkbox-group>
  40. <u-button class="success-btn" shape="circle" type="success" @click="rechargeNow">
  41. <span>立即充值</span>
  42. </u-button>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import * as Pay from '@/apis/weixin.js'
  49. import {
  50. wxPayJs
  51. } from '@/utils/wxpay'
  52. import * as API from '@/apis/finance.js'
  53. export default {
  54. data() {
  55. return {
  56. selectItem:{},
  57. userId: '',
  58. detail: {},
  59. moneyActiveClass: 1,
  60. moneyList: [
  61. ],
  62. list: [{
  63. name: '微信支付',
  64. icon: 'wechat-pay-fill',
  65. color: '#22ac38',
  66. },
  67. {
  68. name: '支付宝支付',
  69. icon: 'alipay-fill',
  70. color: '#1677ff',
  71. },
  72. ],
  73. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  74. value2: '微信支付',
  75. otherNum:"",
  76. value1: '',
  77. checked: true,
  78. }
  79. },
  80. onReady() {
  81. if (this.carhelp.getPersonInfo() != null) {
  82. this.userId = this.carhelp.getPersonInfo().id;
  83. }
  84. this.init();
  85. },
  86. methods: {
  87. ckInput(text){
  88. if(text.indexOf('.')>0){
  89. this.$nextTick(()=>{
  90. this.otherNum=text.substring(0,text.indexOf('.'))
  91. uni.showToast({
  92. title:"请输入正整数"
  93. })
  94. })
  95. }
  96. var t =Number(text);
  97. if(t<1){
  98. this.$nextTick(()=>{
  99. this.otherNum='';
  100. })
  101. }
  102. if(t>500){
  103. this.$nextTick(()=>{
  104. this.otherNum=500;
  105. })
  106. }
  107. },
  108. submit() {
  109. uni.showLoading({
  110. title: "加载中",
  111. mask: true,
  112. })
  113. Pay.wxpay({
  114. chargingMarketingId: this.chargingMarketingId,
  115. type:2
  116. }).then((response) => {
  117. if (!response.result) {
  118. uni.showToast({
  119. title: response.message
  120. })
  121. return
  122. }
  123. var data = response.data
  124. uni.hideLoading()
  125. console.log("Pay+" + new Date().getTime())
  126. wxPayJs(data);
  127. }).catch(error => {
  128. this.$refs.common.showLoading(false, error);
  129. })
  130. },
  131. init1() {
  132. uni.showLoading({
  133. title: "加载中",
  134. mask: true,
  135. })
  136. API.personalCenter().then((res) => {
  137. this.detail = res.data
  138. this.isReady = true;
  139. uni.hideLoading()
  140. }).catch(error => {
  141. uni.showToast({
  142. title: error
  143. })
  144. })
  145. },
  146. init() {
  147. uni.showLoading({
  148. title: "加载中",
  149. mask: true,
  150. })
  151. var data = {
  152. type:2 };
  153. API.marketingData(data).then((res) => {
  154. this.moneyList = res.data.chargingMarketingList
  155. if (this.moneyList.length > 0) {
  156. this.selectItem = this.moneyList[0];
  157. this.moneyActiveClass = this.moneyList[0].id
  158. console.log(this.moneyActiveClass)
  159. }
  160. uni.hideLoading()
  161. this.init1()
  162. }).catch(error => {
  163. uni.showToast({
  164. title: error
  165. })
  166. })
  167. },
  168. moneyClick(index,item) {
  169. this.moneyActiveClass = index;
  170. this.selectItem=item;
  171. },
  172. // 选中某个单选框时,由radio时触发
  173. radioChange(e) {
  174. // console.log(e);
  175. },
  176. // 选中任一radio时,由radio-group触发
  177. radioGroupChange(e) {
  178. // console.log(e);
  179. },
  180. checkboxChange() {
  181. this.checked = !this.checked;
  182. },
  183. rechargeNow() {
  184. if(this.moneyActiveClass==-1&&!this.otherNum){
  185. this.submitForm.chargeStrategy=0;
  186. this.submitForm.amount=0
  187. }else{
  188. this.submitForm.chargeStrategy=2;
  189. if(this.otherNum){
  190. this.submitForm.amount=this.otherNum
  191. }else{
  192. this.submitForm.amount=this.moneyActiveClass
  193. }
  194. }
  195. console.log(this.submitForm)
  196. }
  197. },
  198. onShow() {
  199. if (this.isReady) {
  200. this.init1()
  201. }
  202. }
  203. }
  204. </script>
  205. <style>
  206. page {
  207. background-color: #fff;
  208. }
  209. </style>
  210. <style lang="scss" scoped>
  211. /deep/.u-radio-group {
  212. width: 100%;
  213. }
  214. /deep/.u-radio {
  215. position: relative;
  216. }
  217. /deep/.u-radio__icon-wrap {
  218. position: absolute;
  219. right: 0;
  220. }
  221. .recharge {
  222. padding: 16px;
  223. .title {
  224. font-size: 16px;
  225. }
  226. p {
  227. color: #666;
  228. margin-top: 4px;
  229. }
  230. .self-stop.active{
  231. background-color: #EFFFF7;
  232. border-color: #00B962;
  233. color: #00B962;
  234. }
  235. .rechargeMain {
  236. display: flex;
  237. flex-wrap: wrap;
  238. justify-content: space-between;
  239. margin-top: 12px;
  240. margin-bottom: 20px;
  241. .recharge-item {
  242. width: 31%;
  243. border: 1px solid #e3e3e3;
  244. padding: 15px 0;
  245. border-radius: 4px;
  246. text-align: center;
  247. margin-bottom: 10px;
  248. font-size: 16px;
  249. position: relative;
  250. }
  251. .amount {
  252. // width: 41.9%;
  253. height: 16px;
  254. line-height: 15px;
  255. border-radius: 0px 4px 0px 4px;
  256. background-color: rgba(0, 185, 98, 100);
  257. color: rgba(255, 255, 255, 100);
  258. font-size: 10px;
  259. text-align: center;
  260. position: absolute;
  261. top: 0;
  262. right: 0;
  263. }
  264. .active {
  265. background-color: #EFFFF7;
  266. border-color: #00B962;
  267. color: #00B962;
  268. }
  269. }
  270. }
  271. .recharge-input {
  272. margin-top: 8px;
  273. margin-bottom: 32px;
  274. }
  275. .recharge-radio {
  276. margin-top: 10px;
  277. .recharge-radio-item {
  278. display: flex;
  279. align-items: center;
  280. }
  281. .recharge-radio-name {
  282. margin-left: 8px;
  283. }
  284. }
  285. .recharge-btn {
  286. position: fixed;
  287. left: 16px;
  288. right: 16px;
  289. bottom: 16px;
  290. }
  291. .success-btn {
  292. margin-top: 10px;
  293. background-color: #00B962 !important;
  294. flex: 1;
  295. border-color: #00B962 !important;
  296. color: #fff !important;
  297. }
  298. </style>