zero.vue 17 KB

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