list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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="goods dir-left-wrap">
  5. <view style="width: 100%" v-if="list.length > 0">
  6. <app-product-list sign="exchange" :theme="getTheme" @routeGo="jump" :listStyle="listStyle" :goods_list="list"></app-product-list>
  7. </view>
  8. <view style="padding-top: 30%;width: 100%;" v-if="list.length == 0">
  9. <app-no-goods title="暂无可购买的礼品卡" background="#f7f7f7"></app-no-goods>
  10. </view>
  11. </view>
  12. <view v-if="activeTab == '1'">
  13. <view class="item" v-for="(item,index) in list" :key="index">
  14. <view class="dir-left-nowrap cross-center status">
  15. <view class="item-cover">
  16. <app-image :img-src="item.cover_pic" width="140rpx" height="140rpx"
  17. :border-radius="`8rpx 8rpx 0 0`"></app-image>
  18. </view>
  19. <view class="t-omit-two item-name">{{item.name}}</view>
  20. </view>
  21. <view class="item-time main-between cross-center">
  22. <view>购买时间:{{item.created_at}}</view>
  23. <view v-if="item.status == 'unused'" @click="apply(item)" :style="{'background-color': getTheme.background}" class="rewards-submit">立即使用</view>
  24. <view v-else-if="item.status == 'used'" @click="apply(item)" class="rewards-submit over">已使用</view>
  25. <view @click="apply(item)" v-else class="rewards-submit over">已失效</view>
  26. </view>
  27. </view>
  28. <view style="padding-top: 30%" v-if="list.length == 0">
  29. <app-no-goods title="暂无已获得的礼品卡" background="#f7f7f7"></app-no-goods>
  30. </view>
  31. </view>
  32. <view @click="toIndex" v-if="setting.is_to_exchange == 1" class="jump-dialog cross-center dir-top-nowrap main-center" :class="[`${tabbarbool? 'tabbarbool':''}`]">
  33. <image :src="setting.to_exchange_pic"></image>
  34. <view>兑换中心</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 appProductList from '../../../components/page-component/app-product-list/app-product-list.vue';
  41. import appPrice from '../../../components/page-component/goods/app-price.vue';
  42. import appNoGoods from '../../../components/page-component/app-no-goods/app-no-goods.vue';
  43. import uMask from '../../../components/basic-component/u-mask/u-mask.vue';
  44. import { mapState, mapGetters } from "vuex";
  45. export default {
  46. name: "index",
  47. data() {
  48. return {
  49. currentRoute: this.$platDiff.route(),
  50. tabbarbool: false,
  51. tabList: [
  52. {id:0, name: '购买礼品卡'},
  53. {id:1, name: '我的礼品卡'}
  54. ],
  55. code: '',
  56. activeTab: '0',
  57. list: [],
  58. setting: {},
  59. listStyle: false,
  60. loading: false,
  61. more: false,
  62. dialog: false,
  63. msg: '',
  64. page: 1,
  65. };
  66. },
  67. computed: {
  68. ...mapState({
  69. appImg: state => state.mallConfig.__wxapp_img.mall,
  70. appSetting: state => state.mallConfig.mall.setting,
  71. tabBarNavs: state => state.mallConfig.navbar.navs,
  72. platform: function(state) {
  73. return state.gConfig.systemInfo.platform;
  74. }
  75. }),
  76. ...mapGetters('mallConfig', {
  77. getTheme: 'getTheme'
  78. }),
  79. ...mapGetters('mallConfig', {
  80. getVideo: 'getVideo'
  81. })
  82. },
  83. components: {
  84. "app-tab-nav": appTabNav,
  85. 'app-product-list': appProductList,
  86. appPrice,
  87. appNoGoods,
  88. "u-mask": uMask
  89. },
  90. watch: {
  91. tabBarNavs: {
  92. handler: function() {
  93. this.b();
  94. },
  95. immediate: true,
  96. }
  97. },
  98. // #ifdef MP
  99. onShareAppMessage() {
  100. return this.$shareAppMessage({
  101. title: this.$children[0].navigationBarTitle,
  102. path: "/plugins/exchange/list/list",
  103. });
  104. },
  105. // #endif
  106. // #ifdef MP-WEIXIN
  107. onShareTimeline() {
  108. // 分享朋友圈beta
  109. return this.$shareTimeline({
  110. title: this.$children[0].navigationBarTitle,
  111. query: {} // 此处填写页面的参数
  112. });
  113. },
  114. // #endif
  115. onLoad(options) { this.$commonLoad.onload(options);
  116. // #ifdef MP-WEIXIN
  117. wx.showShareMenu({
  118. menus: ['shareAppMessage', 'shareTimeline']
  119. })
  120. // #endif
  121. if(options.tab > 0) {
  122. this.activeTab = options.tab.toString();
  123. }
  124. this.$showLoading({
  125. type: 'global',
  126. text: '加载中...'
  127. });
  128. this.$request({
  129. url: this.$api.exchange.setting,
  130. }).then(response=>{
  131. if(response.code == 0) {
  132. this.setting = response.data;
  133. this.getList();
  134. }else {
  135. uni.showToast({
  136. title: response.msg,
  137. icon: 'none',
  138. duration: 1000
  139. });
  140. }
  141. })
  142. },
  143. onShow() {
  144. if(this.activeTab == '1') {
  145. this.getList();
  146. }
  147. },
  148. onReachBottom() {
  149. if(this.more) {
  150. this.page++;
  151. this.getMore();
  152. }
  153. },
  154. methods: {
  155. b() {
  156. // #ifndef H5
  157. let currentRoute = this.currentRoute;
  158. for (let i = 0; i < this.tabBarNavs.length; i++) {
  159. if(currentRoute.includes(this.tabBarNavs[i].url.split('?')[0])) {
  160. return this.tabbarbool = true;
  161. }
  162. }
  163. // #endif
  164. return this.tabbarbool = false;
  165. },
  166. toIndex() {
  167. uni.navigateTo({
  168. url: '/plugins/exchange/index/index'
  169. })
  170. },
  171. getMore() {
  172. let that = this;
  173. if(this.loading) {
  174. return false
  175. }
  176. this.loading = true;
  177. this.more = false;
  178. that.$request({
  179. url: that.activeTab == '0' ? that.$api.exchange.list : that.$api.exchange.me_list,
  180. data: {
  181. page: this.page
  182. }
  183. }).then(response=>{
  184. that.$hideLoading();
  185. uni.hideLoading();
  186. this.loading = false;
  187. if(response.code == 0) {
  188. that.list = that.list.concat(response.data.list);
  189. if(response.data.list.length == response.data.pagination.pageSize) {
  190. this.more = true;
  191. }
  192. }else {
  193. uni.showToast({
  194. title: response.msg,
  195. icon: 'none',
  196. duration: 1000
  197. });
  198. }
  199. }).catch(response => {
  200. that.$hideLoading();
  201. uni.hideLoading();
  202. });
  203. },
  204. jump(data) {
  205. // #ifndef MP-BAIDU
  206. if (data.video_url && this.getVideo == 1) {
  207. // #ifdef MP
  208. uni.navigateTo({
  209. url: `/pages/goods/video?goods_id=${data.id}&sign=exchange`
  210. });
  211. // #endif
  212. // #ifdef H5
  213. uni.navigateTo({
  214. url: `/plugins/exchange/goods/goods?goods_id=${data.id}`
  215. });
  216. // #endif
  217. } else {
  218. uni.navigateTo({
  219. url: `/plugins/exchange/goods/goods?goods_id=${data.id}`
  220. });
  221. }
  222. // #endif
  223. // #ifdef MP-BAIDU
  224. uni.navigateTo({
  225. url: `/plugins/exchange/goods/goods?goods_id=${data.id}`
  226. });
  227. // #endif
  228. },
  229. apply(goods) {
  230. uni.navigateTo({
  231. url: '/plugins/exchange/gift/gift?code=' + goods.code
  232. })
  233. },
  234. tabStatus(e) {
  235. if(this.loading) {
  236. return false
  237. }
  238. this.list = [];
  239. this.page = 1;
  240. this.activeTab = e.currentTarget.dataset.id;
  241. uni.showLoading({
  242. mask: true,
  243. title: '加载中...'
  244. });
  245. this.getList();
  246. },
  247. getList() {
  248. let that = this;
  249. if(this.loading) {
  250. return false
  251. }
  252. this.loading = true;
  253. this.page = 1;
  254. this.more = false;
  255. that.$request({
  256. url: that.activeTab == '0' ? that.$api.exchange.list : that.$api.exchange.me_list
  257. }).then(response=>{
  258. that.$hideLoading();
  259. uni.hideLoading();
  260. this.loading = false;
  261. if(response.code == 0) {
  262. that.list = response.data.list;
  263. if(that.list.length == response.data.pagination.pageSize) {
  264. this.more = true;
  265. }
  266. }else {
  267. uni.showToast({
  268. title: response.msg,
  269. icon: 'none',
  270. duration: 1000
  271. });
  272. }
  273. }).catch(response => {
  274. that.$hideLoading();
  275. uni.hideLoading();
  276. });
  277. },
  278. }
  279. }
  280. </script>
  281. <style scoped lang="scss">
  282. .jump-dialog {
  283. position: fixed;
  284. bottom: 120rpx;
  285. right: 24rpx;
  286. width: 100rpx;
  287. height: 100rpx;
  288. border-radius: 50%;
  289. background-color: rgba(0,0,0,.3);
  290. font-size: 16rpx;
  291. color: #fff;
  292. z-index: 100;
  293. &.tabbarbool {
  294. bottom: 240rpx;
  295. }
  296. image {
  297. width: 54rpx;
  298. height: 54rpx;
  299. margin-bottom: 3rpx;
  300. display: block;
  301. }
  302. }
  303. .item {
  304. margin: 24rpx 24rpx 0;
  305. background-color: #fff;
  306. border-radius: 16rpx;
  307. .status {
  308. padding: 28rpx 30rpx;
  309. border-bottom: 2rpx solid #e2e2e2;
  310. .item-cover {
  311. width: 140rpx;
  312. flex-shrink: 0;
  313. margin-right: 30rpx;
  314. }
  315. .item-name {
  316. font-size: 28rpx;
  317. color: #353535;
  318. }
  319. }
  320. .item-time {
  321. height: 112rpx;
  322. font-size: 28rpx;
  323. color: #666666;
  324. padding: 0 30rpx;
  325. .rewards-submit {
  326. height: 68rpx;
  327. line-height: 68rpx;
  328. text-align: center;
  329. padding: 0 30rpx;
  330. border-radius: 40rpx;
  331. color: #fff;
  332. font-size: #{28rpx};
  333. &.over {
  334. background-color: #f7f7f7;
  335. color: #999999;
  336. }
  337. }
  338. }
  339. }
  340. </style>