index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div>
  3. <div class="course-item" @click="goodsDetail(item)">
  4. <div class="course-item__img">
  5. <!-- <div
  6. class="note"
  7. :class="{ note__yellow: item.goodsType == 6 }"
  8. v-if="item.year"
  9. >
  10. {{ item.year }}
  11. </div> -->
  12. <img
  13. v-if="item.coverUrl"
  14. :src="$tools.splitImgHost(item.coverUrl)"
  15. alt=""
  16. />
  17. </div>
  18. <div class="course-item__title">
  19. <span v-if="item.goodsType == 6" class="note">直播</span>
  20. {{ item.goodsName }}
  21. </div>
  22. <div class="course-item__desc">
  23. <div
  24. class="price"
  25. v-if="!item.specTemplateId || (!item.maxPrice && !item.minPrice)"
  26. >
  27. <strong v-if="item.standPrice === 0">
  28. 免费
  29. </strong>
  30. <span v-else>
  31. {{ item.standPrice | formatPrice }}
  32. </span>
  33. </div>
  34. <div v-else class="price">
  35. <span>{{ item.minPrice | formatPrice }}</span>
  36. <template v-if="item.minPrice != item.maxPrice">
  37. <i>-</i>
  38. <span>{{ item.maxPrice | formatPrice }}</span>
  39. </template>
  40. </div>
  41. <div v-if="item.linePrice" class="linePrice">
  42. ¥{{ item.linePrice | formatPrice }}
  43. </div>
  44. </div>
  45. <div class="course-item__btns">
  46. <a class="add" @click.stop="addCart(item)">加购物车</a>
  47. <a class="buynow" @click.stop="buyNow(item)">立即购买</a>
  48. </div>
  49. </div>
  50. <BuyCourseModal ref="selectClassModal"></BuyCourseModal>
  51. <index-sku-dialog
  52. :skuModal.sync="skuModal"
  53. :specTemplateId="item.specTemplateId"
  54. :isCarOrBuy="isCarOrBuy"
  55. @toShopCart="getAddCar($event)"
  56. @togoBuy="togoBuy($event)"
  57. ></index-sku-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. import { mapGetters, mapMutations } from "vuex";
  62. import BuyCourseModal from "@/components/buyCourseModal/index";
  63. import IndexSkuDialog from "./IndexSkuDialog.vue";
  64. export default {
  65. name: "courseItem",
  66. components: {
  67. BuyCourseModal,
  68. IndexSkuDialog
  69. },
  70. computed: {
  71. ...mapGetters(["userInfo"])
  72. },
  73. props: ["item"],
  74. data() {
  75. return {
  76. selectClassModal: false,
  77. skuModal: false,
  78. isCarOrBuy: 1 // 1加入购物车 2立即购买
  79. };
  80. },
  81. mounted() {},
  82. methods: {
  83. ...mapMutations(["setCurrentRouter", "getCartCount"]),
  84. /**
  85. * 查看商品详情
  86. */
  87. goodsDetail(item) {
  88. console.log(item, "items");
  89. this.getGoodsDetail(item.goodsId).then(res => {
  90. if (res.goodsType === 1) {
  91. this.$router.push({
  92. path: "/course-detail/" + res.goodsId
  93. });
  94. }
  95. if (res.goodsType === 2) {
  96. this.$router.push({
  97. path: "/bank-detail/" + res.goodsId
  98. });
  99. }
  100. if (res.goodsType === 6) {
  101. this.$router.push({
  102. path: "/live-detail/" + res.goodsId
  103. });
  104. }
  105. if (res.goodsType === 8) {
  106. this.$router.push({
  107. path: "/handout-detail/" + res.goodsId
  108. });
  109. }
  110. });
  111. },
  112. buyNow(item) {
  113. if (!this.$tools.isLogin()) {
  114. this.setCurrentRouter(this.$route);
  115. this.$router.push({
  116. path: "/login"
  117. });
  118. return;
  119. }
  120. // 判断有没有规格选择
  121. if (this.item.specTemplateId) {
  122. this.isCarOrBuy = 2;
  123. this.getSpecDetail();
  124. // this.skuModal = true
  125. return;
  126. }
  127. this.toPayment(this.item.goodsId);
  128. },
  129. togoBuy(goodList) {
  130. console.log();
  131. if (goodList.length == 1) {
  132. return this.toPayment(goodList[0].goodsId);
  133. }
  134. this.goPayment(goodList);
  135. },
  136. toPayment(goodsId) {
  137. this.getGoodsDetail(goodsId).then(res => {
  138. console.log(res, "res");
  139. if ((res.goodsType === 1 && res.templateType) || res.sevenYear) {
  140. this.$refs.selectClassModal.showModal(res);
  141. } else {
  142. this.goPayment(res);
  143. }
  144. if (res.goodsType === 2 || res.goodsType === 6 || res.goodsType === 8) {
  145. this.goPayment(res);
  146. }
  147. });
  148. },
  149. goPayment(data) {
  150. if (!Array.isArray(data)) {
  151. data = [data];
  152. }
  153. let selectGoodsList = JSON.parse(JSON.stringify(data));
  154. localStorage.setItem("checkGoodsList", JSON.stringify(selectGoodsList));
  155. this.$router.push({
  156. path: "/payment"
  157. });
  158. },
  159. /**
  160. * 加入购物车
  161. */
  162. addCart(item) {
  163. // 判断有没有规格选择
  164. if (this.item.specTemplateId) {
  165. this.isCarOrBuy = 1;
  166. this.getSpecDetail();
  167. return;
  168. }
  169. this.getAddCar(this.item.goodsId);
  170. },
  171. getAddCar(goodsIds) {
  172. if (!Array.isArray(goodsIds)) {
  173. goodsIds = [goodsIds];
  174. }
  175. this.$request
  176. .addCart({ goodsIds })
  177. .then(res => {
  178. if (res) {
  179. this.getCartCount();
  180. this.$message({
  181. message: "加入购物车成功",
  182. type: "success"
  183. });
  184. }
  185. })
  186. .catch(err => {
  187. if (err.code == 500) {
  188. this.$message({
  189. message: err.msg,
  190. type: "warning"
  191. });
  192. }
  193. });
  194. },
  195. getGoodsDetail(goodsId) {
  196. return new Promise(resolve => {
  197. this.$request.commonGoodsDetail(goodsId).then(res => {
  198. resolve(res.data);
  199. });
  200. });
  201. },
  202. getSpecDetail() {
  203. this.$axios({
  204. url: `/app/common/spec/${this.item.specTemplateId}`,
  205. method: "get",
  206. noToken: true
  207. })
  208. .then(res => {
  209. if (res.data) {
  210. this.skuModal = true;
  211. } else {
  212. if (this.isCarOrBuy == 1) {
  213. this.getAddCar(this.item.goodsId);
  214. } else {
  215. this.toPayment(this.item.goodsId);
  216. }
  217. }
  218. })
  219. .catch(() => {});
  220. }
  221. }
  222. };
  223. </script>
  224. <!-- Add "scoped" attribute to limit CSS to this component only -->
  225. <style scoped lang="scss">
  226. .course-item {
  227. cursor: pointer;
  228. margin: 94px 7px 0;
  229. width: 240px;
  230. height: 193px;
  231. background: #ffffff;
  232. box-shadow: 0px 3px 6px 0px rgba(213, 218, 224, 0.8);
  233. border-radius: 10px;
  234. position: relative;
  235. background: #fff;
  236. padding-top: 70px;
  237. &__img {
  238. width: 224px;
  239. height: 125px;
  240. border-radius: 10px 8px 8px 8px;
  241. background: #ffffff;
  242. position: absolute;
  243. left: 8px;
  244. top: -62px;
  245. overflow: hidden;
  246. .note {
  247. position: absolute;
  248. top: 0px;
  249. left: 0px;
  250. z-index: 2;
  251. width: 80px;
  252. height: 24px;
  253. background: #d94404;
  254. box-shadow: 0px 1px 1px 0px rgba(248, 78, 5, 0.4);
  255. border-radius: 10px 0px 20px 0px;
  256. text-align: center;
  257. line-height: 24px;
  258. color: #fff;
  259. &__yellow {
  260. background: #ffb001;
  261. }
  262. }
  263. img {
  264. width: 100%;
  265. height: 100%;
  266. }
  267. }
  268. &__title {
  269. margin: 0 8px;
  270. font-size: 14px;
  271. font-family: Microsoft YaHei;
  272. font-weight: 400;
  273. color: #333333;
  274. line-height: 24px;
  275. height: 48px;
  276. overflow: hidden;
  277. .note {
  278. display: inline-block;
  279. width: 48px;
  280. height: 20px;
  281. background: #fff8e8;
  282. border: 1px solid #ffb001;
  283. border-radius: 10px;
  284. text-align: center;
  285. color: #ffb001;
  286. line-height: 18px;
  287. font-size: 12px;
  288. }
  289. }
  290. &__desc {
  291. height: 32px;
  292. margin-left: 8px;
  293. display: flex;
  294. align-items: center;
  295. .price {
  296. font-size: 18px;
  297. font-family: Microsoft YaHei;
  298. font-weight: bold;
  299. color: #ff2d55;
  300. line-height: 32px;
  301. span {
  302. font-size: 18px;
  303. &::before {
  304. content: "¥";
  305. font-size: 14px;
  306. font-weight: bold;
  307. }
  308. }
  309. i {
  310. // font-size: 18px;
  311. font-style: normal;
  312. }
  313. }
  314. .linePrice {
  315. color: #999999;
  316. font-size: 16px;
  317. text-decoration: line-through;
  318. margin-left: 10px;
  319. }
  320. }
  321. &__btns {
  322. margin: 0 8px;
  323. display: flex;
  324. justify-content: space-between;
  325. .add {
  326. display: block;
  327. width: 108px;
  328. height: 32px;
  329. line-height: 30px;
  330. border: 1px solid #bfbfbf;
  331. background: #fff;
  332. border-radius: 8px;
  333. font-size: 16px;
  334. color: #333333;
  335. text-align: center;
  336. }
  337. .buynow {
  338. display: block;
  339. width: 108px;
  340. height: 32px;
  341. line-height: 30px;
  342. background: #3f8dfd;
  343. border-radius: 8px;
  344. font-size: 16px;
  345. color: #fff;
  346. text-align: center;
  347. transition: all 0.3s;
  348. &:hover {
  349. background: #2b6dd6;
  350. }
  351. }
  352. }
  353. }
  354. </style>