index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. f<template>
  2. <app-layout>
  3. <app-tab-nav :tabList="tabList" :activeItem="activeTab" @click="tabStatus" :theme="theme"></app-tab-nav>
  4. <view class="card-list">
  5. <view @click="toDetail(item.id)" v-for="item in list" :key="item.id">
  6. <view class="card-item">
  7. <image class="card-img" :src="item.pic_url"></image>
  8. <view class="name">{{item.name}}</view>
  9. <view class="right-box">
  10. <image v-if="item.is_may_use == 1" class="card-qr" @click.stop="showModal(item.id)" src="/static/image/icon/icon-card-qrcode.png"></image>
  11. <span>{{activeTab == 3 ? '未核销' : '剩余'}}{{item.surplus_number}}次</span>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="no-list" v-if="list.length === 0">
  17. <app-no-goods background="#f7f7f7" :title="title"></app-no-goods>
  18. </view>
  19. <view class="qr-modal" @click="show=false" v-if="show">
  20. <view class="look-qr" @click.stop="showModal(0)">
  21. <view>卡券二维码</view>
  22. <view>
  23. <image :src="img"></image>
  24. </view>
  25. <view style="height: 60rpx">
  26. <view @click="saveImg">
  27. <button :class="[`${theme}-background`]">保存图片</button>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </app-layout>
  33. </template>
  34. <script>
  35. import appTabNav from "../../../components/basic-component/app-tab-nav/app-tab-nav.vue";
  36. import appNoGoods from '../../../components/page-component/app-no-goods/app-no-goods.vue';
  37. import {
  38. mapState
  39. } from "vuex";
  40. export default {
  41. data() {
  42. return {
  43. tabList: [{
  44. id: 1,
  45. name: '未使用'
  46. },
  47. {
  48. id: 2,
  49. name: '已使用'
  50. },
  51. {
  52. id: 3,
  53. name: '已过期'
  54. }
  55. ],
  56. show: false,
  57. img: '/images/share/img-share-order.png',
  58. activeTab: 1,
  59. list: [],
  60. more: false,
  61. page: 2,
  62. // title: '暂无未使用优惠券~'
  63. title: '暂无课程~',
  64. type: 1, //我的课程1 我的比赛2
  65. }
  66. },
  67. components: {
  68. 'app-tab-nav': appTabNav,
  69. 'app-no-goods': appNoGoods,
  70. },
  71. computed: {
  72. ...mapState({
  73. theme: state => state.mallConfig.theme,
  74. userInfo: state => state.user.info,
  75. })
  76. },
  77. methods: {
  78. saveImg() {
  79. let that = this;
  80. // #ifndef MP-ALIPAY
  81. uni.authorize({
  82. scope: 'scope.writePhotosAlbum',
  83. success(res) {
  84. if (res.errMsg == "authorize:ok") {
  85. uni.downloadFile({
  86. url: that.img,
  87. success(res) {
  88. uni.saveImageToPhotosAlbum({
  89. filePath: res.tempFilePath,
  90. success() {
  91. uni.showToast({
  92. title: '保存成功',
  93. icon: 'success',
  94. duration: 1000
  95. })
  96. },
  97. fail() {
  98. uni.showToast({
  99. title: '保存失败',
  100. icon: 'none',
  101. duration: 1000
  102. })
  103. }
  104. })
  105. }
  106. })
  107. }
  108. },
  109. fail(res) {
  110. uni.showModal({
  111. title: '提示',
  112. content: '保存失败,需要授权保存到相册权限',
  113. showCancel: false,
  114. confirmText: '打开授权',
  115. success(e) {
  116. if (e.confirm) {
  117. uni.openSetting({});
  118. }
  119. }
  120. });
  121. }
  122. })
  123. // #endif
  124. // #ifdef MP-ALIPAY
  125. my.showLoading({
  126. content: '图片保存中'
  127. });
  128. my.saveImage({
  129. url: that.img,
  130. showActionSheet: true,
  131. success: (res) => {
  132. uni.showToast({
  133. title: '保存成功',
  134. icon: 'success',
  135. duration: 1000
  136. })
  137. },
  138. fail() {
  139. uni.showToast({
  140. title: '保存失败',
  141. icon: 'none',
  142. duration: 1000
  143. })
  144. },
  145. complete() {
  146. my.hideLoading();
  147. }
  148. });
  149. // #endif
  150. },
  151. showModal(id) {
  152. let that = this;
  153. if (id > 0) {
  154. uni.showLoading({
  155. text: '生成中...'
  156. });
  157. that.$request({
  158. url: that.$api.card.qrcode,
  159. data: {
  160. cardId: id,
  161. },
  162. method: 'get'
  163. }).then(response => {
  164. uni.hideLoading();
  165. if (response.code === 0) {
  166. that.show = true;
  167. that.img = response.data.file_path;
  168. } else {
  169. uni.showToast({
  170. title: response.msg,
  171. icon: 'none',
  172. duration: 1000,
  173. });
  174. }
  175. }).catch(response => {
  176. uni.hideLoading();
  177. uni.showToast({
  178. title: response,
  179. icon: 'none',
  180. duration: 1000,
  181. });
  182. });
  183. }
  184. },
  185. tabStatus(e) {
  186. this.list = [];
  187. let id = e.currentTarget.dataset.id;
  188. // if (id === 1) {
  189. // this.title = `暂无未使用优惠券~`;
  190. // } else if (id === 2) {
  191. // this.title = `暂无已使用优惠券~`;
  192. // } else if (id === 3) {
  193. // this.title = `暂无已过期优惠券~`;
  194. // }
  195. if (id === 1) {
  196. if (this.type == 2) {
  197. this.title = `暂无比赛~`;
  198. } else {
  199. this.title = `暂无课程~`;
  200. }
  201. } else if (id === 2) {
  202. if (this.type == 2) {
  203. this.title = `暂无比赛~`;
  204. } else {
  205. this.title = `暂无课程~`;
  206. }
  207. } else if (id === 3) {
  208. if (this.type == 2) {
  209. this.title = `暂无比赛~`;
  210. } else {
  211. this.title = `暂无课程~`;
  212. }
  213. }
  214. this.page = 2;
  215. this.activeTab = id;
  216. this.getList();
  217. },
  218. getList() {
  219. let that = this;
  220. that.$showLoading({
  221. text: '加载中...'
  222. });
  223. that.$request({
  224. url: that.type == 1 ? that.$api.card.index + '&type=1' : that.type == 2 ? that.$api.card.index + '&type=2' : that.$api.card.index + '&type=3',
  225. data: {
  226. status: that.activeTab
  227. },
  228. }).then(response => {
  229. that.$hideLoading();
  230. if (response.code === 0) {
  231. that.list = response.data.list;
  232. } else {
  233. uni.showToast({
  234. title: response.msg,
  235. icon: 'none',
  236. duration: 1000
  237. });
  238. }
  239. }).catch(() => {
  240. that.$hideLoading();
  241. that.$event.on(that.$const.EVENT_USER_LOGIN).then(() => {
  242. that.getList();
  243. });
  244. });
  245. },
  246. getMore() {
  247. let that = this;
  248. uni.showLoading({
  249. title: '加载中...',
  250. });
  251. that.$request({
  252. url: that.$api.card.index,
  253. data: {
  254. page: that.page,
  255. status: that.activeTab
  256. },
  257. }).then(response => {
  258. uni.hideLoading();
  259. if (response.code === 0) {
  260. if (response.data.list.length > 0) {
  261. that.loading = null;
  262. that.list = that.list.concat(response.data.list);
  263. that.page++;
  264. }
  265. } else {
  266. uni.showToast({
  267. title: response.msg,
  268. icon: 'none',
  269. duration: 1000,
  270. });
  271. }
  272. }).catch(() => {
  273. that.$hideLoading();
  274. });
  275. },
  276. toDetail(id) {
  277. uni.navigateTo({
  278. url: `/pages/card/details/details?id=${id}`
  279. });
  280. },
  281. },
  282. onLoad(option) {
  283. console.log(option)
  284. this.type = option.type
  285. this.getList();
  286. },
  287. onShow() {
  288. setTimeout(() => {
  289. uni.setNavigationBarTitle({
  290. title: this.type == 1 ? '我的课程' : this.type==2?'我的比赛':'我的培训'
  291. });
  292. }, 1000)
  293. },
  294. onReachBottom() {
  295. this.getMore();
  296. }
  297. }
  298. </script>
  299. <style scoped lang="scss">
  300. .no-list {
  301. margin-top: #{150upx};
  302. }
  303. .card-list {
  304. width: 100%;
  305. padding-top: #{10rpx};
  306. background-color: #f7f7f7;
  307. }
  308. .card-item {
  309. height: #{180rpx};
  310. margin: #{20rpx};
  311. background-color: #fff;
  312. color: #353535;
  313. font-size: #{30rpx};
  314. display: flex;
  315. align-items: center;
  316. border-radius: 16#{rpx};
  317. .name {
  318. display: -webkit-box;
  319. -webkit-box-orient: vertical;
  320. -webkit-line-clamp: 2;
  321. text-overflow: ellipsis;
  322. overflow: hidden;
  323. width: 402#{rpx};
  324. margin-left:35#{rpx};
  325. }
  326. .card-img {
  327. height: #{88rpx};
  328. width: #{88rpx};
  329. border-radius: 50%;
  330. margin-left:24#{rpx};
  331. }
  332. .right-box {
  333. margin: #{65rpx} #{35rpx};
  334. display: flex;
  335. flex-direction: column;
  336. align-items: center;
  337. .card-qr {
  338. height: #{50rpx};
  339. width: #{50rpx};
  340. }
  341. span {
  342. font-size:20#{rpx};
  343. color: #353535;
  344. margin-top:10#{rpx};
  345. }
  346. }
  347. }
  348. .qr-modal {
  349. position: absolute;
  350. left: 0;
  351. right: 0;
  352. top: 0;
  353. background-color: rgba(0, 0, 0, 0.5);
  354. height: 100%;
  355. width: 100%;
  356. z-index: 2;
  357. }
  358. .look-qr {
  359. position: absolute;
  360. background-color: #fff;
  361. width: #{550rpx};
  362. height: #{700rpx};
  363. left: 50%;
  364. margin-left: #{-275rpx};
  365. top: 20%;
  366. border-radius: #{10rpx};
  367. text-align: center;
  368. padding: #{50rpx};
  369. font-size: #{34rpx};
  370. color: #353535;
  371. }
  372. .look-qr image {
  373. margin-top: #{25rpx};
  374. height: #{450rpx};
  375. width: #{450rpx};
  376. }
  377. .look-qr button {
  378. margin-top: #{15rpx};
  379. height: #{60rpx};
  380. line-height: #{60rpx};
  381. color: #fff;
  382. font-size: #{28rpx};
  383. width: #{200rpx};
  384. }
  385. </style>