index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <view class="content">
  3. <div class="choose-box">
  4. <div class="type" :class="{ active: typeActive }">
  5. <picker
  6. @change="bindPickerChange($event, 'type')"
  7. :value="indexType"
  8. :range="pickerTypeArray"
  9. range-key="label"
  10. class="packer"
  11. >
  12. <view class="picker_title">
  13. {{ pickerType }}
  14. </view>
  15. </picker>
  16. </div>
  17. <div class="state" :class="{ active: !typeActive }">
  18. <picker
  19. @change="bindPickerChange($event, 'state')"
  20. :value="indexState"
  21. :range="pickerStateArray"
  22. range-key="label"
  23. class="packer"
  24. >
  25. <view class="picker_title">
  26. {{ pickerState }}
  27. </view>
  28. </picker>
  29. </div>
  30. </div>
  31. <div class="actives">
  32. <div
  33. v-for="(active, idx) in activeListCopy"
  34. :key="idx"
  35. class="actives-item"
  36. @click="goDeatil(active.id)"
  37. >
  38. <div class="active-content">
  39. <div class="img-box"><img :src="active.url" alt="" /></div>
  40. <div class="right">
  41. <div class="right-title">{{ active.title }}</div>
  42. <div class="right-inf">
  43. <div class="inf-type right-item" style="width: 17%">
  44. <div
  45. :class="{ color: active.type == 1 }"
  46. class="originColor"
  47. ></div>
  48. <div>{{ active.type == 1 ? "线上" : "线下" }}</div>
  49. </div>
  50. <div class="inf-way right-item">
  51. {{ active.way }}
  52. </div>
  53. <div class="inf-date right-item">
  54. {{ active.date }}
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="readShare">
  60. <div v-show="active.status == '待开始'" class="active-tips-box wait-color">
  61. <!-- 活动待开始 -->
  62. {{active.timeStatus}}日开始
  63. </div>
  64. <div v-show="active.status == '已开始'" class="active-tips-box ing-color">
  65. 活动进行中
  66. </div>
  67. <div v-show="active.status == '已结束'" class="active-tips-box end-color">
  68. 活动已结束
  69. </div>
  70. <div class="read">浏览 {{ active.read }}</div>
  71. <div class="share">分享 {{ active.share }}</div>
  72. </div>
  73. </div>
  74. </div>
  75. </view>
  76. </template>
  77. <script>
  78. import md5 from "@/common/md5.js";
  79. export default {
  80. data() {
  81. return {
  82. pickerState: "状态",
  83. pickerType: "类型",
  84. message: "找活动",
  85. themeColor: "#007AFF",
  86. mode: "selector",
  87. typeActive: true,
  88. indexType: 0,
  89. indexState: 0,
  90. timeStatus:'',
  91. pickerTypeArray: [
  92. {
  93. label: "全部",
  94. value: 0,
  95. },
  96. {
  97. label: "线上",
  98. value: 1,
  99. },
  100. {
  101. label: "线下",
  102. value: 2,
  103. },
  104. ],
  105. pickerStateArray: [
  106. {
  107. label: "全部",
  108. value: 3,
  109. },
  110. {
  111. label: "待开始",
  112. value: '0',
  113. },
  114. {
  115. label: "已开始",
  116. value: '1',
  117. },
  118. {
  119. label: "已结束",
  120. value: '2',
  121. },
  122. ],
  123. activeList: [
  124. // {
  125. // url: "/static/activity/1.png",
  126. // title: "400场讲座,200门课程,免费送上门!就等你申请",
  127. // way: "区人力资源局",
  128. // date: "2021-08-08",
  129. // read: 322,
  130. // share: 1,
  131. // type: 1, //1线上
  132. // },
  133. // {
  134. // url: "/static/activity/2.png",
  135. // title: "智能制造商标品牌培育系列培训活动",
  136. // way: "市场监督管理局",
  137. // date: "2021-08-07",
  138. // read: 322,
  139. // share: 1,
  140. // type: 2, //2线下
  141. // },
  142. ],
  143. activeListCopy: [],
  144. };
  145. },
  146. onLoad() {
  147. },
  148. onShow() {
  149. this.getActive();
  150. },
  151. methods: {
  152. bindPickerChange(e, op) {
  153. console.log(e.detail);
  154. switch (op) {
  155. case "type":
  156. this.indexType = e.detail.value;
  157. this.pickerType = this.pickerTypeArray[this.indexType].label;
  158. this.typeActive = true;
  159. break;
  160. case "state":
  161. this.indexState = e.detail.value;
  162. this.pickerState = this.pickerStateArray[this.indexState].label;
  163. this.typeActive = false;
  164. }
  165. /*
  166. { label: "全部", value: 1, }, { label: "线上", value: 2, }, { label: "线下", value: 3, },
  167. { label: "全部", value: 1, }, { label: "待开始",value: 2,},{label: "已开始",value: 3, }, { label: "已结束",value: 4, },
  168. "status":"活动状态 0:待开始;1:已开始; 2:已结束
  169. "type":"活动类型 1:线上;2 线下"}
  170. */
  171. let type = this.indexType;
  172. let state = this.indexState;
  173. let stateObj = {
  174. '0' : '全部',
  175. '1' : '待开始',
  176. '2' : '已开始',
  177. '3' : '已结束'
  178. }
  179. state = stateObj[state]
  180. this.activeListCopy = this.activeList.filter((item) => {
  181. return (
  182. (type == 0 || item.type == type) &&
  183. (state == '全部' || item.status == state)
  184. );
  185. });
  186. },
  187. goDeatil(id) {
  188. uni.navigateTo({
  189. url: "/pages/activity/activity_deatil?id=" + id,
  190. });
  191. },
  192. getActive() {
  193. let md5Sign = md5(
  194. "method=" +
  195. "activity" +
  196. "&timestamp=" +
  197. getApp().globalData.globalTimestamp +
  198. "&secret=" +
  199. getApp().globalData.secret
  200. );
  201. let url =
  202. getApp().globalData.shareUrl +
  203. "api/api.php" +
  204. "?method=activity&source=activity&action=list&timestamp=" +
  205. getApp().globalData.globalTimestamp +
  206. "&sign=" +
  207. md5Sign;
  208. let postData = {
  209. // page: 1,
  210. // page_size: 15,
  211. s_cancel : 0,
  212. order_by : "weight desc,id desc"
  213. };
  214. uni.request({
  215. url: url,
  216. method: "POST",
  217. header: {
  218. "content-type": "application/x-www-form-urlencoded",
  219. },
  220. data: postData,
  221. success: (res) => {
  222. // console.log(res);
  223. if (res.data.code === 200) {
  224. let list = res.data.data.list;
  225. this.activeList = list.map((item) => {
  226. /*
  227. url: "/static/activity/2.png",
  228. title: "智能制造商标品牌培育系列培训活动",
  229. way: "市场监督管理局",
  230. date: "2021-08-07",
  231. read: 322,
  232. share: 1,
  233. type: 0, //0线下
  234. */
  235. let ob = {
  236. url: "",
  237. title: "",
  238. way: "",
  239. date: "",
  240. read: 0,
  241. share: 0,
  242. type: "",
  243. status: "",
  244. id: "",
  245. status: 0,
  246. timeStatus:""
  247. };
  248. ob.url = item.pic_url ? getApp().globalData.shareUrl + item.pic_url : '/static/activity/default.png';
  249. ob.title = item.name;
  250. ob.way = item.sponsor;
  251. let timeStart = this.$options.filters["globalTime"](item.start_time) + ' ' + this.$options.filters["globalTimeSecond"](item.start_time);
  252. // let timeSecond = this.$options.filters["globalTime"](item.end_time);
  253. let timeEnd = this.$options.filters["globalTime"](item.end_time) + ' ' + this.$options.filters["globalTimeSecond"](item.end_time);
  254. ob.date = timeStart + " 至 " + timeEnd;
  255. ob.timeStatus = (timeStart.substr(5,5)).replace('-', '月');
  256. ob.read = parseInt(item.base_read_count) + parseInt(item.real_read_count);
  257. ob.share = parseInt(item.real_repost_count) + parseInt(item.base_repost_count);
  258. ob.type = item.type;
  259. ob.status = item.status;
  260. ob.id = item.id;
  261. ob.status = item.status;
  262. return ob;
  263. });
  264. this.activeListCopy = this.activeList;
  265. }
  266. },
  267. fail: () => {
  268. console.log("连接失败");
  269. },
  270. });
  271. },
  272. },
  273. };
  274. </script>
  275. <style lang="scss" scoped>
  276. .content {
  277. display: flex;
  278. flex-direction: column;
  279. align-items: center;
  280. width: 100%;
  281. .choose-box {
  282. padding: 20rpx 0;
  283. width: 100%;
  284. display: flex;
  285. // position: fixed;
  286. height: 50rpx;
  287. top: 0;
  288. // margin-bottom: 50rpx;
  289. .type,
  290. .state {
  291. width: 50%;
  292. display: flex;
  293. justify-content: center;
  294. position: relative;
  295. .packer {
  296. width: 100%;
  297. .picker_title {
  298. z-index: 99;
  299. width: 100%;
  300. height: 100%;
  301. display: flex;
  302. justify-content: center;
  303. }
  304. }
  305. }
  306. .type::after,
  307. .state::after {
  308. z-index: -1;
  309. content: "";
  310. position: absolute;
  311. right: 30%;
  312. top: 20%;
  313. width: 0;
  314. height: 0;
  315. border-top: 15rpx solid rgb(173, 173, 173);
  316. border-left: 15rpx solid transparent;
  317. border-right: 15rpx solid transparent;
  318. }
  319. }
  320. .actives {
  321. width: 90%;
  322. // margin-top: 50rpx;
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. .actives-item {
  327. width: 100%;
  328. // height: 150rpx;
  329. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  330. border-radius: 32rpx;
  331. // margin-top: 20px;
  332. padding: 20rpx;
  333. display: flex;
  334. flex-direction: column;
  335. margin-bottom: 20rpx;
  336. .active-content {
  337. display: flex;
  338. .img-box {
  339. margin-right: 20rpx;
  340. width: 120rpx;
  341. height: 120rpx;
  342. img {
  343. width: 100%;
  344. height: 100%;
  345. border-radius: 10%;
  346. }
  347. }
  348. .right {
  349. width: 80%;
  350. // height: 120rpx;
  351. box-sizing: border-box;
  352. display: flex;
  353. flex-direction: column;
  354. justify-content: space-between;
  355. .right-title {
  356. width: 100%;
  357. margin-bottom:10rpx;
  358. font-size: 32rpx;
  359. // font-weight: 600;
  360. letter-spacing: 3rpx;
  361. overflow: hidden;
  362. text-overflow: ellipsis;
  363. white-space: nowrap;
  364. }
  365. .right-inf {
  366. flex-wrap: wrap;
  367. display: flex;
  368. font-size: 26rpx;
  369. align-items: center;
  370. color: $uni-text-color-grey;
  371. .right-item{
  372. margin-bottom: 10rpx;
  373. }
  374. .inf-type {
  375. margin-right: 10rpx;
  376. display: flex;
  377. align-items: center;
  378. .originColor {
  379. margin-right: 8rpx;
  380. height: 20rpx;
  381. width: 20rpx;
  382. border-radius: 50%;
  383. background-color: #ffcf86;
  384. }
  385. }
  386. .inf-way {
  387. // margin-right: 20rpx;
  388. width: 77%;
  389. overflow: hidden;
  390. text-overflow: ellipsis;
  391. white-space: nowrap;
  392. }
  393. .inf-date {
  394. white-space: nowrap;
  395. }
  396. }
  397. }
  398. }
  399. .readShare {
  400. display: flex;
  401. justify-content: flex-end;
  402. font-size: 26rpx;
  403. color: rgba(0, 0, 0, 0.3);
  404. margin-top: 20rpx;
  405. align-items: center;
  406. .active-tips-box {
  407. font-size: 28rpx;
  408. padding: 10rpx;
  409. border-radius: 10rpx;
  410. color: #fff;
  411. margin-right: 50rpx;
  412. }
  413. .wait-color {
  414. background-color: #aee359;
  415. }
  416. .ing-color {
  417. background-color: #00a8ea;
  418. }
  419. .end-color {
  420. background-color: #d7d7d7;
  421. }
  422. .read {
  423. width: 20%;
  424. text-align: center;
  425. // margin-right: 60rpx;
  426. }
  427. .share {
  428. width: 20%;
  429. text-align: center;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. .active {
  436. color: $uni-color-primary;
  437. }
  438. .color {
  439. background-color: #589cff !important;
  440. }
  441. </style>