zero.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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">
  14. {{pUser.holding_value || 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.phone}}</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. }).catch( err => {
  221. this.buying = false
  222. })
  223. },
  224. passUser() {
  225. passUser().then(res => {
  226. // console.log(res);
  227. this.pUser = res.data
  228. })
  229. },
  230. getTime(time) {
  231. const num =13 - (time+'').length;
  232. let l = 1;//倍数
  233. for (let i = 0; i < num; i++) {
  234. l+='0';
  235. }
  236. // 重新解析为数字
  237. l = parseInt(l)
  238. const date = new Date(parseInt(time) * l);
  239. const year = date.getFullYear();
  240. const mon = date.getMonth() + 1;
  241. const day = date.getDate();
  242. const hours = date.getHours();
  243. const minu = date.getMinutes();
  244. const sec = date.getSeconds();
  245. return year + '-' + mon + '-' + day + ' ' + hours + ':' + minu + ':' + sec;
  246. },
  247. getMore(status) {
  248. if(status == 2) {
  249. this.getGsList()
  250. }
  251. },
  252. popChange(e) {
  253. console.log(e)
  254. if(!e.show) {
  255. this.buyItem = {}
  256. this.goodsNumber = 1
  257. this.goodsNumberMax = 1
  258. }
  259. },
  260. getCardList() {
  261. getCardList().then(res => {
  262. console.log(res);
  263. this.navList[0].list = res.data
  264. this.navList[0].loadingType = 'noMore'
  265. })
  266. },
  267. createPass() {
  268. let that = this
  269. if(that.loading) {
  270. return
  271. }
  272. that.loading = true
  273. createPass({
  274. card_id: that.buyItem.id,
  275. num: that.goodsNumber
  276. }).then(res => {
  277. that.loading = false
  278. uni.showToast({
  279. title:'兑换成功',
  280. duration:2000
  281. });
  282. that.loadBaseData()
  283. that.$refs.popup.close()
  284. }).catch(err => {
  285. that.loading = false
  286. })
  287. },
  288. // 购买数量变化
  289. numberChange(e) {
  290. this.goodsNumber = e.number;
  291. },
  292. //筛选点击
  293. tabClick(index) {
  294. // 防止重复点击综合排序
  295. if (this.filterIndex === 0 && this.filterIndex === index) {
  296. console.log('zhe')
  297. return;
  298. }
  299. this.filterIndex = index;
  300. if(index === 0) {
  301. this.order = 'id asc'
  302. }
  303. // 判断是否为销量优先
  304. if (index === 1) {
  305. this.numberOrder = this.numberOrder === 1 ? 2 : 1;
  306. this.order = this.numberOrder === 1 ? 'amount asc': 'amount desc'
  307. }
  308. // 判断是否为价格优先
  309. if (index === 2) {
  310. this.priceOrder = this.priceOrder === 1 ? 2 : 1;
  311. this.order = this.priceOrder === 1 ? 'price asc': 'price desc'
  312. }
  313. // 初始化页数
  314. // this.page = 1;
  315. this.navList[1].list.page = 1
  316. // 初始化数组
  317. // uni.pageScrollTo({
  318. // duration: 300,
  319. // scrollTop: 0
  320. // });
  321. this.getGsList('re');
  322. uni.showLoading({
  323. title: '正在加载'
  324. });
  325. },
  326. makeCall(item) {
  327. uni.makePhoneCall({
  328. phoneNumber:item + ''
  329. })
  330. },
  331. loadBaseData(tit) {
  332. const obj = this
  333. getUserInfo({})
  334. .then(({
  335. data
  336. }) => {
  337. console.log(data,'data')
  338. obj.setUserInfo(data);
  339. obj.getCardList()
  340. obj.passUser()
  341. obj.getGsList()
  342. })
  343. .catch(e => {
  344. console.log(e);
  345. });
  346. },
  347. buy() {},
  348. changeTab(index) {
  349. this.current = index
  350. this.getList('tab')
  351. },
  352. getList(type) {
  353. if(this.current == 1) {
  354. console.log('ddddddddddddddddddd')
  355. this.getGsList('re');
  356. }else {
  357. }
  358. },
  359. navto(url) {
  360. if (!this.hasLogin) {
  361. // 保存地址
  362. saveUrl();
  363. // 登录拦截
  364. interceptor();
  365. } else {
  366. uni.navigateTo({
  367. url,
  368. fail() {
  369. uni.switchTab({
  370. url
  371. })
  372. }
  373. })
  374. }
  375. },
  376. open(item) {
  377. let that = this
  378. if(!item.activate) {
  379. return that.$api.msg('当前不可兑换')
  380. }
  381. that.buyItem = item
  382. that.goodsNumberMax = item.max_count*1 - item.progress*1
  383. this.$refs.popup.open()
  384. },
  385. getGsList(type) {
  386. console.log('jinriu')
  387. let that = this
  388. let item = that.navList[1]
  389. if(type == 're') {
  390. item.list = []
  391. item.loadingType = 'more'
  392. item.page = 1
  393. item.loaded = false
  394. }
  395. if(item.loadingType == 'loading' || item.loadingType == 'noMore') {
  396. return
  397. }
  398. item.loadingType = 'loading'
  399. getGsList({
  400. // uid: this.userI.uid
  401. page: item.page,
  402. limit: item.limit,
  403. order: that.order,
  404. status: 0
  405. }).then(res => {
  406. uni.hideLoading()
  407. let arr = res.data.result.list
  408. item.list = item.list.concat(arr)
  409. if(arr.length == item.limit) {
  410. item.loadingType = 'more'
  411. }else {
  412. item.loadingType = 'noMore'
  413. }
  414. item.page++
  415. item.loaded = true
  416. })
  417. }
  418. }
  419. }
  420. </script>
  421. <style lang="scss" scoped>
  422. .center-box {
  423. width: 693rpx;
  424. height: 152rpx;
  425. background: #FFFFFF;
  426. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  427. border-radius: 20rpx;
  428. margin: 0 auto;
  429. font-size: 30rpx;
  430. font-weight: bold;
  431. color: #333333;
  432. .center-item {
  433. flex-grow: 1;
  434. flex-direction: column;
  435. justify-content: center;
  436. align-items: center;
  437. .val {
  438. font-size: 38rpx;
  439. font-weight: bold;
  440. color: #333333;
  441. }
  442. .name {
  443. padding-top: 10rpx;
  444. }
  445. }
  446. .line {
  447. width: 2rpx;
  448. height: 74rpx;
  449. background: #eff1f5;
  450. }
  451. }
  452. .banne {
  453. justify-content: center;
  454. padding: 20rpx 0;
  455. image {
  456. width: 340rpx;
  457. height: 204rpx;
  458. margin: 0 8rpx;
  459. }
  460. }
  461. .nav {
  462. padding: 30rpx 0;
  463. .nav-item {
  464. flex-grow: 1;
  465. text-align: center;
  466. font-size: 33rpx;
  467. font-weight: bold;
  468. color: #333;
  469. }
  470. .action {
  471. color: #FF4C4C;
  472. }
  473. }
  474. .list-wrap {
  475. // background-color: red;
  476. .card-wrap {
  477. width: 690rpx;
  478. height: 197rpx;
  479. background: #FFFFFF;
  480. border-radius: 10rpx;
  481. margin: 0 auto 20rpx;
  482. padding: 20rpx;
  483. justify-content: flex-start;
  484. position: relative;
  485. .card-img {
  486. flex-shrink: 0;
  487. width: 158rpx;
  488. height: 158rpx;
  489. background-color: #eee;
  490. margin-right: 20rpx;
  491. }
  492. .card-info {
  493. flex-grow: 1;
  494. font-size: 24rpx;
  495. font-weight: 500;
  496. height: 100%;
  497. color: #999999;
  498. flex-direction: column;
  499. justify-content: space-between;
  500. align-items: flex-start;
  501. .name {
  502. font-size: 32rpx;
  503. font-weight: bold;
  504. color: #333333;
  505. }
  506. .price {
  507. font-size: 20rpx;
  508. font-weight: 500;
  509. color: $base-color;
  510. line-height: 35rpx;
  511. .show {
  512. font-size: 36rpx;
  513. font-weight: bold;
  514. color: #FC4141;
  515. vertical-align: bottom;
  516. padding: 0 5rpx;
  517. }
  518. image {
  519. width: 34rpx;
  520. height: 33rpx;
  521. vertical-align: bottom;
  522. }
  523. text {
  524. color: #999999;
  525. }
  526. }
  527. }
  528. .card-btn {
  529. flex-shrink: 0;
  530. width: 137rpx;
  531. height: 52rpx;
  532. background: $base-color;
  533. border-radius: 26rpx;
  534. font-size: 26rpx;
  535. font-weight: 500;
  536. color: #FFFFFF;
  537. text-align: center;
  538. line-height: 50rpx;
  539. align-self: flex-end;
  540. }
  541. .buyless {
  542. background:#999 ;
  543. }
  544. .card-nun {
  545. position: absolute;
  546. top: 20rpx;
  547. right: 20rpx;
  548. font-size: 26rpx;
  549. color: $base-color;
  550. }
  551. }
  552. .order-wrap {
  553. width: 686rpx;
  554. height: 297rpx;
  555. background: #FFFFFF;
  556. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  557. border-radius: 20rpx;
  558. margin: 0 auto 20rpx;
  559. padding: 33rpx 40rpx;
  560. position: relative;
  561. .m-info {
  562. justify-content: flex-start;
  563. image {
  564. width: 55rpx;
  565. height: 55rpx;
  566. margin-right: 13rpx;
  567. }
  568. text {
  569. font-size: 28rpx;
  570. font-weight: bold;
  571. color: #333333;
  572. }
  573. }
  574. .price {
  575. font-size: 40rpx;
  576. font-family: PingFang SC;
  577. font-weight: bold;
  578. color: #FF4C4C;
  579. padding: 40rpx 0 30rpx;
  580. }
  581. .num {
  582. font-size: 26rpx;
  583. font-weight: 500;
  584. color: #888785;
  585. }
  586. .order-btn {
  587. width: 148rpx;
  588. height: 62rpx;
  589. border: 2px solid #FF5570;
  590. border-radius: 30rpx;
  591. line-height: 62rpx;
  592. text-align: center;
  593. font-size: 28rpx;
  594. font-weight: bold;
  595. color: #FF4C4C;
  596. position: absolute;
  597. right: 40rpx;
  598. bottom: 33rpx;
  599. }
  600. }
  601. }
  602. .attr-list {
  603. display: flex;
  604. flex-direction: column;
  605. font-size: $font-base + 2rpx;
  606. color: $font-color-base;
  607. padding-top: 30rpx;
  608. padding-left: 40rpx;
  609. padding-right: 30rpx;
  610. }
  611. .item-list {
  612. padding: 20rpx 0 0;
  613. display: flex;
  614. flex-wrap: wrap;
  615. .tit {
  616. display: flex;
  617. align-items: center;
  618. justify-content: center;
  619. background: #eee;
  620. // margin-left: 10rpx;
  621. margin-right: 20rpx;
  622. margin-bottom: 20rpx;
  623. border-radius: 100rpx;
  624. min-width: 60rpx;
  625. height: 60rpx;
  626. padding: 0 20rpx;
  627. font-size: $font-base;
  628. color: $font-color-dark;
  629. }
  630. .selected {
  631. background: #fbebee;
  632. color: $uni-color-primary;
  633. }
  634. }
  635. .btn {
  636. width: 750rpx;
  637. height: 98rpx;
  638. background: $base-color;
  639. line-height: 98rpx;
  640. // background: $uni-color-primary;
  641. font-size: $font-base + 2rpx;
  642. color: #fff;
  643. }
  644. .a-t {
  645. padding: 0 30rpx;
  646. display: flex;
  647. image {
  648. width: 170rpx;
  649. height: 170rpx;
  650. flex-shrink: 0;
  651. border-radius: 8rpx;
  652. }
  653. .right {
  654. display: flex;
  655. flex-direction: column;
  656. padding-left: 24rpx;
  657. font-size: $font-sm + 2rpx;
  658. color: $font-color-base;
  659. line-height: 42rpx;
  660. .good-name {
  661. padding-top: 20rpx;
  662. max-width: 320rpx;
  663. font-size: 30rpx;
  664. font-family: PingFang SC;
  665. font-weight: bold;
  666. color: #1d2023;
  667. line-height: 42rpx;
  668. margin-bottom: 15rpx;
  669. }
  670. .price {
  671. font-size: 60rpx;
  672. font-family: PingFang SC;
  673. font-weight: bold;
  674. color: $base-color;
  675. // font-size: $font-lg;
  676. // color: $uni-color-primary;
  677. // margin-bottom: 10rpx;
  678. &::after {
  679. content: '阅读积分';
  680. font-size: 30rpx;
  681. padding-left: 10rpx;
  682. }
  683. }
  684. .selected-text {
  685. margin-right: 10rpx;
  686. }
  687. }
  688. }
  689. .px-wrap {
  690. height: 60rpx;
  691. background-color: #fff;
  692. position: fixed;
  693. width: 750rpx;
  694. top: 0;
  695. z-index: 999;
  696. .nav-item {
  697. flex: 1;
  698. display: flex;
  699. justify-content: center;
  700. align-items: center;
  701. height: 100%;
  702. font-size: 25rpx;
  703. font-weight: 500;
  704. color: #666666;
  705. position: relative;
  706. &.current {
  707. color: $base-color;
  708. }
  709. }
  710. .p-box {
  711. display: flex;
  712. flex-direction: column;
  713. .iconfont {
  714. display: flex;
  715. align-items: center;
  716. justify-content: center;
  717. width: 30rpx;
  718. height: 14rpx;
  719. line-height: 1;
  720. margin-left: 4rpx;
  721. font-size: 20rpx;
  722. color: #888;
  723. &.active {
  724. color: $base-color;
  725. }
  726. }
  727. .xia {
  728. transform: scaleY(-1);
  729. }
  730. }
  731. }
  732. .p2 {
  733. padding-top: 80rpx;
  734. }
  735. </style>