index.vue 12 KB

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