BookCard.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <div>
  3. <el-skeleton
  4. style="width: 240px"
  5. :loading="true"
  6. animated
  7. v-if="item.skeleton"
  8. >
  9. <template slot="template">
  10. <el-skeleton-item variant="image" style="width: 200px; height: 280px" />
  11. <div style="padding: 12px; width: 200px">
  12. <el-skeleton-item variant="h3" style="width: 100%; height: 22px" />
  13. <el-skeleton-item
  14. variant="text"
  15. style="margin: 4px 0 12px 0; height: 16px; width: 50%"
  16. />
  17. <el-skeleton-item
  18. variant="text"
  19. style="height: 21px; width: 70%"
  20. v-if="!type || type != 'bookShelf'"
  21. />
  22. </div>
  23. </template>
  24. </el-skeleton>
  25. <div
  26. class="BookCard"
  27. :class="[item.isYD ? 'BookCard-no' : '']"
  28. @click="handleLink"
  29. v-else
  30. >
  31. <!-- <div
  32. class="image"
  33. :style="{height:height?height:'280px'}"
  34. ></div> -->
  35. <span class="isNew" v-if="item.is_new && item.is_new === 'true'"
  36. >NEW</span
  37. >
  38. <span
  39. class="isReservation"
  40. v-if="item.is_reservation && item.is_reservation === 'true'"
  41. >订阅</span
  42. >
  43. <el-image
  44. class="image"
  45. :src="
  46. item.cover_image_url
  47. ? item.cover_image_url
  48. : item.course_type === 'baozhi' ||
  49. (goodsTypeList[item.type] &&
  50. goodsTypeList[item.type].type === 'baozhi')
  51. ? item.study_phase
  52. ? item.study_phase === 11
  53. ? require('../../assets/baozhi3.png')
  54. : item.study_phase === 20 ||
  55. item.study_phase === 21 ||
  56. item.study_phase === 22 ||
  57. item.study_phase === 23
  58. ? require('../../assets/baozhi1.png')
  59. : item.study_phase === 30 ||
  60. item.study_phase === 31 ||
  61. item.study_phase === 32 ||
  62. item.study_phase === 33
  63. ? require('../../assets/baozhi2.png')
  64. : require('../../assets/baozhi' +
  65. (Math.floor(Math.random() * 2) + 1) +
  66. '.png')
  67. : require('../../assets/baozhi' +
  68. (Math.floor(Math.random() * 2) + 1) +
  69. '.png')
  70. : require('../../assets/kecheng' +
  71. (Math.floor(Math.random() * 3) + 1) +
  72. '.png')
  73. "
  74. :fit="'cover'"
  75. >
  76. </el-image>
  77. <div class="bottom">
  78. <template v-if="item.isYD">
  79. <p class="name">
  80. 二十一世纪学生英文报·{{ item.study_phase_name }}第{{
  81. item.iss_no
  82. }}期{{ item.school_year_no ? "(" + item.school_year_no + ")" : "" }}
  83. </p>
  84. <p class="author">
  85. {{ item.shelve_date || "暂无" }}
  86. </p>
  87. </template>
  88. <template v-else>
  89. <p class="name">
  90. {{ item.name
  91. }}{{ item.school_year_no ? "(" + item.school_year_no + ")" : "" }}
  92. </p>
  93. <!-- <template>
  94. <el-rate
  95. v-model="item.score"
  96. disabled
  97. show-score
  98. :colors="colors"
  99. :score-template="score"
  100. >
  101. </el-rate>
  102. </template> -->
  103. <p class="author">
  104. {{
  105. item.shelve_date ||
  106. item.typeName ||
  107. item.classperiod ||
  108. item.author ||
  109. "暂无"
  110. }}
  111. </p>
  112. </template>
  113. <template v-if="!type || type != 'bookShelf'">
  114. <p class="price">
  115. <span class="OPPOSans"
  116. >¥{{
  117. item.hasOwnProperty("price_discount")
  118. ? item.price_discount
  119. : item.price | cutMoneyFiter
  120. }}</span
  121. >
  122. <s
  123. v-if="
  124. item.hasOwnProperty('price_discount') &&
  125. item.price_discount !== item.price
  126. "
  127. >¥{{ item.price | cutMoneyFiter }}</s
  128. >
  129. </p>
  130. </template>
  131. </div>
  132. </div>
  133. </div>
  134. </template>
  135. <script>
  136. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  137. //例如:import 《组件名称》from ‘《组件路径》';
  138. import { cutMoneyFiter } from "@/utils/defined";
  139. import { getLogin } from "@/api/ajax";
  140. import { getToken } from "@/utils/auth";
  141. export default {
  142. name: "BookCard",
  143. //import引入的组件需要注入到对象中才能使用
  144. components: {},
  145. props: [
  146. "item",
  147. "height",
  148. "type",
  149. "LoginNavIndex",
  150. "userBg",
  151. "headerBorder",
  152. "headerBg",
  153. "previousPage",
  154. "isBuy",
  155. ],
  156. filters: {
  157. cutMoneyFiter,
  158. },
  159. data() {
  160. //这里存放数据
  161. return {
  162. goodsTypeList: {
  163. 0: {
  164. type: "LB",
  165. },
  166. 2: {
  167. type: "baozhi",
  168. },
  169. 3: {
  170. type: "jingdu",
  171. },
  172. 4: {
  173. type: "huakan",
  174. },
  175. 20: {
  176. type: "zhuanji",
  177. },
  178. },
  179. userMessage: getToken() ? JSON.parse(getToken()) : null,
  180. };
  181. },
  182. //计算属性 类似于data概念
  183. computed: {
  184. score() {
  185. return this.item.score.toFixed(1);
  186. },
  187. },
  188. //监控data中数据变化
  189. watch: {},
  190. //方法集合
  191. methods: {
  192. changeData(data) {
  193. var datasort = data.sort((a, b) => a.date.localeCompare(b.date));
  194. var timeArr = new Set(datasort.map((it) => it.date));
  195. let newarr = [];
  196. let rateArr = [];
  197. timeArr.forEach((item) => {
  198. let a = {
  199. date: "",
  200. arr: [],
  201. };
  202. data.forEach((items) => {
  203. if (item == items.date) {
  204. a.date = items.date;
  205. a.arr.push(items.weight);
  206. rateArr.push(items.rate);
  207. }
  208. });
  209. newarr.push(a);
  210. });
  211. newarr.forEach((item) => {
  212. if (item.arr.length < 3) {
  213. for (let i = 0; i < 3 - (item.arr.length - 1); i++) {
  214. item.arr.push(0);
  215. }
  216. }
  217. });
  218. return { newarr, timeArr, rateArr };
  219. },
  220. async handleLink() {
  221. if (this.item.isYD) return;
  222. let url = this.LoginNavIndex + "&&&1&&&2&&&3&&&" + this.previousPage;
  223. if (this.LoginNavIndex === 0 && this.userMessage) {
  224. let MethodName = "/ShopServer/Client/BookshelfQuery/SetMyGoodsIsLooked";
  225. let data = {
  226. goods_id: this.item.id,
  227. goods_type: this.item.type,
  228. };
  229. await getLogin(MethodName, data)
  230. .then((res) => {
  231. if (res.status === 1) {
  232. }
  233. })
  234. .catch(() => {});
  235. }
  236. if (this.item.type === 3 && this.userMessage) {
  237. this.$router.push({
  238. path: "/bookPeruseItem",
  239. query: {
  240. headerConfig: encodeURIComponent(url),
  241. cardType: "jingdu",
  242. id: this.item.goods_id,
  243. },
  244. });
  245. } else {
  246. this.$router.push({
  247. path: "/bookItem",
  248. query: {
  249. headerConfig: encodeURIComponent(url),
  250. isBuy: this.isBuy,
  251. cardType:
  252. this.item.course_type || this.goodsTypeList[this.item.type].type,
  253. id: this.item.goods_id || this.item.id,
  254. },
  255. });
  256. }
  257. },
  258. },
  259. //生命周期 - 创建完成(可以访问当前this实例)
  260. created() {
  261. // let data = this.changeData(this.dataContext)
  262. },
  263. //生命周期 - 挂载完成(可以访问DOM元素)
  264. mounted() {},
  265. //生命周期-创建之前
  266. beforeCreated() {},
  267. //生命周期-挂载之前
  268. beforeMount() {},
  269. //生命周期-更新之前
  270. beforUpdate() {},
  271. //生命周期-更新之后
  272. updated() {},
  273. //生命周期-销毁之前
  274. beforeDestory() {},
  275. //生命周期-销毁完成
  276. destoryed() {},
  277. //如果页面有keep-alive缓存功能,这个函数会触发
  278. activated() {},
  279. };
  280. </script>
  281. <style lang="scss" scoped>
  282. /* @import url(); 引入css类 */
  283. .BookCard {
  284. width: 100%;
  285. cursor: pointer;
  286. position: relative;
  287. .image {
  288. width: 100%;
  289. height: 280px;
  290. }
  291. &-no {
  292. cursor: initial;
  293. .image {
  294. opacity: 0.8;
  295. }
  296. }
  297. .bottom {
  298. // height: 132px;
  299. padding: 4px 12px 12px;
  300. }
  301. p {
  302. margin: 0;
  303. padding: 0;
  304. }
  305. .name {
  306. width: 100%;
  307. font-weight: 400;
  308. font-size: 14px;
  309. line-height: 22px;
  310. color: #2f3742;
  311. height: 44px;
  312. word-break: break-word;
  313. text-overflow: ellipsis;
  314. display: -webkit-box;
  315. -webkit-box-orient: vertical;
  316. -webkit-line-clamp: 2; /* 超出几行省略 */
  317. overflow: hidden;
  318. }
  319. .author {
  320. margin-top: 1px;
  321. font-weight: 400;
  322. font-size: 12px;
  323. line-height: 20px;
  324. color: #929ca8;
  325. }
  326. .price {
  327. margin-top: 1px;
  328. display: flex;
  329. align-items: flex-end;
  330. :nth-child(1) {
  331. font-weight: 700;
  332. font-size: 14px;
  333. line-height: 22px;
  334. color: #ec5e41;
  335. }
  336. :nth-child(2) {
  337. font-weight: 400;
  338. font-size: 12px;
  339. line-height: 20px;
  340. text-decoration-line: line-through;
  341. color: #929ca8;
  342. margin-left: 8px;
  343. }
  344. }
  345. }
  346. </style>