BookCard.vue 8.3 KB

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