index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <app-layout>
  3. <app-tab-nav setTop="0" :border="false" :shadow="false" height="100" :tabList="tabList" padding="0" :activeItem="activeTab" @click="tabStatus" :theme="getTheme"></app-tab-nav>
  4. <view v-if="activeTab == '0'" class="scan">
  5. <view>输入兑换码或者扫码兑换二维码开始兑换</view>
  6. <view class="scan-input">
  7. <input placeholder="请输入兑换码" v-model="code" type="text">
  8. <image @click="scan" src="./../image/scan.png"></image>
  9. </view>
  10. <view @click="clerk" class="scan-button" :class="code.length > 0 ? getTheme + '-m-back ' + getTheme:'default'">兑换</view>
  11. </view>
  12. <view v-if="activeTab == '1'">
  13. <view v-if="list.length > 0" class="item" v-for="(item,index) in list" :key="index">
  14. <view class="main-between cross-center status">
  15. <view class="item-code" :class="item.status == 2 ? getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme:'default'">{{item.code}}</view>
  16. <view @click="toDetail(item)" class="dir-left-nowrap cross-center item-status" :class="item.status == 2 ? getTheme + '-m-text ' + getTheme:'default'">
  17. <view>{{item.status == 2 ? item.last_num + '项待领取' : '已全部领取'}}</view>
  18. <i v-if="item.status == 2" :class="getTheme + '-m-text ' + getTheme" class="iconfont icon-right">&#xe7eb;</i>
  19. <image v-else src="/static/image/icon/right.png"></image>
  20. </view>
  21. </view>
  22. <view class="item-time">兑换时间:{{item.r_raffled_at}}</view>
  23. </view>
  24. <view style="padding-top: 30%" v-if="list.length == 0">
  25. <app-no-goods title="暂无兑换记录" :is_image="1" background="#f7f7f7"></app-no-goods>
  26. </view>
  27. </view>
  28. <view @click="showRule" class="use-info" :class="[ `${getTheme + '-m-text ' + getTheme}`,`${tabbarbool? 'tabbarbool':''}`]" v-if="setting.is_rules == 1 && activeTab == '0'">使用说明</view>
  29. <u-mask :show="dialog" :maskClickAble="false" :zoom="false">
  30. <view class="dialog">
  31. <image class="dialog-img" src="./../image/error.png"></image>
  32. <view class="dialog-msg">
  33. <text>{{msg}}</text>
  34. </view>
  35. <view class="dialog-other">{{other}}</view>
  36. <view @click="dialog=false;code=''" :class="getTheme + '-m-back ' + getTheme" class="dialog-button">我知道了</view>
  37. </view>
  38. </u-mask>
  39. <view v-if="showRules" class="dialog-bg">
  40. <view class="u-rules" :animation="animationData" :style="{bottom: bottom}" :class="[`${tabbarbool? 'tabbarbool':''}`,`${iphone_x? 'iphone_x':''}`]">
  41. <view class="u-rules-top dir-right-nowrap">
  42. <view v-if="over" @click="showRules=false;bottom='-998rpx';animationData={}" class="end-close main-center cross-center">
  43. <image src="/static/image/icon/icon-close.png"></image>
  44. </view>
  45. </view>
  46. <view class="u-rules-content">
  47. <parse :content="setting.rules"></parse>
  48. </view>
  49. </view>
  50. </view>
  51. <view @click="toGift" v-if="setting.is_to_gift == 1" class="jump-dialog cross-center dir-top-nowrap main-center" :class="[`${tabbarbool? 'tabbarbool':''}`]">
  52. <image :src="setting.to_gift_pic"></image>
  53. <view>礼品卡</view>
  54. </view>
  55. </app-layout>
  56. </template>
  57. <script>
  58. import appTabNav from "../../../components/basic-component/app-tab-nav/app-tab-nav.vue";
  59. import uMask from '../../../components/basic-component/u-mask/u-mask.vue';
  60. import parse from "../../../components/basic-component/app-rich/parse.vue";
  61. import appNoGoods from '../../../components/page-component/app-no-goods/app-no-goods.vue';
  62. import { mapState, mapGetters } from "vuex";
  63. export default {
  64. name: "index",
  65. data() {
  66. return {
  67. currentRoute: this.$platDiff.route(),
  68. tabbarbool: false,
  69. iphone_x: false,
  70. tabList: [
  71. {id:0, name: '兑换礼品'},
  72. {id:1, name: '兑换记录'}
  73. ],
  74. over: false,
  75. code: '',
  76. bottom: '-998rpx',
  77. activeTab: '0',
  78. list: [],
  79. setting: {},
  80. animationData: {},
  81. showRules: false,
  82. dialog: false,
  83. more: false,
  84. loading: false,
  85. msg: '',
  86. other: '',
  87. page: 1,
  88. };
  89. },
  90. watch: {
  91. tabBarNavs: {
  92. handler: function() {
  93. this.b();
  94. },
  95. immediate: true,
  96. }
  97. },
  98. components: {
  99. "app-tab-nav": appTabNav,
  100. parse,
  101. "app-no-goods": appNoGoods,
  102. "u-mask": uMask
  103. },
  104. computed: {
  105. ...mapState({
  106. tabBarNavs: state => state.mallConfig.navbar.navs,
  107. }),
  108. ...mapGetters('mallConfig', {
  109. getTheme: 'getTheme'
  110. })
  111. },
  112. onShareAppMessage: function() {
  113. return this.$shareAppMessage({
  114. title: this.$children[0].navigationBarTitle,
  115. path: "/plugins/exchange/index/index",
  116. });
  117. },
  118. // #ifdef MP-WEIXIN
  119. onShareTimeline() {
  120. // 分享朋友圈beta
  121. return this.$shareTimeline({
  122. title: this.$children[0].navigationBarTitle,
  123. query: {} // 此处填写页面的参数
  124. });
  125. },
  126. // #endif
  127. onReachBottom() {
  128. if(this.more) {
  129. this.page++;
  130. this.getMore();
  131. }
  132. },
  133. onLoad(options) {
  134. let that = this;
  135. if(options.code) {
  136. this.code = options.code
  137. }
  138. // #ifdef MP-WEIXIN
  139. wx.showShareMenu({
  140. menus: ['shareAppMessage', 'shareTimeline']
  141. })
  142. // #endif
  143. uni.getSystemInfo({
  144. success: function (res) {
  145. that.height = -res.screenHeight;
  146. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  147. that.iphone_x = true;
  148. }
  149. }
  150. });
  151. that.$request({
  152. url: that.$api.exchange.setting,
  153. }).then(response=>{
  154. if(response.code == 0) {
  155. that.setting = response.data;
  156. }else {
  157. uni.showToast({
  158. title: response.msg,
  159. icon: 'none',
  160. duration: 1000
  161. });
  162. }
  163. })
  164. },
  165. onShow() {
  166. if(this.activeTab == '1') {
  167. this.getList();
  168. }
  169. },
  170. methods: {
  171. b() {
  172. let currentRoute = this.currentRoute;
  173. for (let i = 0; i < this.tabBarNavs.length; i++) {
  174. if(currentRoute.includes(this.tabBarNavs[i].url.split('?')[0])) {
  175. return this.tabbarbool = true;
  176. }
  177. }
  178. return this.tabbarbool = false;
  179. },
  180. showRule() {
  181. let that = this;
  182. that.over = false;
  183. that.showRules = true;
  184. var animation = uni.createAnimation({
  185. duration: 1000,
  186. timingFunction: 'ease',
  187. })
  188. that.animationData = animation
  189. setTimeout(function(){
  190. let num = 0;
  191. if(that.tabbarbool) {
  192. num += 55
  193. }
  194. animation.bottom(-500).bottom(num).step()
  195. that.animationData = animation.export();
  196. setTimeout(function(){
  197. that.bottom = num *2 + 'rpx';
  198. that.over = true;
  199. },1200)
  200. },200)
  201. },
  202. scan() {
  203. let that = this;
  204. // #ifndef MP-ALIPAY
  205. uni.scanCode({
  206. success(res) {
  207. if(res.scanType == "CODE_128" || (res.result && res.result.length == 12)) {
  208. that.code = res.result
  209. } else {
  210. if(res.path) {
  211. let path = res.path
  212. path = path.split('?');
  213. let scene = path[1];
  214. let reg = new RegExp("scene=", "g");
  215. scene = path[1].replace(reg, "");
  216. that.$request({
  217. url: that.$api.default.qrcode_parameter,
  218. data: {
  219. token: scene
  220. }
  221. }).then(response => {
  222. if (response.code === 0) {
  223. that.code = response.data.detail.data.code;
  224. }
  225. });
  226. }else {
  227. uni.showToast({
  228. title: '暂不支持此二维码,请使用应用内扫一扫功能',
  229. icon: 'none',
  230. duration: 1000
  231. });
  232. }
  233. }
  234. },
  235. fail(res) {
  236. }
  237. })
  238. // #endif
  239. // #ifdef MP-ALIPAY
  240. my.ap.navigateToAlipayPage({
  241. appCode:'alipayScan',
  242. success:(res) => {
  243. },
  244. fail:(res) => {
  245. my.alert({content:'失败:'+JSON.stringify(res)});
  246. }
  247. });
  248. // #endif
  249. },
  250. tabStatus(e) {
  251. if(this.loading) {
  252. return false
  253. }
  254. this.list = [];
  255. this.page = 1;
  256. this.activeTab = e.currentTarget.dataset.id;
  257. this.getList();
  258. },
  259. getMore() {
  260. let that = this;
  261. if(this.loading) {
  262. return false
  263. }
  264. this.loading = true;
  265. that.more = false;
  266. uni.showLoading({
  267. title: '加载中...'
  268. });
  269. that.$request({
  270. url: that.$api.exchange.log,
  271. data: {
  272. page: that.page
  273. }
  274. }).then(response=>{
  275. uni.hideLoading();
  276. this.loading = false;
  277. if(response.code == 0) {
  278. that.list = that.list.concat(response.data.list);
  279. if(that.list.length == response.data.pagination.pageSize) {
  280. that.more = true;
  281. }
  282. }else {
  283. uni.showToast({
  284. title: response.msg,
  285. icon: 'none',
  286. duration: 1000
  287. });
  288. }
  289. }).catch(response => {
  290. uni.hideLoading();
  291. });
  292. },
  293. getList() {
  294. let that = this;
  295. if(this.loading) {
  296. return false
  297. }
  298. this.loading = true;
  299. that.page = 1;
  300. that.more = false;
  301. uni.showLoading({
  302. title: '加载中...'
  303. });
  304. that.$request({
  305. url: that.$api.exchange.log
  306. }).then(response=>{
  307. this.loading = false;
  308. uni.hideLoading();
  309. if(response.code == 0) {
  310. that.list = response.data.list;
  311. if(that.list.length == response.data.pagination.pageSize) {
  312. that.more = true;
  313. }
  314. }else {
  315. uni.showToast({
  316. title: response.msg,
  317. icon: 'none',
  318. duration: 1000
  319. });
  320. }
  321. }).catch(response => {
  322. uni.hideLoading();
  323. });
  324. },
  325. toDetail(item) {
  326. uni.navigateTo({
  327. url: '/plugins/exchange/detail/detail?code=' + item.code + '&exchange=1'
  328. })
  329. },
  330. toGift() {
  331. uni.navigateTo({
  332. url: '/plugins/exchange/list/list'
  333. })
  334. },
  335. clerk() {
  336. let that = this;
  337. if(this.loading || !this.code) {
  338. return false
  339. }
  340. uni.showLoading({
  341. title: '兑换中...'
  342. });
  343. this.loading = true;
  344. let code = this.code;
  345. that.$request({
  346. url: that.$api.exchange.info,
  347. data: {
  348. code: code
  349. }
  350. }).then(response=>{
  351. this.loading = false;
  352. uni.hideLoading();
  353. if(response.code == 0) {
  354. this.code = '';
  355. uni.navigateTo({
  356. url: '/plugins/exchange/detail/detail?code=' + code
  357. })
  358. }else {
  359. this.msg = response.msg;
  360. this.other = '';
  361. if(response.msg == '该兑换码未到使用时间!') {
  362. this.other = response.data.valid_start_time + '-' + response.data.valid_end_time + ' 可用'
  363. }
  364. this.dialog = true;
  365. }
  366. }).catch(response => {
  367. uni.hideLoading();
  368. });
  369. }
  370. }
  371. }
  372. </script>
  373. <style scoped lang="scss">
  374. .dialog-bg {
  375. position: fixed;
  376. top: 0;
  377. left: 0;
  378. width: 100%;
  379. height: 100%;
  380. background-color: rgba(0,0,0,.3);
  381. z-index: 101;
  382. }
  383. .jump-dialog {
  384. position: fixed;
  385. bottom: 120rpx;
  386. right: 24rpx;
  387. width: 100rpx;
  388. height: 100rpx;
  389. border-radius: 50%;
  390. background-color: rgba(0,0,0,.3);
  391. font-size: 16rpx;
  392. color: #fff;
  393. z-index: 100;
  394. &.tabbarbool {
  395. bottom: 240rpx;
  396. }
  397. image {
  398. width: 54rpx;
  399. height: 54rpx;
  400. margin-bottom: 3rpx;
  401. display: block;
  402. }
  403. }
  404. .use-info {
  405. position: fixed;
  406. bottom: 64rpx;
  407. text-align: center;
  408. font-size: 28rpx;
  409. width: 200rpx;
  410. margin: 0 auto;
  411. left: 0;
  412. right: 0;
  413. &.tabbarbool {
  414. bottom: 204rpx;
  415. }
  416. }
  417. .scan {
  418. position: absolute;
  419. top: 0;
  420. left: 0;
  421. width: 100%;
  422. height: 100%;
  423. background-color: #fff;
  424. text-align: center;
  425. padding-top: 184rpx;
  426. font-size: 28rpx;
  427. color: #353535;
  428. .scan-input {
  429. height: 94rpx;
  430. width: 580rpx;
  431. margin: 40rpx auto;
  432. background-color: #f9f9f9;
  433. border: 2rpx solid #e2e2e2;
  434. border-radius: 16rpx;
  435. position: relative;
  436. box-shadow: 1rpx 1rpx 4rpx 4rpx #f5f5f5;
  437. input {
  438. border-radius: 16rpx;
  439. width: 100%;
  440. height: 100%;
  441. padding: 10rpx 80rpx 10rpx 20rpx;
  442. text-align: left;
  443. }
  444. image {
  445. width: 48rpx;
  446. height: 44rpx;
  447. position: absolute;
  448. right: 24rpx;
  449. top: 23rpx;
  450. z-index: 2
  451. }
  452. }
  453. .scan-button {
  454. height: 300rpx;
  455. width: 300rpx;
  456. border-radius: 50%;
  457. text-align: center;
  458. line-height: 300rpx;
  459. box-shadow: 2rpx 2rpx 8rpx 8rpx #f3f3f3;
  460. margin: 112rpx auto;
  461. font-size: 42rpx;
  462. font-weight: 600;
  463. color: #fff;
  464. &.default {
  465. color: #b2b2b2;
  466. background-color: #d6d6d6;
  467. }
  468. }
  469. }
  470. .item {
  471. margin: 24rpx 24rpx 0;
  472. background-color: #fff;
  473. border-radius: 16rpx;
  474. .status {
  475. padding: 28rpx 30rpx;
  476. border-bottom: 2rpx solid #e2e2e2;
  477. .item-code {
  478. padding: 16rpx 30rpx;
  479. border-radius: 40rpx;
  480. font-size: 28rpx;
  481. font-weight: 600;
  482. &.default {
  483. background-color: #F5F5F5;
  484. color: #999999;
  485. }
  486. }
  487. .item-status {
  488. font-size: 28rpx;
  489. &.default {
  490. color: #999999;
  491. }
  492. view:first-of-type {
  493. margin-right: 16rpx;
  494. }
  495. image {
  496. height: 22rpx;
  497. width: 14rpx;
  498. display: block;
  499. }
  500. }
  501. }
  502. .item-time {
  503. height: 72rpx;
  504. line-height: 72rpx;
  505. font-size: 28rpx;
  506. color: #666666;
  507. padding: 0 30rpx;
  508. }
  509. }
  510. .dialog {
  511. margin: 270rpx auto;
  512. background-color: #fff;
  513. border-radius: 16rpx;
  514. width: 600rpx;
  515. padding: 60rpx 0;
  516. text-align: center;
  517. .dialog-img {
  518. width: 200rpx;
  519. height: 200rpx;
  520. margin: 0 auto 20rpx;
  521. }
  522. .dialog-msg {
  523. font-size: 32rpx;
  524. color: #353535;
  525. }
  526. .dialog-other {
  527. font-size: 24rpx;
  528. color: #999999;
  529. }
  530. .dialog-button {
  531. font-size: 26rpx;
  532. width: 520rpx;
  533. height: 90rpx;
  534. border-radius: 45rpx;
  535. line-height: 90rpx;
  536. text-align: center;
  537. color: #fff;
  538. margin: 50rpx auto 0;
  539. }
  540. }
  541. .u-rules {
  542. border-top-left-radius: 16rpx;
  543. border-top-right-radius: 16rpx;
  544. width: 100%;
  545. position: fixed;
  546. z-index: 1005;
  547. left: 0;
  548. background-color: #fff;
  549. &.iphone_x.tabbarbool {
  550. padding-bottom: 50rpx;
  551. }
  552. .u-rules-top {
  553. border-top-left-radius: 16rpx;
  554. border-top-right-radius: 16rpx;
  555. background-color: #fff;
  556. height: 80rpx;
  557. .end-close {
  558. width: 80rpx;
  559. height: 80rpx;
  560. padding: 25rpx;
  561. image {
  562. width: 30rpx;
  563. height: 30rpx;
  564. }
  565. }
  566. }
  567. .u-rules-content {
  568. padding: 0 20rpx;
  569. min-height: 160rpx;
  570. max-height: 918rpx;
  571. overflow: auto;
  572. }
  573. }
  574. </style>