list.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <template>
  2. <app-layout>
  3. <image class="banner" :src="setting.banner"></image>
  4. <view class="nav-area">
  5. <view class="nav main-center cross-center" :style="{'background-color': getTheme.background}">
  6. <view @click="tabStatus(item,index)" :key="item.id" class="nav-item" v-for="(item,index) in tabList">
  7. <text>{{item.name}}</text>
  8. </view>
  9. <view class="active" :animation="animationData" :style="{'color': getTheme.color}">{{activeTabName}}</view>
  10. </view>
  11. </view>
  12. <view class="placeholder"></view>
  13. <view v-if="list.length > 0">
  14. <view v-for="item in list" :key="item.id" v-if="item.goods_count > 0" class="list">
  15. <view class="title main-center dir-top-nowrap" :style="{'background': getTheme.background_gradient}">
  16. <view class="title-text t-omit">{{item.title}}
  17. <image class="hot-icon" src="./../image/hot.png"></image>
  18. </view>
  19. <view class="sec-title-text t-omit" v-if="item.condition > 0">
  20. <text v-if="item.num - item.condition_count > 0">还差{{item.num - item.condition_count}}{{item.condition == 1 ? '人':'件商品'}}成团</text>
  21. <text v-else>已成团</text>
  22. ,已<text v-if="item.condition == 1">参</text>团{{item.condition_count ? item.condition_count : '0'}}{{item.condition == 1 ? '人':'件'}}
  23. </view>
  24. </view>
  25. <view class="status-text" :style="{'color': getTheme.color}">
  26. <view class="status-bg" :style="{'background-color': getTheme.background}"></view>
  27. {{item.statusText}}
  28. </view>
  29. <view @click="toDetail(item)" class="goods-list">
  30. <view class="dir-left-nowrap">
  31. <view class="goods" v-for="goods in item.communityGoods_4" :key="goods.id">
  32. <image mode='aspectFill' :src="goods.cover_pic"></image>
  33. </view>
  34. </view>
  35. <image class="right-arrow" src="/static/image/icon/arrow-right.png"></image>
  36. </view>
  37. <view class="main-between cross-center other">
  38. <view>共{{item.goods_count}}件商品</view>
  39. </view>
  40. </view>
  41. </view>
  42. <view v-else class="empty-box">
  43. <image v-if="!loading" src="/static/image/no-goods.png"></image>
  44. <span v-if="!loading">暂无{{activeTab == 0?'未开始': activeTab == 1?'进行中':activeTab == 2?'已结束':''}}活动</span>
  45. </view>
  46. </app-layout>
  47. </template>
  48. <script>
  49. import {mapGetters, mapState} from 'vuex';
  50. import appMenu from '../components/app-menu';
  51. import appTabNav from "../../../components/basic-component/app-tab-nav/app-tab-nav.vue";
  52. import appShareQrCode from '../../../components/page-component/app-share-qr-code-poster/app-share-qr-code-poster.vue';
  53. export default {
  54. data() {
  55. return {
  56. tabList: [
  57. {id:-1, name: '全部'},
  58. {id:1, name: '进行中'},
  59. {id:0, name: '未开始'},
  60. {id:2, name: '已结束'}
  61. ],
  62. activeTab: -1,
  63. activeTabName: '全部',
  64. list: [],
  65. setting: {},
  66. widthRate: 1,
  67. id: 0,
  68. loading: false,
  69. more: false,
  70. page: 1,
  71. first: true,
  72. poster: '',
  73. longitude: '',
  74. latitude: '',
  75. middleman: {},
  76. middleman_id: '',
  77. animation: {},
  78. animationData: {}
  79. }
  80. },
  81. components: {
  82. "app-tab-nav": appTabNav,
  83. "app-menu": appMenu,
  84. appShareQrCode
  85. },
  86. computed: {
  87. ...mapGetters('mallConfig', {
  88. getTheme: 'getTheme'
  89. }),
  90. ...mapState({
  91. stock: state => state.mallConfig.__wxapp_img.stock,
  92. bonusImg: state => state.mallConfig.__wxapp_img.bonus,
  93. userInfo: state => state.user.info,
  94. })
  95. },
  96. // #ifdef MP-WEIXIN
  97. onShareTimeline() {
  98. // 分享朋友圈beta
  99. return this.$shareTimeline({
  100. title: this.setting.app_share_title ? this.setting.app_share_title : this.$children[0].navigationBarTitle,
  101. query: {} // 此处填写页面的参数
  102. });
  103. },
  104. // #endif
  105. onShow() {
  106. let that = this;
  107. that.animation = uni.createAnimation({
  108. duration: 400,
  109. timingFunction: 'linear',
  110. });
  111. if(that.first) {
  112. return false;
  113. }
  114. if(this.$storage.getStorageSync('middleman_info')) {
  115. let middleman = this.$storage.getStorageSync('middleman_info');
  116. if(middleman.id > 0) {
  117. that.middleman_id = middleman.user_id
  118. }
  119. that.getList();
  120. }else {
  121. that.getList();
  122. }
  123. },
  124. onLoad() { this.$commonLoad.onload();
  125. let that = this;
  126. uni.getSystemInfo({
  127. success: function (res) {
  128. let width = res.windowWidth * 2;
  129. that.widthRate = width / 750;
  130. }
  131. });
  132. // #ifdef MP-WEIXIN
  133. wx.showShareMenu({
  134. menus: ['shareAppMessage', 'shareTimeline']
  135. })
  136. // #endif
  137. // #ifndef H5
  138. uni.getLocation({
  139. success: (e) => {
  140. uni.hideLoading();
  141. that.longitude = e.longitude;
  142. that.latitude = e.latitude;
  143. that.$showLoading({
  144. type: 'global',
  145. text: '加载中...'
  146. });
  147. that.getSetting();
  148. },
  149. fail: (e) => {
  150. uni.hideLoading();
  151. uni.showModal({
  152. title: '提示',
  153. content: '获取位置信息失败,需要授权获取您的位置信息',
  154. showCancel: false,
  155. confirmText: '打开授权',
  156. success(e) {
  157. if (e.confirm) {
  158. uni.openSetting({});
  159. }
  160. }
  161. });
  162. },
  163. });
  164. // #endif
  165. // #ifdef H5
  166. if (that.$jwx.isWechat()) {
  167. that.$jwx.getLocation({
  168. success(res) {
  169. uni.hideLoading();
  170. that.longitude = res.longitude;
  171. that.latitude = res.latitude;
  172. that.$showLoading({
  173. type: 'global',
  174. text: '加载中...'
  175. });
  176. that.getSetting();
  177. },
  178. fail: function () {
  179. uni.showToast({
  180. title: '请开启手机位置权限',
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. },
  185. })
  186. }else {
  187. uni.getLocation({
  188. success: (e) => {
  189. uni.hideLoading();
  190. that.longitude = e.longitude;
  191. that.latitude = e.latitude;
  192. that.$showLoading({
  193. type: 'global',
  194. text: '加载中...'
  195. });
  196. that.getSetting();
  197. },
  198. fail: (e) => {
  199. uni.showModal({
  200. title: '提示',
  201. content: '定位失败,确保定位服务已开启',
  202. success: function (res) {
  203. if (res.confirm) {
  204. window.location.reload();
  205. } else if (res.cancel) {
  206. let pages = getCurrentPages();
  207. if (pages.length > 1) {
  208. uni.navigateBack();
  209. } else {
  210. uni.navigateTo({
  211. url: 'pages/index/index'
  212. });
  213. }
  214. }
  215. }
  216. });
  217. },
  218. });
  219. }
  220. // #endif
  221. },
  222. onReachBottom() {
  223. if(this.more) {
  224. this.page++;
  225. this.getMore();
  226. this.more = false;
  227. }
  228. },
  229. // #ifdef MP
  230. onShareAppMessage() {
  231. return this.$shareAppMessage({
  232. title: this.setting.app_share_title ? this.setting.app_share_title : this.$children[0].navigationBarTitle,
  233. imageUrl: this.setting.app_share_pic ? this.setting.app_share_pic : '',
  234. path: "/plugins/community/list/list"
  235. });
  236. },
  237. // #endif
  238. methods: {
  239. getMore() {
  240. let that = this;
  241. that.loading = true;
  242. let para = {
  243. longitude: that.longitude,
  244. latitude: that.latitude,
  245. page: that.page,
  246. status: that.activeTab
  247. };
  248. if(that.middleman_id > 0) {
  249. para.middleman_id = that.middleman_id
  250. }
  251. that.$request({
  252. url: that.$api.community.list,
  253. data: para,
  254. }).then(response=>{
  255. that.loading = false;
  256. that.first = false;
  257. that.$hideLoading();
  258. uni.hideLoading();
  259. if(response.code === 0) {
  260. if (response.list.length === 20) {
  261. that.more = true;
  262. }else {
  263. that.more = false
  264. }
  265. for(let index in response.list) {
  266. if(response.list[index].goods_count == 0) {
  267. response.list.splice(index,1)
  268. }
  269. }
  270. that.list = that.list.concat(response.list);
  271. for(let i in that.list) {
  272. if(that.list[i].status_name === '已结束') {
  273. that.list[i].statusText = '活动结束'
  274. }else if(that.list[i].status_name === '进行中') {
  275. that.list[i].statusText = that.list[i].end_at + '结束'
  276. }else if(that.list[i].status_name === '未开始') {
  277. that.list[i].statusText = that.list[i].start_at + '开始'
  278. }
  279. }
  280. }else {
  281. uni.showToast({
  282. title: response.msg,
  283. icon: 'none',
  284. duration: 1000
  285. });
  286. }
  287. }).catch(() => {
  288. that.loading = false;
  289. uni.hideLoading();
  290. that.$hideLoading();
  291. });
  292. },
  293. toDetail(item) {
  294. uni.navigateTo({
  295. url: '/plugins/community/activity/activity?id=' + item.id + '&title=' + item.title
  296. });
  297. },
  298. tabStatus(e,index) {
  299. let that = this;
  300. if(that.loading) {
  301. return false
  302. }
  303. that.list = [];
  304. that.page = 1;
  305. that.activeTab = e.id;
  306. that.activeTabName = e.name;
  307. let width = 88* +that.widthRate * index;
  308. that.animation.translate(width, 0).step();
  309. that.animationData = that.animation.export();
  310. // uni.showLoading({mask: true,
  311. // title: '加载中...'
  312. // });
  313. that.getList();
  314. },
  315. getSetting() {
  316. let that = this;
  317. that.$showLoading({
  318. type: 'global',
  319. text: '加载中...'
  320. });
  321. that.$request({
  322. url: that.$api.community.setting,
  323. }).then(response=>{
  324. if(response.code === 0) {
  325. that.setting = response.data;
  326. if(this.$storage.getStorageSync('middleman_info')) {
  327. let middleman = this.$storage.getStorageSync('middleman_info');
  328. if(middleman.id > 0) {
  329. that.middleman_id = middleman.user_id
  330. }
  331. that.getList();
  332. }else {
  333. that.getList();
  334. }
  335. }else {
  336. that.$hideLoading();
  337. uni.showToast({
  338. title: response.msg,
  339. icon: 'none',
  340. duration: 1000
  341. });
  342. }
  343. }).catch(() => {
  344. that.$hideLoading();
  345. });
  346. },
  347. getList() {
  348. let that = this;
  349. that.loading = true;
  350. let para = {
  351. longitude: that.longitude,
  352. latitude: that.latitude,
  353. status: that.activeTab
  354. };
  355. if(that.middleman_id > 0) {
  356. para.middleman_id = that.middleman_id
  357. }
  358. that.$request({
  359. url: that.$api.community.list,
  360. data: para,
  361. method: 'post'
  362. }).then(response=>{
  363. that.loading = false;
  364. that.first = false;
  365. that.$hideLoading();
  366. uni.hideLoading();
  367. if(response.code === 0) {
  368. if (response.list.length === 20) {
  369. that.more = true;
  370. }else {
  371. that.more = false
  372. }
  373. for(let index in response.list) {
  374. if(response.list[index].goods_count == 0) {
  375. response.list.splice(index,1)
  376. }
  377. }
  378. that.list = response.list;
  379. for(let i in that.list) {
  380. if(that.list[i].status_name === '已结束') {
  381. that.list[i].statusText = '活动结束'
  382. }else if(that.list[i].status_name === '进行中') {
  383. that.list[i].statusText = that.list[i].end_at + '结束'
  384. }else if(that.list[i].status_name === '未开始') {
  385. that.list[i].statusText = that.list[i].start_at + '开始'
  386. }
  387. }
  388. if(response.removeStorage) {
  389. this.$storage.removeStorageSync('middleman_info');
  390. }
  391. }else {
  392. uni.showToast({
  393. title: response.msg,
  394. icon: 'none',
  395. duration: 1000
  396. });
  397. }
  398. }).catch(() => {
  399. that.loading = false;
  400. uni.hideLoading();
  401. that.$hideLoading();
  402. });
  403. }
  404. }
  405. }
  406. </script>
  407. <style scoped lang="scss">
  408. .list {
  409. margin: #{24rpx};
  410. width: #{702rpx};
  411. .title {
  412. height: #{115rpx};
  413. font-size: #{22rpx};
  414. color: #fff;
  415. border-top-left-radius: #{16rpx};
  416. border-top-right-radius: #{16rpx};
  417. padding-left: 63rpx;
  418. .title-text {
  419. font-size: #{30rpx};
  420. font-weight: 600;
  421. height: #{35rpx};
  422. line-height: #{35rpx};
  423. max-width: #{600rpx};
  424. position: relative;
  425. overflow: inherit;
  426. .hot-icon {
  427. position: absolute;
  428. top: 0;
  429. left: #{-49rpx};
  430. width: #{35rpx};
  431. height: #{35rpx};
  432. }
  433. }
  434. .sec-title-text {
  435. width: #{600rpx};
  436. }
  437. }
  438. .status-text {
  439. text-align: center;
  440. position: relative;
  441. width: 100%;
  442. height: #{48rpx};
  443. line-height: #{48rpx};
  444. font-size: #{26rpx};
  445. .status-bg {
  446. position: absolute;
  447. top: 0;
  448. left: 0;
  449. width: 100%;
  450. height: 100%;
  451. opacity: 0.1;
  452. z-index: 0;
  453. }
  454. }
  455. .goods-list {
  456. position: relative;
  457. height: #{160rpx};
  458. background-color: #fff;
  459. padding: 0 #{24rpx} #{24rpx};
  460. .goods {
  461. height: #{160rpx};
  462. padding-top: #{22rpx};
  463. padding-bottom: #{22rpx};
  464. image {
  465. margin-right: #{38rpx};
  466. height: #{120rpx};
  467. width: #{120rpx};
  468. border-radius: #{16rpx};
  469. }
  470. }
  471. .right-arrow {
  472. position: absolute;
  473. top: 50%;
  474. margin-top: #{-12rpx};
  475. right: #{30rpx};
  476. width: #{12rpx};
  477. height: #{24rpx};
  478. }
  479. }
  480. .other {
  481. padding: 0 #{24rpx} #{24rpx};
  482. font-size: #{24rpx};
  483. color: #999;
  484. height: #{60rpx};
  485. background-color: #fff;
  486. border-bottom-left-radius: #{16rpx};
  487. border-bottom-right-radius: #{16rpx};
  488. .other-button {
  489. line-height: #{58rpx};
  490. height: #{58rpx};
  491. padding: 0 #{35rpx};
  492. border-radius: #{30rpx};
  493. border: #{2rpx} solid #e2e2e2;
  494. display: inline-block;
  495. font-size: #{24rpx};
  496. margin-left: #{25rpx};
  497. &.active {
  498. border-color: #ff4544;
  499. color: #ff4544;
  500. }
  501. }
  502. }
  503. }
  504. .banner {
  505. position: fixed;
  506. top: 0;
  507. left: 0;
  508. z-index: 10;
  509. height: #{280rpx};
  510. width: #{750rpx};
  511. background-color: #f7f7f7;
  512. }
  513. .nav-area {
  514. background-color: #f7f7f7;
  515. position: fixed;
  516. top: #{280rpx};
  517. left: 0;
  518. z-index: 10;
  519. .nav {
  520. height: #{54rpx};
  521. width: #{702rpx};
  522. margin: #{35rpx} #{24rpx};
  523. border-radius: 27rpx;
  524. box-shadow: rgba(186, 186, 186, 0.35) 0 4rpx 4rpx;
  525. .active {
  526. position: absolute;
  527. top: 28rpx;
  528. left: #{24rpx};
  529. width: 182rpx;
  530. height: 68rpx;
  531. line-height: 68rpx;
  532. z-index: 10;
  533. background-color: #fff;
  534. border-radius: 27rpx;
  535. text-align: center;
  536. box-shadow: rgba(186, 186, 186, 0.35) 0 4rpx 4rpx;
  537. }
  538. .nav-item {
  539. width: 25%;
  540. height: #{54rpx};
  541. color: #ffffff;
  542. font-size: #{28rpx};
  543. text-align: center;
  544. line-height: #{54rpx};
  545. position: relative;
  546. }
  547. }
  548. }
  549. .placeholder {
  550. height: #{380rpx};
  551. }
  552. .empty-box {
  553. width: 100%;
  554. height: 60vh;
  555. display: flex;
  556. justify-content: center;
  557. align-items: center;
  558. flex-direction: column;
  559. image {
  560. width: 280#{rpx};
  561. height: 280#{rpx};
  562. }
  563. span {
  564. margin-top: 15#{rpx};
  565. color: #999;
  566. font-size: 28#{rpx};
  567. }
  568. }
  569. </style>