life.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="content">
  3. <view class="search-box flex">
  4. <input type="text" v-model="phone" placeholder="输入手机号码" />
  5. <view class="search-btn" @click="goCz()">
  6. 充值
  7. </view>
  8. </view>
  9. <view class="item-wrap" v-for="item in info">
  10. <view class="tit">
  11. {{item.cname}}
  12. </view>
  13. <view class="item-list flex">
  14. <view class="item " v-for="itemt in item.goods" :class="{'action': itemt.goods_id == choose.goods_id}"
  15. @click="chooseGood(itemt)">
  16. <view class="num">
  17. {{itemt.num}}元
  18. </view>
  19. <view class="base-price">
  20. <!-- 官方¥{{itemt.num}} -->
  21. 赠送:{{(itemt.num*1*pUser.recharge_resumption*0.01).toFixed(0)}}复投积分
  22. </view>
  23. <!-- <view class="price">
  24. 实付{{(itemt.num * 1 * pUser.recharge_discount*1*0.01).toFixed(2)}}
  25. </view> -->
  26. </view>
  27. </view>
  28. </view>
  29. <view class="item-wrap" v-if="content">
  30. <view class="tit">
  31. 注意事项
  32. </view>
  33. <view class="tip" v-html="content">
  34. </view>
  35. </view>
  36. <uni-popup ref="popup" type="bottom">
  37. <view class="cz-model">
  38. <view class="price">
  39. {{choose.num}}
  40. </view>
  41. <view class="">
  42. {{choose.goods_name}}
  43. </view>
  44. <view class="">
  45. 到账时间:1-96小时 (高峰期96小时内)
  46. </view>
  47. <view class="">
  48. 充值号码:<text class="tip">{{this.phone}}</text>
  49. </view>
  50. <view class="tip tips">
  51. 请仔细核对号码。输错号码后果自负
  52. </view>
  53. <view class="pay-type-list ">
  54. <!-- #ifdef APP-PLUS -->
  55. <view class="type-item b-b flex" @click="changePayType(2)">
  56. <text class="icon iconfont iconzhifubao"></text>
  57. <view class="con"><text class="tit">支付宝支付</text></view>
  58. <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 2"></radio></label>
  59. </view>
  60. <!-- #endif -->
  61. <!-- <view class="type-item" @click="changePayType(3)">
  62. <text class="icon iconfont iconyue"></text>
  63. <view class="con">
  64. <text class="tit">消费积分支付</text>
  65. <text>可用消费积分 ¥{{ userInfo.now_money }}</text>
  66. </view>
  67. <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 3"></radio></label>
  68. </view> -->
  69. </view>
  70. <view class="btn" @click="goNew">
  71. 立即充值
  72. </view>
  73. </view>
  74. </uni-popup>
  75. </view>
  76. </template>
  77. <script>
  78. import { mapState } from 'vuex';
  79. import {
  80. getCzList,
  81. createCz
  82. } from '@/api/three'
  83. import { passUser } from '@/api/zero.js'
  84. export default {
  85. data() {
  86. return {
  87. pUser: {},
  88. phone: '',
  89. info: [],
  90. content: '',
  91. choose: {
  92. goods_id: 0
  93. },
  94. payType: 3,
  95. payName: 'ali'
  96. }
  97. },
  98. computed: {
  99. // #ifdef H5
  100. ...mapState(['weichatObj']),
  101. // #endif
  102. ...mapState('user',['userInfo'])
  103. },
  104. onLoad() {},
  105. onShow() {
  106. this.passUser()
  107. },
  108. onReachBottom() {
  109. },
  110. onReady() {
  111. },
  112. onNavigationBarButtonTap(event) {
  113. console.log('nav button pressed', event)
  114. uni.navigateTo({
  115. url: '/pages/index/lifeOrder'
  116. })
  117. },
  118. methods: {
  119. //选择支付方式
  120. changePayType(type) {
  121. this.payType = type;
  122. if (this.payType == 1) {
  123. this.payName = 'weixin';
  124. }
  125. if (this.payType == 2) {
  126. this.payName = 'ali';
  127. }
  128. if (this.payType == 3) {
  129. this.payName = 'yue';
  130. }
  131. },
  132. passUser() {
  133. passUser().then(res => {
  134. this.pUser = res.data
  135. this.getCzList()
  136. })
  137. },
  138. goCz() {
  139. if (!this.phone) {
  140. return this.$api.msg('请输入手机号')
  141. }
  142. var pattern = /^1[0-9]{10}$/;
  143. if (!pattern.test(this.phone)) {
  144. return this.$api.msg('请输入正确的手机号')
  145. }
  146. if (!this.choose.goods_id) {
  147. return this.$api.msg('请选择需要充值的套餐')
  148. }
  149. // 校验手机
  150. let phoneType = this.getMobileOperator(this.phone)
  151. if(this.choose.goods_name.indexOf(phoneType) == -1) {
  152. this.choose = {}
  153. return uni.showModal({
  154. title: '温馨提醒',
  155. content: `您当前的手机号为${phoneType}号码,与充值套餐的运营商不一致,请重新选择套餐!`,
  156. showCancel:false
  157. })
  158. }
  159. this.$refs.popup.open()
  160. },
  161. getMobileOperator(phoneNumber) {
  162. // 移动号段
  163. var cmccPrefixes = ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159', '182', '183', '184', '187', '188', '178', '147', '172', '198'];
  164. // 联通号段
  165. var cuccPrefixes = ['130', '131', '132', '155', '156', '185', '186', '145', '176', '175', '166'];
  166. // 电信号段
  167. var ctcPrefixes = ['133', '153', '180', '181', '189', '177', '173', '199'];
  168. // 虚拟运营商号段
  169. var virtualPrefixes = ['170', '171'];
  170. var prefix = phoneNumber.substring(0, 3);
  171. if (cmccPrefixes.includes(prefix)) {
  172. return '移动';
  173. } else if (cuccPrefixes.includes(prefix)) {
  174. return '联通';
  175. } else if (ctcPrefixes.includes(prefix)) {
  176. return '电信';
  177. } else if (virtualPrefixes.includes(prefix)) {
  178. return '虚拟运营商';
  179. } else {
  180. return '未知运营商';
  181. }
  182. },
  183. // // 示例用法
  184. // var phoneNumber = '13812345678';
  185. // var operator = getMobileOperator(phoneNumber);
  186. // console.log(operator); // 输出: 中国移动
  187. goNew() {
  188. let that = this
  189. if(this.payName == 'yue' && this.userInfo.now_money*1 < this.choose.num) {
  190. return this.$api.msg('当前消费积分不足,请选择其他方式支付!')
  191. }
  192. createCz({
  193. rechargeno: this.phone,
  194. pay_type: this.payName,
  195. goods_id: this.choose.goods_id,
  196. pay_price: this.choose.num,
  197. price: this.choose.num
  198. }).then(res => {
  199. if(res.data.status == 'PAY_DEFICIENCY' ||res.data.status == 'PAY_ERROR') {
  200. this.$api.msg(res.msg)
  201. }else {
  202. if(this.payName == 'ali') {
  203. let da = res.data.result.jsConfig;
  204. uni.requestPayment({
  205. provider: 'alipay',
  206. orderInfo: da, //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  207. success: function (res) {
  208. console.log('success:' + JSON.stringify(res));
  209. uni.showToast({
  210. icon: 'success',
  211. title: '充值成功'
  212. })
  213. // obj.paySuccessTo();
  214. },
  215. fail: function (err) {
  216. console.log('fail:' + JSON.stringify(err));
  217. // uni.navigateTo({
  218. // url: '/pages/order/order?state=0'
  219. // });
  220. }
  221. });
  222. }else {
  223. uni.showToast({
  224. icon: 'success',
  225. title: '充值成功'
  226. })
  227. }
  228. }
  229. this.$refs.popup.close()
  230. })
  231. },
  232. chooseGood(item) {
  233. this.choose = item
  234. },
  235. getCzList() {
  236. let that = this
  237. getCzList().then(res => {
  238. this.info = res.data.data
  239. this.info.forEach(item => {
  240. if (item.goods.length > 0) {
  241. item.goods.forEach(itemt => {
  242. if (itemt.desc && itemt.desc.split('<p>').length > 1) {
  243. that.content = itemt.desc
  244. }
  245. })
  246. }
  247. })
  248. })
  249. },
  250. }
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. .content {
  255. padding-top: 20rpx;
  256. padding-bottom: 20rpx;
  257. }
  258. .phone {
  259. width: 690rpx;
  260. height: 80rpx;
  261. background-color: #fff;
  262. border-radius: 220rpx;
  263. margin: 0 auto 20rpx;
  264. }
  265. .item-wrap {
  266. width: 690rpx;
  267. background-color: #fff;
  268. margin: 0 auto 20rpx;
  269. padding: 20rpx 34rpx;
  270. border-radius: 20rpx;
  271. .tip {
  272. width: 620rpx;
  273. margin: auto;
  274. background-color: #e9f1fe;
  275. padding: 20rpx;
  276. border-radius: 20rpx;
  277. margin-top: 40rpx;
  278. }
  279. .tit {
  280. font-size: 30rpx;
  281. font-weight: bold;
  282. }
  283. .item-list {
  284. justify-content: flex-start;
  285. padding-top: 40rpx;
  286. .item {
  287. // width: 192rpx;
  288. border-radius: 20rpx;
  289. margin-right: 20rpx;
  290. background-color: #e9f1fe;
  291. text-align: center;
  292. padding: 40rpx;
  293. .num {
  294. color: #409EFF;
  295. font-weight: bold;
  296. font-size: 28rpx;
  297. }
  298. .base-price {
  299. padding-top: 10rpx;
  300. font-size: 22rpx;
  301. }
  302. .price {
  303. font-size: 28rpx;
  304. color: #f3253a;
  305. padding-top: 10rpx;
  306. }
  307. }
  308. .action {
  309. border: 1px solid #f3253a;
  310. }
  311. }
  312. }
  313. .top-search {
  314. height: 80rpx;
  315. padding: 0 20rpx;
  316. width: 100%;
  317. height: 116rpx;
  318. z-index: 99;
  319. .search {
  320. width: 24rpx;
  321. margin-right: 20rpx;
  322. }
  323. }
  324. .search-box {
  325. justify-content: flex-start;
  326. width: 690rpx;
  327. height: 72rpx;
  328. background: rgb(255, 255, 255);
  329. border-radius: 30rpx;
  330. padding: 0 10rpx 0 20rpx;
  331. margin: 0 auto 20rpx;
  332. input {
  333. flex-grow: 1;
  334. }
  335. .search-btn {
  336. flex-shrink: 0;
  337. width: 110rpx;
  338. height: 52rpx;
  339. text-align: center;
  340. line-height: 50rpx;
  341. color: #fff;
  342. background-color: $base-color;
  343. border-radius: 26rpx;
  344. }
  345. }
  346. .cz-model {
  347. width: 750rpx;
  348. background-color: #fff;
  349. padding: 60rpx 0 30rpx;
  350. text-align: center;
  351. border-radius: 25rpx 25rpx 0 0;
  352. view {
  353. padding: 10rpx 0;
  354. }
  355. .price {
  356. color: $base-color;
  357. font-size: 48rpx;
  358. font-weight: bold;
  359. }
  360. .tip {
  361. color: #409eff;
  362. }
  363. .tips {
  364. padding-bottom: 20rpx;
  365. }
  366. .btn {
  367. width: 690rpx;
  368. text-align: center;
  369. line-height: 60rpx;
  370. color: #fff;
  371. background-color: $base-color;
  372. border-radius: 40rpx;
  373. margin: auto;
  374. }
  375. }
  376. .pay-type-list {
  377. margin-top: 20upx;
  378. background-color: #fff;
  379. padding-left: 60upx;
  380. .type-item {
  381. height: 120upx;
  382. padding: 20upx 0;
  383. display: flex;
  384. justify-content: flex-start;
  385. align-items: center;
  386. padding-right: 60upx;
  387. font-size: 30upx;
  388. position: relative;
  389. }
  390. .icon {
  391. width: 100upx;
  392. font-size: 52upx;
  393. }
  394. .iconyue {
  395. color: #fe8e2e;
  396. }
  397. .iconweixin {
  398. color: #36cb59;
  399. }
  400. .iconzhifubao {
  401. color: #01aaef;
  402. }
  403. .tit {
  404. font-size: $font-lg;
  405. color: $font-color-dark;
  406. margin-bottom: 4upx;
  407. }
  408. .con {
  409. flex: 1;
  410. display: flex;
  411. flex-direction: column;
  412. font-size: $font-sm;
  413. color: $font-color-light;
  414. }
  415. }
  416. </style>