index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. <template>
  2. <view class="content">
  3. <view class="nav">
  4. <view class="nav-item" v-for="item in navList" :key="item.ctype" :class="{'action': ctype == item.ctype}"
  5. @click="getYjList('re',item.ctype)">
  6. {{item.name}}
  7. </view>
  8. </view>
  9. <view class="" style="height: 20rpx;">
  10. </view>
  11. <view class="search-box flex">
  12. <input type="text" v-model="phone" placeholder="输入手机号码" />
  13. <view class="search-btn" @click="goCz()">
  14. 充值
  15. </view>
  16. </view>
  17. <template v-if="ctype == 2">
  18. <picker @change="bindPickerChange" :value="chooseId" :range="provinces" range-key="label">
  19. <view class="search-box sf-wrap flex">
  20. <view class="">
  21. 省份
  22. </view>
  23. <view class="">{{province || '请选择省份'}}</view>
  24. </view>
  25. </picker>
  26. <view class="search-box sf-wrap flex">
  27. <view class="">
  28. 姓名
  29. </view>
  30. <input type="text" placeholder="请输入户主姓名" class="name-inp" v-model="userName"/>
  31. </view>
  32. </template>
  33. <view class='search-box sf-wrap flex'>
  34. <view>积分抵扣</view>
  35. <view class='discount acea-row row-middle'>
  36. <view style="margin-right: 10rpx;"> 当前积分
  37. <text class='num font-color'>{{userInfo.integral || 0}}</text>
  38. </view>
  39. <view class="cb" @click="changeUseIntegral">
  40. <view v-show="useIntegral" class="cb-in" >
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="item-wrap" v-for="item in info">
  46. <view class="tit">
  47. {{item.cname}}
  48. </view>
  49. <view class="item-list flex">
  50. <view class="item " v-for="itemt in item.goods" :class="{'action': itemt.goods_id == choose.goods_id}"
  51. @click="chooseGood(itemt)">
  52. <view class="num">
  53. {{itemt.num}}元
  54. </view>
  55. <!-- <view class="base-price">
  56. {{itemt.price}}
  57. </view> -->
  58. </view>
  59. </view>
  60. <template v-if="item.area">
  61. <view class="tit-area">
  62. 地区:
  63. </view>
  64. <view class="area-item">
  65. <text v-for="area in item.area">{{area}}</text>
  66. </view>
  67. </template>
  68. </view>
  69. <view class="item-wrap" v-if="content && ctype != 2 && info.length > 0">
  70. <view class="tit">
  71. 注意事项
  72. </view>
  73. <view class="tip" v-html="content">
  74. </view>
  75. </view>
  76. <uni-popup ref="popup" type="bottom">
  77. <view class="cz-model">
  78. <view class="price">
  79. {{priceInfo.payPrice}}
  80. </view>
  81. <view class="">
  82. {{choose.goods_name}}
  83. </view>
  84. <view class="">
  85. 到账时间:1-96小时 (高峰期96小时内)
  86. </view>
  87. <view class="">
  88. 充值号码:<text class="tip">{{phone}}</text>
  89. </view>
  90. <view class="tip tips">
  91. 请仔细核对号码。输错号码后果自负
  92. </view>
  93. <view class="pay-type-list ">
  94. </view>
  95. <!-- <view class='item acea-row row-between-wrapper' v-if="userInfo.integral > 0"> -->
  96. <view class="btn" @click="goNew">
  97. 立即充值
  98. </view>
  99. </view>
  100. </uni-popup>
  101. <payment v-if="totalPrice" :payMode="cartArr" :pay_close="pay_close" :isCall="true" :totalPrice="totalPrice"
  102. @changePayType="changePayType" @onChangeFun="onChangeFun"></payment>
  103. </view>
  104. </template>
  105. <script>
  106. import payment from '@/components/payment';
  107. import {
  108. getCzList,
  109. createCz,
  110. computedCz
  111. } from '@/api/three'
  112. import {
  113. getUserInfo
  114. } from '@/api/user.js'
  115. import {
  116. getCityData
  117. } from '@/api/api.js'
  118. // import { passUser } from '@/api/zero.js'
  119. export default {
  120. components: {
  121. payment,
  122. },
  123. data() {
  124. return {
  125. toPay: false,
  126. paying: false,
  127. navList: [{
  128. name: '话费慢充',
  129. ctype: 0
  130. }, {
  131. name: '话费快充',
  132. ctype: 1
  133. },
  134. {
  135. name: '电费充值',
  136. ctype: 2
  137. }
  138. ],
  139. useIntegral: false,
  140. phone: '',
  141. info: [],
  142. content: '',
  143. choose: {
  144. goods_id: 0
  145. },
  146. payType:1,
  147. payName: 'weixin',
  148. userInfo: {},
  149. ctype: 0,
  150. province: '', //省份
  151. provinces: [],
  152. chooseId: 0,
  153. priceInfo: {},
  154. userName: '',
  155. totalPrice: 0,
  156. pay_close: false,
  157. cartArr: [{
  158. "name": "微信支付",
  159. "icon": "icon-weixin2",
  160. value: 'weixin',
  161. title: '使用微信快捷支付',
  162. payStatus: 1,
  163. },
  164. {
  165. "name": "余额支付",
  166. "icon": "icon-yuezhifu",
  167. value: 'yue',
  168. title: '可用余额:',
  169. payStatus: 1,
  170. },
  171. ],
  172. }
  173. },
  174. onLoad() {
  175. this.getUserInfo()
  176. this.getCzList()
  177. this.getCityData()
  178. },
  179. onShow() {},
  180. onReachBottom() {
  181. },
  182. onReady() {
  183. },
  184. methods: {
  185. changePayType(type) {
  186. console.log(type)
  187. // this.payType = type
  188. },
  189. getCityData() {
  190. getCityData().then(res => {
  191. console.log(res)
  192. this.provinces = res.data
  193. })
  194. },
  195. bindPickerChange(e) {
  196. console.log(e)
  197. this.province = this.provinces[e.detail.value].label
  198. },
  199. getYjList(tip, ctype) {
  200. this.ctype = ctype
  201. this.info = []
  202. this.getCzList()
  203. },
  204. changeUseIntegral: function() {
  205. this.useIntegral = !this.useIntegral;
  206. if(this.choose.goods_id) {
  207. this.computedPrice();
  208. }
  209. },
  210. // 计算价格
  211. computedPrice() {
  212. computedCz({
  213. integral: this.useIntegral ? 1: 0,
  214. num: this.choose.num,
  215. uid: this.userInfo.uid
  216. }).then(res => {
  217. this.priceInfo = res.data
  218. this.totalPrice = res.data.payPrice
  219. })
  220. },
  221. getUserInfo: function() {
  222. let that = this;
  223. getUserInfo().then(res => {
  224. that.userInfo = res.data
  225. this.cartArr[1].number = res.data.now_money
  226. });
  227. },
  228. //选择支付方式
  229. changePayType(type) {
  230. this.payType = type;
  231. if (this.payType == 1) {
  232. this.payName = 'weixin';
  233. }
  234. if (this.payType == 2) {
  235. this.payName = 'ali';
  236. }
  237. if (this.payType == 3) {
  238. this.payName = 'yue';
  239. }
  240. },
  241. goCz() {
  242. if (!this.phone) {
  243. return this.$util.Tips({
  244. title: '请输入手机号'
  245. });
  246. }
  247. var pattern = /^1[0-9]{10}$/;
  248. if (!pattern.test(this.phone)) {
  249. return this.$util.Tips({
  250. title: '请输入正确的手机号'
  251. });
  252. }
  253. if (!this.choose.goods_id) {
  254. return this.$util.Tips({
  255. title: '请选择需要充值的套餐'
  256. });
  257. }
  258. if (this.ctype == 2) {
  259. if (!this.province) {
  260. return this.$util.Tips({
  261. title: '请选择省份'
  262. });
  263. }
  264. if (!this.userName) {
  265. return this.$util.Tips({
  266. title: '请输入姓名'
  267. });
  268. }
  269. } else {
  270. // 校验手机
  271. let phoneType = this.getMobileOperator(this.phone)
  272. if (this.choose.goods_name.indexOf(phoneType) == -1) {
  273. this.choose = {}
  274. return uni.showModal({
  275. title: '温馨提醒',
  276. content: `您当前的手机号为${phoneType}号码,与充值套餐的运营商不一致,请重新选择套餐!`,
  277. showCancel: false
  278. })
  279. }
  280. }
  281. // this.$refs.popup.open()
  282. this.pay_close = true
  283. },
  284. getMobileOperator(phoneNumber) {
  285. // 移动号段
  286. var cmccPrefixes = ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159',
  287. '182', '183', '184', '187', '188', '178', '147', '172', '198'
  288. ];
  289. // 联通号段
  290. var cuccPrefixes = ['130', '131', '132', '155', '156', '185', '186', '145', '176', '175', '166'];
  291. // 电信号段
  292. var ctcPrefixes = ['133', '153', '180', '181', '189', '177', '173', '199'];
  293. // 虚拟运营商号段
  294. var virtualPrefixes = ['170', '171'];
  295. var prefix = phoneNumber.substring(0, 3);
  296. if (cmccPrefixes.includes(prefix)) {
  297. return '移动';
  298. } else if (cuccPrefixes.includes(prefix)) {
  299. return '联通';
  300. } else if (ctcPrefixes.includes(prefix)) {
  301. return '电信';
  302. } else if (virtualPrefixes.includes(prefix)) {
  303. return '虚拟运营商';
  304. } else {
  305. return '未知运营商';
  306. }
  307. },
  308. onChangeFun(e) {
  309. //
  310. console.log(e)
  311. let that = this
  312. if(e.action == 'payClose') {
  313. this.pay_close = false
  314. return
  315. }else {
  316. if(e.value == 'yue') {
  317. if(that.priceInfo.payPrice*1 > that.userInfo.now_money) {
  318. return this.$util.Tips({
  319. title: '当前余额不足'
  320. });
  321. }
  322. }
  323. let qdata = {
  324. goods_id: this.choose.goods_id,
  325. rechargeno: this.phone,
  326. province: this.province,
  327. pay_type: e.value,
  328. pay_price: this.priceInfo.payPrice,
  329. store_id: 0,
  330. user_phone: this.phone,
  331. real_name: this.userName,
  332. deduction_price: this.priceInfo.deduction_price,
  333. deduction_integral: this.priceInfo.deduction_integral,
  334. deduction_price: this.priceInfo.deduction_price,
  335. cid: this.choose.cid,
  336. goods_name: this.choose.goods_name,
  337. type: this.ctype,
  338. // #ifdef MP
  339. 'from': 'routine',
  340. // #endif
  341. // #ifdef H5
  342. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  343. // #endif
  344. }
  345. if(that.paying) {
  346. return
  347. }
  348. that.paying = true
  349. createCz(qdata).then(res => {
  350. setTimeout(()=> {
  351. that.paying = false
  352. },2500)
  353. let status = res.data.status,
  354. // orderId = res.data.result.order_id,
  355. jsConfig = res.data.result.jsConfig
  356. // goPages = '/pages/goods/order_pay_status/index?order_id=' + orderId + '&msg=' + res
  357. // .msg +
  358. // '&type=6' + '&totalPrice=' + this.totalPrice + '&pay_type=' + e.value
  359. switch (status) {
  360. case 'ORDER_EXIST':
  361. case 'EXTEND_ORDER':
  362. case 'PAY_ERROR':
  363. uni.hideLoading();
  364. that.pay_close = false
  365. return that.$util.Tips({
  366. title: res.msg
  367. });
  368. break;
  369. case 'SUCCESS':
  370. uni.hideLoading();
  371. // if (that.BargainId || that.combinationId || that.pinkId || that.seckillId ||
  372. // that
  373. // .discountId)
  374. // return that.$util.Tips({
  375. // title: res.msg,
  376. // icon: 'success'
  377. // }, {
  378. // tab: 4,
  379. // url: goPages+ '&pay_end=SUCCESS'
  380. // });
  381. that.pay_close = false
  382. return that.$util.Tips({
  383. title: res.msg,
  384. icon: 'success'
  385. });
  386. break;
  387. case 'WECHAT_PAY':
  388. that.toPay = true;
  389. // #ifdef MP
  390. /* that.toPay = true; */
  391. let mp_pay_name = ''
  392. if (uni.requestOrderPayment) {
  393. mp_pay_name = 'requestOrderPayment'
  394. } else {
  395. mp_pay_name = 'requestPayment'
  396. }
  397. uni[mp_pay_name]({
  398. timeStamp: jsConfig.timestamp,
  399. nonceStr: jsConfig.nonceStr,
  400. package: jsConfig.package,
  401. signType: jsConfig.signType,
  402. paySign: jsConfig.paySign,
  403. success: function(res) {
  404. uni.hideLoading();
  405. return that.$util.Tips({
  406. title: '支付成功',
  407. icon: 'success'
  408. });
  409. },
  410. fail: function(e) {
  411. uni.hideLoading();
  412. return that.$util.Tips({
  413. title: '取消支付'
  414. });
  415. },
  416. complete: function(e) {
  417. uni.hideLoading();
  418. //关闭当前页面跳转至订单状态
  419. if (res.errMsg == 'requestPayment:cancel') return that
  420. .$util
  421. .Tips({
  422. title: '取消支付'
  423. });
  424. },
  425. })
  426. // #endif
  427. // #ifdef H5
  428. this.$wechat.pay(res.data.result.jsConfig).then(res => {
  429. return that.$util.Tips({
  430. title: '支付成功',
  431. icon: 'success'
  432. });
  433. }).catch(res => {
  434. if (!this.$wechat.isWeixin()) {
  435. // uni.redirectTo({
  436. // url: goPages +
  437. // '&msg=支付失败&status=2' + '&pay_end=SUCCESS'
  438. // })
  439. }
  440. if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
  441. title: '取消支付'
  442. });
  443. })
  444. // #endif
  445. break;
  446. case 'PAY_DEFICIENCY':
  447. uni.hideLoading();
  448. //余额不足
  449. return that.$util.Tips({
  450. title: res.msg
  451. });
  452. break;
  453. case "WECHAT_H5_PAY":
  454. uni.hideLoading();
  455. that.$util.Tips({
  456. title: '订单创建成功!'
  457. });
  458. setTimeout(() => {
  459. location.href = res.data.result.jsConfig.mweb_url;
  460. }, 2000);
  461. break;
  462. case 'ALIPAY_PAY':
  463. //#ifdef H5
  464. if (this.from === 'weixin') {
  465. } else {
  466. uni.hideLoading();
  467. that.formContent = res.data.result.jsConfig;
  468. that.$nextTick(() => {
  469. document.getElementById('alipaysubmit').submit();
  470. })
  471. }
  472. //#endif
  473. // #ifdef MP
  474. uni.navigateTo({
  475. url: `/pages/users/alipay_invoke/index?id=${orderId}&link=${jsConfig.qrCode}`
  476. });
  477. // #endif
  478. // #ifdef APP-PLUS
  479. uni.requestPayment({
  480. provider: 'alipay',
  481. orderInfo: jsConfig,
  482. success: (e) => {
  483. uni.showToast({
  484. title: "支付成功"
  485. })
  486. let url = '/pages/goods/order_pay_status/index?order_id=' +
  487. orderId +
  488. '&msg=支付成功';
  489. setTimeout(res => {
  490. uni.redirectTo({
  491. url: url
  492. })
  493. }, 2000)
  494. },
  495. fail: (e) => {
  496. let url = '/pages/goods/order_pay_status/index?order_id=' +
  497. orderId +
  498. '&msg=支付失败';
  499. uni.showModal({
  500. content: "支付失败",
  501. showCancel: false,
  502. success: function(res) {
  503. if (res.confirm) {
  504. uni.redirectTo({
  505. url: url
  506. })
  507. } else if (res.cancel) {
  508. console.log('用户点击取消');
  509. }
  510. }
  511. })
  512. },
  513. complete: () => {
  514. uni.hideLoading();
  515. },
  516. });
  517. // #endif
  518. break;
  519. }
  520. })
  521. }
  522. },
  523. chooseGood(item) {
  524. this.choose = item
  525. this.computedPrice()
  526. },
  527. getCzList() {
  528. let that = this
  529. uni.showLoading({
  530. title: '加载中...'
  531. })
  532. getCzList({
  533. ctype: that.ctype
  534. }).then(res => {
  535. uni.hideLoading()
  536. this.info = res.data
  537. this.info.forEach(item => {
  538. if (item.goods.length > 0) {
  539. item.goods.forEach(itemt => {
  540. if (itemt.desc && itemt.desc.split('<p>').length > 1) {
  541. that.content = itemt.desc
  542. }
  543. })
  544. }
  545. })
  546. })
  547. },
  548. }
  549. }
  550. </script>
  551. <style lang="scss" scoped>
  552. .flex {
  553. display: flex;
  554. align-items: center;
  555. // justify-content: space-between;
  556. }
  557. .content {
  558. // padding-top: 20rpx;
  559. padding-bottom: 20rpx;
  560. }
  561. .phone {
  562. width: 690rpx;
  563. height: 80rpx;
  564. background-color: #fff;
  565. border-radius: 220rpx;
  566. margin: 0 auto 20rpx;
  567. }
  568. .item-wrap {
  569. width: 690rpx;
  570. background-color: #fff;
  571. margin: 0 auto 20rpx;
  572. padding: 20rpx 34rpx;
  573. border-radius: 20rpx;
  574. .tip {
  575. width: 620rpx;
  576. margin: auto;
  577. background-color: #e9f1fe;
  578. padding: 20rpx;
  579. border-radius: 20rpx;
  580. margin-top: 40rpx;
  581. }
  582. .tit {
  583. font-size: 30rpx;
  584. font-weight: bold;
  585. }
  586. .item-list {
  587. justify-content: flex-start;
  588. padding-top: 40rpx;
  589. .item {
  590. // width: 192rpx;
  591. border-radius: 20rpx;
  592. margin-right: 20rpx;
  593. background-color: #e9f1fe;
  594. text-align: center;
  595. padding: 40rpx;
  596. .num {
  597. color: #409EFF;
  598. font-weight: bold;
  599. font-size: 28rpx;
  600. }
  601. .base-price {
  602. padding-top: 10rpx;
  603. font-size: 22rpx;
  604. }
  605. .price {
  606. font-size: 28rpx;
  607. color: #f3253a;
  608. padding-top: 10rpx;
  609. }
  610. }
  611. .action {
  612. border: 1px solid #f3253a;
  613. }
  614. }
  615. }
  616. .top-search {
  617. height: 80rpx;
  618. padding: 0 20rpx;
  619. width: 100%;
  620. height: 116rpx;
  621. z-index: 99;
  622. .search {
  623. width: 24rpx;
  624. margin-right: 20rpx;
  625. }
  626. }
  627. .search-box {
  628. justify-content: flex-start;
  629. width: 690rpx;
  630. height: 72rpx;
  631. background: rgb(255, 255, 255);
  632. border-radius: 30rpx;
  633. padding: 0 10rpx 0 20rpx;
  634. margin: 0 auto 20rpx;
  635. input {
  636. flex-grow: 1;
  637. height: 72rpx;
  638. line-height: 72rpx;
  639. }
  640. .search-btn {
  641. flex-shrink: 0;
  642. width: 110rpx;
  643. height: 52rpx;
  644. text-align: center;
  645. line-height: 50rpx;
  646. color: #fff;
  647. background-color: #409EFF;
  648. border-radius: 26rpx;
  649. }
  650. }
  651. .cz-model {
  652. width: 750rpx;
  653. background-color: #fff;
  654. padding: 60rpx 0 30rpx;
  655. text-align: center;
  656. border-radius: 25rpx 25rpx 0 0;
  657. view {
  658. padding: 10rpx 0;
  659. }
  660. .price {
  661. color: #409eff;
  662. font-size: 48rpx;
  663. font-weight: bold;
  664. }
  665. .tip {
  666. color: #409eff;
  667. }
  668. .tips {
  669. padding-bottom: 20rpx;
  670. }
  671. .btn {
  672. width: 690rpx;
  673. text-align: center;
  674. line-height: 60rpx;
  675. color: #fff;
  676. background-color: #409eff;
  677. border-radius: 40rpx;
  678. margin: auto;
  679. }
  680. }
  681. .pay-type-list {
  682. margin-top: 20upx;
  683. background-color: #fff;
  684. padding-left: 60upx;
  685. .type-item {
  686. height: 120upx;
  687. padding: 20upx 0;
  688. display: flex;
  689. justify-content: flex-start;
  690. align-items: center;
  691. padding-right: 60upx;
  692. font-size: 30upx;
  693. position: relative;
  694. }
  695. .icon {
  696. width: 100upx;
  697. font-size: 52upx;
  698. }
  699. .iconyue {
  700. color: #fe8e2e;
  701. }
  702. .iconweixin {
  703. color: #36cb59;
  704. }
  705. .iconzhifubao {
  706. color: #01aaef;
  707. }
  708. .tit {
  709. font-size: 28rpx;
  710. color: #000;
  711. margin-bottom: 4upx;
  712. }
  713. .con {
  714. flex: 1;
  715. display: flex;
  716. flex-direction: column;
  717. font-size: 26rpx;
  718. color: #000;
  719. }
  720. }
  721. .tit-area {
  722. font-size: 26rpx;
  723. padding: 20rpx 0;
  724. }
  725. .area-item {
  726. padding-left: 20rpx;
  727. font-size: 24rpx;
  728. }
  729. .nav {
  730. display: flex;
  731. justify-content: space-evenly;
  732. .nav-item {
  733. width: 50%;
  734. line-height: 60rpx;
  735. text-align: center;
  736. color: #1890FF;
  737. border: 1px solid #1890FF;
  738. font-size: 28rpx;
  739. background-color: #fff;
  740. }
  741. .action {
  742. background-color: #1890FF;
  743. color: #fff;
  744. font-weight: bold;
  745. }
  746. }
  747. .sf-wrap {
  748. justify-content: space-between;
  749. padding: 0 20rpx;
  750. }
  751. .cb {
  752. width: 30rpx;
  753. border-radius: 50%;
  754. height: 30rpx;
  755. border: 1px solid #1890FF;
  756. // position: absolute;
  757. display: flex;
  758. justify-content: center;
  759. align-items: center;
  760. .cb-in {
  761. width: 20rpx;
  762. height: 20rpx;
  763. border-radius: 50%;
  764. background-color: #1890FF;
  765. }
  766. }
  767. .name-inp {
  768. // width: ;
  769. flex-grow: 1;
  770. text-align: right;
  771. }
  772. </style>