index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <template>
  2. <div class="bookShelf">
  3. <Header
  4. :headerBg="'#00ADEF'"
  5. :headerBorder="'#5C5C5C'"
  6. :userBg="'rgba(0, 0, 0, 0.24)'"
  7. :LoginNavIndex="0"
  8. />
  9. <ul class="option">
  10. <li
  11. class="option-item"
  12. :class="[typeIndex === indexo ? 'active' : '']"
  13. v-for="(itemo, indexo) in optionList"
  14. :key="indexo"
  15. @click="handleClick(itemo, indexo)"
  16. >
  17. <svg-icon :icon-class="itemo.img" className="icon-img"></svg-icon>
  18. <span>{{ itemo.label }}</span>
  19. <b>{{
  20. itemo.value === 3 ? itemo.number + orderPeruseNumber : itemo.number
  21. }}</b>
  22. </li>
  23. </ul>
  24. <div class="main">
  25. <template v-if="userMessage">
  26. <div class="searchChangebox">
  27. <div class="searchChange-box">
  28. <div
  29. class="searchChange"
  30. :class="[item.sortName == sortField ? 'active' : '']"
  31. v-for="(item, indexC) in changeList"
  32. :key="indexC"
  33. >
  34. <span>
  35. {{ item.name }}
  36. </span>
  37. <div :class="['sort']">
  38. <div>
  39. <svg-icon
  40. icon-class="up"
  41. className="icon-up"
  42. :class="[item.sort == 'up' ? 'active' : '']"
  43. @click="SortEvent('up', item.name, item.sortName)"
  44. ></svg-icon>
  45. </div>
  46. <div>
  47. <svg-icon
  48. icon-class="down"
  49. className="icon-down"
  50. :class="[item.sort == 'down' ? 'active' : '']"
  51. @click="SortEvent('down', item.name, item.sortName)"
  52. ></svg-icon>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <el-input
  58. placeholder="输入名称"
  59. v-model="searchNameValue"
  60. class="input-search"
  61. maxlength="20"
  62. >
  63. <el-button
  64. slot="append"
  65. icon="el-icon-search"
  66. @click="getSearch"
  67. ></el-button>
  68. </el-input>
  69. </div>
  70. <h5 class="show-title" v-if="typeIndex !== 0">
  71. {{ optionList[typeIndex].label
  72. }}<b>{{
  73. optionList[typeIndex].value === 3
  74. ? optionList[typeIndex].number + orderPeruseNumber
  75. : optionList[typeIndex].number
  76. }}</b>
  77. </h5>
  78. <div class="list" v-if="BookList.length > 0">
  79. <!-- v-infinite-scroll="load" -->
  80. <div
  81. v-for="(item, index) in BookList"
  82. :key="index + 'todayNew'"
  83. v-infinite-scroll="load"
  84. infinite-scroll-disabled="disabled"
  85. :class="[item.type === 3 ? 'book-item-peruse' : '']"
  86. >
  87. <template v-if="item.type === 3">
  88. <BookPeruseCard
  89. :item="item"
  90. type="bookShelf"
  91. :headerBg="'#00ADEF'"
  92. :headerBorder="'#5C5C5C'"
  93. :userBg="'rgba(0, 0, 0, 0.24)'"
  94. :LoginNavIndex="0"
  95. :previousPage="'书架'"
  96. />
  97. </template>
  98. <template v-if="item.type === 30">
  99. <BookPeruseListCard
  100. :item="item"
  101. type="bookShelf"
  102. :headerBg="'#00ADEF'"
  103. :headerBorder="'#5C5C5C'"
  104. :userBg="'rgba(0, 0, 0, 0.24)'"
  105. :LoginNavIndex="0"
  106. :previousPage="'书架'"
  107. />
  108. </template>
  109. <template v-else>
  110. <BookCard
  111. :item="item"
  112. type="bookShelf"
  113. :headerBg="'#00ADEF'"
  114. :headerBorder="'#5C5C5C'"
  115. :userBg="'rgba(0, 0, 0, 0.24)'"
  116. :LoginNavIndex="0"
  117. :previousPage="'书架'"
  118. :cardType="item.course_type"
  119. />
  120. </template>
  121. </div>
  122. <p v-if="loading" class="tips">加载中...</p>
  123. <p v-if="noMore" class="tips">没有更多了</p>
  124. </div>
  125. <div class="nodata" v-else>
  126. <img src="../../assets/nodata.png" />
  127. <p>找不到文件</p>
  128. </div>
  129. </template>
  130. <template v-else>
  131. <p class="login-no">
  132. 您还未登录,请先<a
  133. @click="
  134. loginFlag = true;
  135. toUrl = '/bookShelf';
  136. "
  137. >登录</a
  138. >
  139. </p>
  140. </template>
  141. </div>
  142. <el-dialog
  143. :visible.sync="loginFlag"
  144. :show-close="false"
  145. :close-on-click-modal="false"
  146. :modal-append-to-body="false"
  147. width="504px"
  148. class="login-dialog"
  149. v-if="loginFlag"
  150. >
  151. <login @cancelLogin="cancelLogin" :toUrl="toUrl" linkType="url"></login>
  152. </el-dialog>
  153. </div>
  154. </template>
  155. <script>
  156. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  157. //例如:import 《组件名称》from ‘《组件路径》';
  158. import Header from "../../components/Header.vue";
  159. import BookCard from "@/components/common/BookCard.vue";
  160. import BookPeruseCard from "@/components/common/BookPeruseCard.vue";
  161. import BookPeruseListCard from "@/components/common/BookPeruseListCard.vue";
  162. import { getLogin } from "@/api/ajax";
  163. import { getToken } from "@/utils/auth";
  164. import Login from "@/views/login.vue";
  165. export default {
  166. //import引入的组件需要注入到对象中才能使用
  167. components: { Header, BookCard, BookPeruseCard, BookPeruseListCard, Login },
  168. props: {},
  169. data() {
  170. //这里存放数据
  171. return {
  172. BookList: [
  173. {
  174. skeleton: true,
  175. },
  176. {
  177. skeleton: true,
  178. },
  179. {
  180. skeleton: true,
  181. },
  182. {
  183. skeleton: true,
  184. },
  185. {
  186. skeleton: true,
  187. },
  188. ],
  189. optionList: [
  190. {
  191. label: "全部",
  192. img: "quanbu",
  193. number: 0,
  194. value: -1,
  195. },
  196. {
  197. label: "画刊",
  198. img: "huakan",
  199. number: 0,
  200. value: 4,
  201. },
  202. {
  203. label: "报纸",
  204. img: "baozhi",
  205. number: 0,
  206. value: 2,
  207. },
  208. {
  209. label: "练习册",
  210. img: "xiti",
  211. number: 0,
  212. },
  213. {
  214. label: "课程",
  215. img: "kecheng",
  216. number: 0,
  217. value: 10,
  218. },
  219. {
  220. label: "精读",
  221. img: "jingdu",
  222. number: 0,
  223. value: 3,
  224. },
  225. {
  226. label: "专辑",
  227. img: "zhuanji",
  228. number: 0,
  229. value: 20,
  230. },
  231. // ,
  232. // {
  233. // label: '合刊',
  234. // img: 'hekan',
  235. // number: '6'
  236. // }
  237. ],
  238. typeValue: -1,
  239. changeList: [
  240. {
  241. name: "按购买时间",
  242. sort: "down",
  243. sortName: "buy_time",
  244. },
  245. {
  246. name: "按名称",
  247. sort: "",
  248. sortName: "name",
  249. },
  250. {
  251. name: "最近使用",
  252. sort: "",
  253. sortName: "last_use_time",
  254. },
  255. ],
  256. sortField: "",
  257. searchNameValue: "", // 搜索名称值
  258. loading: false,
  259. noMore: false,
  260. pageNumber: 1,
  261. pageSize: 30,
  262. typeIndex: 0,
  263. orderPeruseNumber: 0, // 精读订阅个数
  264. userMessage: getToken() ? JSON.parse(getToken()) : null,
  265. loginFlag: false,
  266. toUrl: "",
  267. };
  268. },
  269. //计算属性 类似于data概念
  270. computed: {
  271. disabled() {
  272. return this.loading || this.noMore;
  273. },
  274. },
  275. //监控data中数据变化
  276. watch: {},
  277. //方法集合
  278. methods: {
  279. handleClick(item, index) {
  280. this.typeIndex = index;
  281. this.pageNumber = 1;
  282. if (item.hasOwnProperty("value")) {
  283. this.typeValue = item.value;
  284. if (item.number > 0 || item.value === 3) {
  285. this.BookList = [
  286. {
  287. skeleton: true,
  288. },
  289. {
  290. skeleton: true,
  291. },
  292. {
  293. skeleton: true,
  294. },
  295. {
  296. skeleton: true,
  297. },
  298. {
  299. skeleton: true,
  300. },
  301. ];
  302. this.getList();
  303. } else {
  304. this.BookList = [];
  305. }
  306. } else {
  307. this.BookList = [];
  308. }
  309. $(".list").animate(
  310. {
  311. scrollTop: 0,
  312. },
  313. 200
  314. );
  315. },
  316. // 搜索查询
  317. getSearch() {
  318. this.pageNumber = 1;
  319. this.BookList = [
  320. {
  321. skeleton: true,
  322. },
  323. {
  324. skeleton: true,
  325. },
  326. {
  327. skeleton: true,
  328. },
  329. {
  330. skeleton: true,
  331. },
  332. {
  333. skeleton: true,
  334. },
  335. ];
  336. $(".list").animate(
  337. {
  338. scrollTop: 0,
  339. },
  340. 200
  341. );
  342. this.getList();
  343. },
  344. SortEvent(type, name, sortName) {
  345. let sort = "";
  346. this.changeList.forEach((item) => {
  347. if (item.name == name) {
  348. // if (!item.sort || item.sort == "up") {
  349. // item.sort = "down";
  350. // sort = "down";
  351. // } else if (item.sort == "down") {
  352. // item.sort = "up";
  353. // sort = "up";
  354. // }
  355. item.sort = type;
  356. sort = type;
  357. } else {
  358. item.sort = "";
  359. }
  360. });
  361. if (sort == "down") {
  362. this.sortType = 1;
  363. } else {
  364. this.sortType = 0;
  365. }
  366. this.sortField = sortName;
  367. $(".list").animate(
  368. {
  369. scrollTop: 0,
  370. },
  371. 200
  372. );
  373. this.pageNumber = 1;
  374. this.getList();
  375. },
  376. // 查询列表
  377. getList() {
  378. this.loading = true;
  379. let MethodName = "/ShopServer/Client/BookshelfQuery/PageQueryMyGoodsList";
  380. let order_column_list = [];
  381. if (this.sortField !== "") {
  382. if (this.sortType === 1) {
  383. order_column_list = [this.sortField + ":desc"];
  384. } else if (this.sortType === 0) {
  385. // 升序不传值
  386. order_column_list = [this.sortField];
  387. }
  388. }
  389. let data = {
  390. goods_name: this.searchNameValue.trim(),
  391. goods_type: this.typeValue,
  392. page_capacity: this.pageSize,
  393. cur_page: this.pageNumber,
  394. order_column_list: order_column_list,
  395. };
  396. getLogin(MethodName, data)
  397. .then((res) => {
  398. this.loading = false;
  399. if (res.status === 1) {
  400. if (this.pageNumber === 1) {
  401. if (this.typeValue === -1 || this.typeValue === 3) {
  402. getLogin(
  403. "/ShopServer/Client/BookshelfQuery/GetMyValidPeriodList_Iread",
  404. {}
  405. ).then((ress) => {
  406. if (ress.status === 1) {
  407. this.orderPeruseNumber = ress.valid_period_list.length;
  408. ress.valid_period_list.forEach((items) => {
  409. items.type = 30;
  410. });
  411. this.BookList = ress.valid_period_list.concat(
  412. res.goods_list
  413. );
  414. } else {
  415. this.BookList = res.goods_list;
  416. }
  417. });
  418. } else {
  419. this.BookList = res.goods_list;
  420. }
  421. this.noMore = false;
  422. } else {
  423. this.BookList = this.BookList.concat(res.goods_list);
  424. }
  425. if (res.total_page <= this.pageNumber) {
  426. this.noMore = true;
  427. }
  428. }
  429. })
  430. .catch(() => {
  431. this.loading = false;
  432. });
  433. },
  434. load() {
  435. if (this.userMessage) {
  436. this.pageNumber++;
  437. this.getList();
  438. }
  439. },
  440. // 获取商品个数
  441. getNumber() {
  442. let MethodName = "/ShopServer/Client/BookshelfQuery/GetMyGoodsCount";
  443. getLogin(MethodName, {})
  444. .then((res) => {
  445. if (res.status === 1) {
  446. this.optionList = [
  447. {
  448. label: "全部",
  449. img: "quanbu",
  450. number: res.count_all,
  451. value: -1,
  452. },
  453. {
  454. label: "画刊",
  455. img: "huakan",
  456. number: res.count_pictorial,
  457. value: 4,
  458. },
  459. {
  460. label: "报纸",
  461. img: "baozhi",
  462. number: res.count_issue,
  463. value: 2,
  464. },
  465. {
  466. label: "练习册",
  467. img: "xiti",
  468. number: 0,
  469. },
  470. {
  471. label: "课程",
  472. img: "kecheng",
  473. number: res.count_course,
  474. value: 10,
  475. },
  476. {
  477. label: "精读课堂",
  478. img: "jingdu",
  479. number: res.count_iread,
  480. value: 3,
  481. },
  482. {
  483. label: "专辑",
  484. img: "zhuanji",
  485. number: res.count_album,
  486. value: 20,
  487. },
  488. // ,
  489. // {
  490. // label: '合刊',
  491. // img: 'hekan',
  492. // number: '6'
  493. // }
  494. ];
  495. }
  496. })
  497. .catch(() => {
  498. this.loading = false;
  499. });
  500. },
  501. // 关闭登录弹窗
  502. cancelLogin() {
  503. this.loginFlag = false;
  504. },
  505. },
  506. //生命周期 - 创建完成(可以访问当前this实例)
  507. created() {
  508. if (this.userMessage) {
  509. this.getNumber();
  510. this.getList();
  511. }
  512. },
  513. //生命周期 - 挂载完成(可以访问DOM元素)
  514. mounted() {
  515. if (this.userMessage) {
  516. let _this = this;
  517. let input = document.querySelector("input");
  518. input.addEventListener("keyup", function (event) {
  519. // 判断是否按下回车键
  520. if (event.keyCode === 13) {
  521. // 回车键被按下,执行你想要的操作
  522. _this.getList(1);
  523. }
  524. });
  525. }
  526. },
  527. //生命周期-创建之前
  528. beforeCreated() {},
  529. //生命周期-挂载之前
  530. beforeMount() {},
  531. //生命周期-更新之前
  532. beforUpdate() {},
  533. //生命周期-更新之后
  534. updated() {},
  535. //生命周期-销毁之前
  536. beforeDestory() {},
  537. //生命周期-销毁完成
  538. destoryed() {},
  539. //如果页面有keep-alive缓存功能,这个函数会触发
  540. activated() {},
  541. };
  542. </script>
  543. <style lang="scss" scoped>
  544. /* @import url(); 引入css类 */
  545. .bookShelf {
  546. background: #f7f8fa;
  547. height: calc(100vh - 64px);
  548. .option {
  549. list-style: none;
  550. display: flex;
  551. justify-content: center;
  552. margin: 0;
  553. padding: 0;
  554. background: #00adef;
  555. li {
  556. display: flex;
  557. align-items: center;
  558. border-radius: 30px;
  559. height: 36px;
  560. padding: 7px 20px;
  561. margin: 8px 4px;
  562. cursor: pointer;
  563. &:hover {
  564. background: rgba(255, 255, 255, 0.08);
  565. }
  566. &.active {
  567. background: rgba(255, 255, 255, 0.08);
  568. .icon-img,
  569. span,
  570. b {
  571. color: rgba(255, 255, 255, 0.9);
  572. }
  573. }
  574. .icon-img {
  575. width: 14px;
  576. height: 14px;
  577. margin: 1px 8px 0 0;
  578. color: rgba(255, 255, 255, 0.5);
  579. }
  580. span {
  581. color: rgba(255, 255, 255, 0.5);
  582. font-size: 14px;
  583. line-height: 22px;
  584. }
  585. b {
  586. font-weight: 400;
  587. font-size: 14px;
  588. line-height: 22px;
  589. color: rgba(255, 255, 255, 0.5);
  590. margin-left: 5px;
  591. }
  592. }
  593. }
  594. .main {
  595. width: 1200px;
  596. margin: 0 auto;
  597. padding: 24px 0 0 0;
  598. .searchChangebox {
  599. display: flex;
  600. justify-content: space-between;
  601. .searchChange-box {
  602. display: flex;
  603. }
  604. .searchChange {
  605. display: flex;
  606. align-items: center;
  607. justify-content: space-between;
  608. padding: 4px 12px;
  609. height: 32px;
  610. margin-right: 16px;
  611. border: 1px solid #e5e6eb;
  612. border-radius: 20px;
  613. &.active {
  614. background: #175dff;
  615. > span {
  616. color: #ffffff;
  617. }
  618. .sort {
  619. > div {
  620. svg {
  621. color: #5e89ef;
  622. &.active {
  623. color: #ffffff;
  624. }
  625. }
  626. }
  627. }
  628. }
  629. > span {
  630. font-weight: 400;
  631. font-size: 16px;
  632. line-height: 22px;
  633. color: #000;
  634. margin-right: 4px;
  635. }
  636. .sort {
  637. cursor: pointer;
  638. height: 20px;
  639. > div {
  640. font-size: 0;
  641. svg {
  642. width: 11px;
  643. height: 11px;
  644. color: #c2c2c2;
  645. padding: 3px 2px 2px 2px;
  646. &.icon-down {
  647. height: 9px;
  648. padding: 0 2px 2px 2px;
  649. }
  650. }
  651. }
  652. }
  653. }
  654. .input-search {
  655. width: 220px;
  656. }
  657. }
  658. .show-title {
  659. color: #1f2c5c;
  660. margin: 24px 0 0 0;
  661. font-weight: 500;
  662. font-size: 24px;
  663. line-height: 32px;
  664. b {
  665. margin-left: 16px;
  666. color: #ed5f00;
  667. }
  668. }
  669. .list {
  670. margin: 28px -25px 0 -25px;
  671. display: flex;
  672. flex-wrap: wrap;
  673. height: calc(100vh - 256px);
  674. overflow-y: scroll;
  675. &::-webkit-scrollbar {
  676. display: none;
  677. }
  678. > div {
  679. width: 200px;
  680. height: 352px;
  681. border-radius: 8px;
  682. overflow: hidden;
  683. background: #ffffff;
  684. margin: 0 25px 24px 25px;
  685. &.book-item-peruse {
  686. width: 200px;
  687. height: 298px;
  688. margin-top: 54px;
  689. }
  690. }
  691. .tips {
  692. width: 100%;
  693. text-align: center;
  694. font-size: 12px;
  695. color: #929ca8;
  696. }
  697. }
  698. }
  699. }
  700. </style>
  701. <style lang="scss">
  702. .bookShelf {
  703. .searchChangebox {
  704. .input-search {
  705. .el-input__inner {
  706. height: 32px;
  707. color: #1d2129;
  708. background: #f2f3f5;
  709. border: none;
  710. line-height: 32px;
  711. }
  712. .el-input-group__append {
  713. border: none;
  714. width: 32px;
  715. height: 32px;
  716. background: #165dff;
  717. text-align: center;
  718. cursor: pointer;
  719. &:hover {
  720. background: #4080ff;
  721. }
  722. &:focus {
  723. background: #0e42d2;
  724. }
  725. }
  726. .el-button {
  727. padding: 10px 12px;
  728. color: #ffffff;
  729. }
  730. }
  731. }
  732. }
  733. .login-no {
  734. text-align: center;
  735. line-height: 500px;
  736. a {
  737. color: #00adef;
  738. }
  739. }
  740. </style>