zero.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <template>
  2. <view class="" style="padding-top: 20rpx;">
  3. <view class="flex center-box ">
  4. <!-- <view class="flex center-item" @click="navto('/pages/user/xzdl?type=2')">
  5. <view class="val">
  6. 1000
  7. </view>
  8. <view class="name">我的消费包</view>
  9. </view>
  10. <view class="line">
  11. </view> -->
  12. <view class="flex center-item" @click="navto('/pages/zero/gfz')">
  13. <view class="val" v-if="pUser.zero_level">
  14. {{pUser.zero_level.name || 0}}
  15. </view>
  16. <view class="name">我的持包值</view>
  17. </view>
  18. <view class="line">
  19. </view>
  20. <view class="flex center-item" >
  21. <view class="val">
  22. {{pUser.pass || 0}}
  23. </view>
  24. <view class="name">我的通证</view>
  25. </view>
  26. </view>
  27. <view class="flex banne">
  28. <image src="../../static/img/zjf.png" mode="" @click="navto('/pages/zero/task')"></image>
  29. <image src="../../static/img/yj.png" mode="" @click="navto('/pages/index/dkf')"></image>
  30. </view>
  31. <view class="flex nav">
  32. <view class="nav-item" v-for="(item,index) in navList" :class="{'action': current == index}"
  33. @click="changeTab(index)">
  34. {{item.tit}}
  35. </view>
  36. </view>
  37. <swiper disable-touch :current="current" class="list-wrap" :style="{'height': maxHeight}">
  38. <swiper-item :style="{'height': maxHeight}" v-for="item in navList">
  39. <scroll-view scroll-y="true" class="" :style="{'height': maxHeight}" :class="{'p2':current == 1}" @scrolltolower="getMore(item.status)">
  40. <view class="card-wrap flex" v-for="cardItem in item.list" v-if="item.status == 1">
  41. <image :src="cardItem.image" mode="" class="card-img"></image>
  42. <view class="flex card-info">
  43. <view class="name ">
  44. {{cardItem.name}}
  45. </view>
  46. <view class="" style="padding-right: 10rpx;">
  47. 周期{{cardItem.end_day || 0}}天,每日产出数量{{cardItem.day_pass || 0}},共富值+{{cardItem.holding_value || 0}}.最多可持有{{cardItem.max_count}}个
  48. </view>
  49. <view class="price">
  50. <image src="../../static/icon/ydjf.png" mode=""></image>
  51. <text class="show">{{cardItem.pay_points}}</text> 阅读积分 <text > (有效期{{cardItem.max_send ||0}})</text>
  52. </view>
  53. </view>
  54. <view class="card-btn" :class="{'buyless': cardItem.activate == 0}" @click="open(cardItem)">
  55. 立即兑换
  56. </view>
  57. <view class="card-nun" v-if="cardItem.total">
  58. 进行中:{{cardItem.progress}}/{{cardItem.total}}
  59. </view>
  60. </view>
  61. <view class="px-wrap flex" v-if="item.status == 2">
  62. <view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">默认</view>
  63. <view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
  64. <text>单价</text>
  65. <view class="p-box">
  66. <text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="iconfont iconfold"></text>
  67. <text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="iconfont iconfold xia"></text>
  68. </view>
  69. </view>
  70. <view class="nav-item" :class="{ current: filterIndex === 1 }" @click="tabClick(1)">
  71. <text>数量</text>
  72. <view class="p-box">
  73. <text :class="{ active: numberOrder === 1 && filterIndex === 1 }" class="iconfont iconfold"></text>
  74. <text :class="{ active: numberOrder === 2 && filterIndex === 1 }" class="iconfont iconfold xia"></text>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="order-wrap " v-for="orderItem in item.list" v-if="item.status == 2">
  79. <view class="flex m-info">
  80. <image src="../../static/icon/gs-av.png" mode="" class="card-img"></image>
  81. <text style=" display: inline-block;line-height: 55rpx;">{{orderItem.user.nickname}}</text>
  82. </view>
  83. <view class="price">
  84. ¥{{orderItem.total_price}}
  85. </view>
  86. <view class="num">
  87. 数量:{{orderItem.amount}}
  88. </view>
  89. <view class="num">
  90. {{ getTime(orderItem.add_time)}}
  91. </view>
  92. <view class="order-btn" @click="gobuy(orderItem)">
  93. 立即购买
  94. </view>
  95. </view>
  96. <uni-load-more :status="item.loadingType"></uni-load-more>
  97. </scroll-view>
  98. </swiper-item>
  99. </swiper>
  100. <uni-popup ref="popup" type="bottom" @change="popChange">
  101. <view class="" style="padding-bottom: 50px;background-color: #fff;">
  102. <view class="a-t">
  103. <image :src="buyItem.image"></image>
  104. <view class="right">
  105. <view class="good-name clamp">{{buyItem.name}}</view>
  106. <text class="price">{{ buyItem.pay_points*1* goodsNumber }}</text>
  107. </view>
  108. </view>
  109. <view class="attr-list" style="padding-bottom:40rpx;">
  110. <text>兑换数量</text>
  111. <view class="item-list">
  112. <uni-number-box class="step" :isMin="true" :value="goodsNumber" :min="1" :max="goodsNumberMax"
  113. @eventChange="numberChange"></uni-number-box>
  114. </view>
  115. </view>
  116. <button class="btn" @click.stop="createPass">确定</button>
  117. </view>
  118. </uni-popup>
  119. </view>
  120. </template>
  121. <script>
  122. import {
  123. mapState,
  124. mapMutations
  125. } from 'vuex';
  126. import uniNumberBox from '@/components/uni-number-box.vue';
  127. import {
  128. saveUrl,
  129. interceptor
  130. } from '@/utils/loginUtils.js';
  131. import {
  132. getUserInfo,
  133. userPool,
  134. goft
  135. } from '@/api/user.js';
  136. import { getCardList,createPass, getGsList,passUser,buyGs } from '@/api/zero.js'
  137. export default {
  138. components: {
  139. uniNumberBox
  140. },
  141. data() {
  142. return {
  143. pUser: {},
  144. order: 'id asc',
  145. buyItem: {},//购买卡包信息
  146. filterIndex: 0,
  147. priceOrder: 0, //1 价格从低到高 2价格从高到低
  148. numberOrder: 0, //1 销量从低到高 2销量从高到低
  149. actionPrice: 100,
  150. goodsNumber: 1,
  151. goodsNumberMax: 1,
  152. maxHeight: '',
  153. current: 0,
  154. navList: [{
  155. status: 1,
  156. tit: '消费包',
  157. list: [],
  158. loadingType: 'more',
  159. loaded: false,
  160. page: 1,
  161. limit: 10,
  162. },
  163. {
  164. status: 2,
  165. tit: '阅读积分交易',
  166. list: [],
  167. loadingType: 'more',
  168. loaded: false,
  169. page: 1,
  170. limit: 10,
  171. }
  172. ],
  173. loading: false,
  174. buying: false,
  175. }
  176. },
  177. onLoad() {
  178. },
  179. onShow() {
  180. this.loadBaseData()
  181. },
  182. computed: {
  183. ...mapState('user', ['userInfo', 'hasLogin'])
  184. },
  185. onReady(res) {
  186. var that = this;
  187. uni.getSystemInfo({
  188. success: resu => {
  189. const query = uni.createSelectorQuery();
  190. query.select('.list-wrap').boundingClientRect();
  191. query.exec(function(res) {
  192. that.maxHeight = resu.windowHeight - res[0].top + 'px';
  193. console.log(that.maxHeight);
  194. });
  195. },
  196. fail: res => {}
  197. });
  198. },
  199. methods: {
  200. ...mapMutations('user', ['setUserInfo']),
  201. gobuy(item) {
  202. if(this.buying) {
  203. return
  204. }
  205. this.buying = true
  206. buyGs({
  207. id: item.id
  208. }).then(res => {
  209. uni.showToast({
  210. title:'购买成功',
  211. duration:2000
  212. });
  213. this.buying = false
  214. this.getGsList('re')
  215. }).catch( err => {
  216. this.buying = false
  217. })
  218. },
  219. passUser() {
  220. passUser().then(res => {
  221. // console.log(res);
  222. this.pUser = res.data
  223. })
  224. },
  225. getTime(time) {
  226. const num =13 - (time+'').length;
  227. let l = 1;//倍数
  228. for (let i = 0; i < num; i++) {
  229. l+='0';
  230. }
  231. // 重新解析为数字
  232. l = parseInt(l)
  233. const date = new Date(parseInt(time) * l);
  234. const year = date.getFullYear();
  235. const mon = date.getMonth() + 1;
  236. const day = date.getDate();
  237. const hours = date.getHours();
  238. const minu = date.getMinutes();
  239. const sec = date.getSeconds();
  240. return year + '-' + mon + '-' + day + ' ' + hours + ':' + minu + ':' + sec;
  241. },
  242. getMore(status) {
  243. if(status == 2) {
  244. this.getGsList()
  245. }
  246. },
  247. popChange(e) {
  248. console.log(e)
  249. if(!e.show) {
  250. this.buyItem = {}
  251. this.goodsNumber = 1
  252. this.goodsNumberMax = 1
  253. }
  254. },
  255. getCardList() {
  256. getCardList().then(res => {
  257. console.log(res);
  258. this.navList[0].list = res.data
  259. this.navList[0].loadingType = 'noMore'
  260. })
  261. },
  262. createPass() {
  263. let that = this
  264. if(that.loading) {
  265. return
  266. }
  267. that.loading = true
  268. createPass({
  269. card_id: that.buyItem.id,
  270. num: that.goodsNumber
  271. }).then(res => {
  272. that.loading = false
  273. uni.showToast({
  274. title:'兑换成功',
  275. duration:2000
  276. });
  277. that.loadBaseData()
  278. that.$refs.popup.close()
  279. }).catch(err => {
  280. that.loading = false
  281. })
  282. },
  283. // 购买数量变化
  284. numberChange(e) {
  285. this.goodsNumber = e.number;
  286. },
  287. //筛选点击
  288. tabClick(index) {
  289. // 防止重复点击综合排序
  290. if (this.filterIndex === 0 && this.filterIndex === index) {
  291. console.log('zhe')
  292. return;
  293. }
  294. this.filterIndex = index;
  295. if(index === 0) {
  296. this.order = 'id asc'
  297. }
  298. // 判断是否为销量优先
  299. if (index === 1) {
  300. this.numberOrder = this.numberOrder === 1 ? 2 : 1;
  301. this.order = this.numberOrder === 1 ? 'amount asc': 'amount desc'
  302. }
  303. // 判断是否为价格优先
  304. if (index === 2) {
  305. this.priceOrder = this.priceOrder === 1 ? 2 : 1;
  306. this.order = this.priceOrder === 1 ? 'price asc': 'price desc'
  307. }
  308. // 初始化页数
  309. // this.page = 1;
  310. this.navList[1].list.page = 1
  311. // 初始化数组
  312. // uni.pageScrollTo({
  313. // duration: 300,
  314. // scrollTop: 0
  315. // });
  316. this.getGsList('re');
  317. uni.showLoading({
  318. title: '正在加载'
  319. });
  320. },
  321. makeCall(item) {
  322. uni.makePhoneCall({
  323. phoneNumber:item + ''
  324. })
  325. },
  326. loadBaseData(tit) {
  327. const obj = this
  328. getUserInfo({})
  329. .then(({
  330. data
  331. }) => {
  332. console.log(data,'data')
  333. obj.setUserInfo(data);
  334. obj.getCardList()
  335. obj.passUser()
  336. obj.getGsList()
  337. })
  338. .catch(e => {
  339. console.log(e);
  340. });
  341. },
  342. buy() {},
  343. changeTab(index) {
  344. this.current = index
  345. this.getList('tab')
  346. },
  347. getList(type) {
  348. if(this.current == 1) {
  349. console.log('ddddddddddddddddddd')
  350. this.getGsList('re');
  351. }else {
  352. }
  353. },
  354. navto(url) {
  355. if (!this.hasLogin) {
  356. // 保存地址
  357. saveUrl();
  358. // 登录拦截
  359. interceptor();
  360. } else {
  361. uni.navigateTo({
  362. url,
  363. fail() {
  364. uni.switchTab({
  365. url
  366. })
  367. }
  368. })
  369. }
  370. },
  371. open(item) {
  372. let that = this
  373. if(!item.activate) {
  374. return that.$api.msg('当前不可兑换')
  375. }
  376. that.buyItem = item
  377. that.goodsNumberMax = item.max_count*1 - item.progress*1
  378. this.$refs.popup.open()
  379. },
  380. getGsList(type) {
  381. console.log('jinriu')
  382. let that = this
  383. let item = that.navList[1]
  384. if(type == 're') {
  385. item.list = []
  386. item.loadingType = 'more'
  387. item.page = 1
  388. item.loaded = false
  389. }
  390. if(item.loadingType == 'loading' || item.loadingType == 'noMore') {
  391. return
  392. }
  393. item.loadingType = 'loading'
  394. getGsList({
  395. // uid: this.userI.uid
  396. page: item.page,
  397. limit: item.limit,
  398. order: that.order,
  399. status: 0
  400. }).then(res => {
  401. uni.hideLoading()
  402. let arr = res.data.result.list
  403. item.list = item.list.concat(arr)
  404. if(arr.length == item.limit) {
  405. item.loadingType = 'more'
  406. }else {
  407. item.loadingType = 'noMore'
  408. }
  409. item.page++
  410. item.loaded = true
  411. })
  412. }
  413. }
  414. }
  415. </script>
  416. <style lang="scss" scoped>
  417. .center-box {
  418. width: 693rpx;
  419. height: 152rpx;
  420. background: #FFFFFF;
  421. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  422. border-radius: 20rpx;
  423. margin: 0 auto;
  424. font-size: 30rpx;
  425. font-weight: bold;
  426. color: #333333;
  427. .center-item {
  428. flex-grow: 1;
  429. flex-direction: column;
  430. justify-content: center;
  431. align-items: center;
  432. .val {
  433. font-size: 38rpx;
  434. font-weight: bold;
  435. color: #333333;
  436. }
  437. .name {
  438. padding-top: 10rpx;
  439. }
  440. }
  441. .line {
  442. width: 2rpx;
  443. height: 74rpx;
  444. background: #eff1f5;
  445. }
  446. }
  447. .banne {
  448. justify-content: center;
  449. padding: 20rpx 0;
  450. image {
  451. width: 340rpx;
  452. height: 204rpx;
  453. margin: 0 8rpx;
  454. }
  455. }
  456. .nav {
  457. padding: 30rpx 0;
  458. .nav-item {
  459. flex-grow: 1;
  460. text-align: center;
  461. font-size: 33rpx;
  462. font-weight: bold;
  463. color: #333;
  464. }
  465. .action {
  466. color: #FF4C4C;
  467. }
  468. }
  469. .list-wrap {
  470. // background-color: red;
  471. .card-wrap {
  472. width: 690rpx;
  473. height: 197rpx;
  474. background: #FFFFFF;
  475. border-radius: 10rpx;
  476. margin: 0 auto 20rpx;
  477. padding: 20rpx;
  478. justify-content: flex-start;
  479. position: relative;
  480. .card-img {
  481. flex-shrink: 0;
  482. width: 158rpx;
  483. height: 158rpx;
  484. background-color: #eee;
  485. margin-right: 20rpx;
  486. }
  487. .card-info {
  488. flex-grow: 1;
  489. font-size: 24rpx;
  490. font-weight: 500;
  491. height: 100%;
  492. color: #999999;
  493. flex-direction: column;
  494. justify-content: space-between;
  495. align-items: flex-start;
  496. .name {
  497. font-size: 32rpx;
  498. font-weight: bold;
  499. color: #333333;
  500. }
  501. .price {
  502. font-size: 20rpx;
  503. font-weight: 500;
  504. color: $base-color;
  505. line-height: 35rpx;
  506. .show {
  507. font-size: 36rpx;
  508. font-weight: bold;
  509. color: #FC4141;
  510. vertical-align: bottom;
  511. padding: 0 5rpx;
  512. }
  513. image {
  514. width: 34rpx;
  515. height: 33rpx;
  516. vertical-align: bottom;
  517. }
  518. text {
  519. color: #999999;
  520. }
  521. }
  522. }
  523. .card-btn {
  524. flex-shrink: 0;
  525. width: 137rpx;
  526. height: 52rpx;
  527. background: $base-color;
  528. border-radius: 26rpx;
  529. font-size: 26rpx;
  530. font-weight: 500;
  531. color: #FFFFFF;
  532. text-align: center;
  533. line-height: 50rpx;
  534. align-self: flex-end;
  535. }
  536. .buyless {
  537. background:#999 ;
  538. }
  539. .card-nun {
  540. position: absolute;
  541. top: 20rpx;
  542. right: 20rpx;
  543. font-size: 26rpx;
  544. color: $base-color;
  545. }
  546. }
  547. .order-wrap {
  548. width: 686rpx;
  549. height: 297rpx;
  550. background: #FFFFFF;
  551. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  552. border-radius: 20rpx;
  553. margin: 0 auto 20rpx;
  554. padding: 33rpx 40rpx;
  555. position: relative;
  556. .m-info {
  557. justify-content: flex-start;
  558. image {
  559. width: 55rpx;
  560. height: 55rpx;
  561. margin-right: 13rpx;
  562. }
  563. text {
  564. font-size: 28rpx;
  565. font-weight: bold;
  566. color: #333333;
  567. }
  568. }
  569. .price {
  570. font-size: 40rpx;
  571. font-family: PingFang SC;
  572. font-weight: bold;
  573. color: #FF4C4C;
  574. padding: 40rpx 0 30rpx;
  575. }
  576. .num {
  577. font-size: 26rpx;
  578. font-weight: 500;
  579. color: #888785;
  580. }
  581. .order-btn {
  582. width: 148rpx;
  583. height: 62rpx;
  584. border: 2px solid #FF5570;
  585. border-radius: 30rpx;
  586. line-height: 62rpx;
  587. text-align: center;
  588. font-size: 28rpx;
  589. font-weight: bold;
  590. color: #FF4C4C;
  591. position: absolute;
  592. right: 40rpx;
  593. bottom: 33rpx;
  594. }
  595. }
  596. }
  597. .attr-list {
  598. display: flex;
  599. flex-direction: column;
  600. font-size: $font-base + 2rpx;
  601. color: $font-color-base;
  602. padding-top: 30rpx;
  603. padding-left: 40rpx;
  604. padding-right: 30rpx;
  605. }
  606. .item-list {
  607. padding: 20rpx 0 0;
  608. display: flex;
  609. flex-wrap: wrap;
  610. .tit {
  611. display: flex;
  612. align-items: center;
  613. justify-content: center;
  614. background: #eee;
  615. // margin-left: 10rpx;
  616. margin-right: 20rpx;
  617. margin-bottom: 20rpx;
  618. border-radius: 100rpx;
  619. min-width: 60rpx;
  620. height: 60rpx;
  621. padding: 0 20rpx;
  622. font-size: $font-base;
  623. color: $font-color-dark;
  624. }
  625. .selected {
  626. background: #fbebee;
  627. color: $uni-color-primary;
  628. }
  629. }
  630. .btn {
  631. width: 750rpx;
  632. height: 98rpx;
  633. background: $base-color;
  634. line-height: 98rpx;
  635. // background: $uni-color-primary;
  636. font-size: $font-base + 2rpx;
  637. color: #fff;
  638. }
  639. .a-t {
  640. padding: 0 30rpx;
  641. display: flex;
  642. image {
  643. width: 170rpx;
  644. height: 170rpx;
  645. flex-shrink: 0;
  646. border-radius: 8rpx;
  647. }
  648. .right {
  649. display: flex;
  650. flex-direction: column;
  651. padding-left: 24rpx;
  652. font-size: $font-sm + 2rpx;
  653. color: $font-color-base;
  654. line-height: 42rpx;
  655. .good-name {
  656. padding-top: 20rpx;
  657. max-width: 320rpx;
  658. font-size: 30rpx;
  659. font-family: PingFang SC;
  660. font-weight: bold;
  661. color: #1d2023;
  662. line-height: 42rpx;
  663. margin-bottom: 15rpx;
  664. }
  665. .price {
  666. font-size: 60rpx;
  667. font-family: PingFang SC;
  668. font-weight: bold;
  669. color: $base-color;
  670. // font-size: $font-lg;
  671. // color: $uni-color-primary;
  672. // margin-bottom: 10rpx;
  673. &::after {
  674. content: '阅读积分';
  675. font-size: 30rpx;
  676. padding-left: 10rpx;
  677. }
  678. }
  679. .selected-text {
  680. margin-right: 10rpx;
  681. }
  682. }
  683. }
  684. .px-wrap {
  685. height: 60rpx;
  686. background-color: #fff;
  687. position: fixed;
  688. width: 750rpx;
  689. top: 0;
  690. z-index: 999;
  691. .nav-item {
  692. flex: 1;
  693. display: flex;
  694. justify-content: center;
  695. align-items: center;
  696. height: 100%;
  697. font-size: 25rpx;
  698. font-weight: 500;
  699. color: #666666;
  700. position: relative;
  701. &.current {
  702. color: $base-color;
  703. }
  704. }
  705. .p-box {
  706. display: flex;
  707. flex-direction: column;
  708. .iconfont {
  709. display: flex;
  710. align-items: center;
  711. justify-content: center;
  712. width: 30rpx;
  713. height: 14rpx;
  714. line-height: 1;
  715. margin-left: 4rpx;
  716. font-size: 20rpx;
  717. color: #888;
  718. &.active {
  719. color: $base-color;
  720. }
  721. }
  722. .xia {
  723. transform: scaleY(-1);
  724. }
  725. }
  726. }
  727. .p2 {
  728. padding-top: 80rpx;
  729. }
  730. </style>