index.vue 13 KB

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