index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. console.log('asd',this.item.specTemplateId)
  121. // 判断有没有规格选择
  122. if (this.item.specTemplateId) {
  123. this.isCarOrBuy = 2;
  124. this.getSpecDetail();
  125. // this.skuModal = true
  126. return;
  127. }
  128. this.toPayment(this.item.goodsId);
  129. },
  130. togoBuy(goodList) {
  131. console.log();
  132. if (goodList.length == 1) {
  133. return this.toPayment(goodList[0].goodsId);
  134. }
  135. this.goPayment(goodList);
  136. },
  137. toPayment(goodsId) {
  138. this.getGoodsDetail(goodsId).then(res => {
  139. console.log(res, "res");
  140. if ((res.goodsType === 1 && res.templateType) || res.sevenYear) {
  141. this.$refs.selectClassModal.showModal(res);
  142. } else {
  143. this.goPayment(res);
  144. }
  145. if (res.goodsType === 2 || res.goodsType === 6 || res.goodsType === 8) {
  146. this.goPayment(res);
  147. }
  148. });
  149. },
  150. goPayment(data) {
  151. if (!Array.isArray(data)) {
  152. data = [data];
  153. }
  154. let selectGoodsList = JSON.parse(JSON.stringify(data));
  155. localStorage.setItem("checkGoodsList", JSON.stringify(selectGoodsList));
  156. this.$router.push({
  157. path: "/payment"
  158. });
  159. },
  160. /**
  161. * 加入购物车
  162. */
  163. addCart(item) {
  164. // 判断有没有规格选择
  165. if (this.item.specTemplateId) {
  166. this.isCarOrBuy = 1;
  167. this.getSpecDetail();
  168. return;
  169. }
  170. this.getAddCar(this.item.goodsId);
  171. },
  172. getAddCar(goodsIds) {
  173. if (!Array.isArray(goodsIds)) {
  174. goodsIds = [goodsIds];
  175. }
  176. this.$request
  177. .addCart({ goodsIds })
  178. .then(res => {
  179. if (res) {
  180. this.getCartCount();
  181. this.$message({
  182. message: "加入购物车成功",
  183. type: "success"
  184. });
  185. }
  186. })
  187. .catch(err => {
  188. if (err.code == 500) {
  189. this.$message({
  190. message: err.msg,
  191. type: "warning"
  192. });
  193. }
  194. });
  195. },
  196. getGoodsDetail(goodsId) {
  197. return new Promise(resolve => {
  198. this.$request.commonGoodsDetail(goodsId).then(res => {
  199. resolve(res.data);
  200. });
  201. });
  202. },
  203. getSpecDetail() {
  204. this.$axios({
  205. url: `/app/common/spec/${this.item.specTemplateId}`,
  206. method: "get",
  207. noToken: true
  208. })
  209. .then(res => {
  210. console.log("dawdsf",res)
  211. if (res.data) {
  212. this.skuModal = true;
  213. } else {
  214. if (this.isCarOrBuy == 1) {
  215. this.getAddCar(this.item.goodsId);
  216. } else {
  217. this.toPayment(this.item.goodsId);
  218. }
  219. }
  220. })
  221. .catch(() => {});
  222. }
  223. }
  224. };
  225. </script>
  226. <!-- Add "scoped" attribute to limit CSS to this component only -->
  227. <style scoped lang="scss">
  228. .course-item {
  229. cursor: pointer;
  230. margin: 94px 7px 0;
  231. width: 240px;
  232. height: 193px;
  233. background: #ffffff;
  234. box-shadow: 0px 3px 6px 0px rgba(213, 218, 224, 0.8);
  235. border-radius: 10px;
  236. position: relative;
  237. background: #fff;
  238. padding-top: 70px;
  239. &__img {
  240. width: 224px;
  241. height: 125px;
  242. border-radius: 10px 8px 8px 8px;
  243. background: #ffffff;
  244. position: absolute;
  245. left: 8px;
  246. top: -62px;
  247. overflow: hidden;
  248. .note {
  249. position: absolute;
  250. top: 0px;
  251. left: 0px;
  252. z-index: 2;
  253. width: 80px;
  254. height: 24px;
  255. background: #d94404;
  256. box-shadow: 0px 1px 1px 0px rgba(248, 78, 5, 0.4);
  257. border-radius: 10px 0px 20px 0px;
  258. text-align: center;
  259. line-height: 24px;
  260. color: #fff;
  261. &__yellow {
  262. background: #ffb001;
  263. }
  264. }
  265. img {
  266. width: 100%;
  267. height: 100%;
  268. }
  269. }
  270. &__title {
  271. margin: 0 8px;
  272. font-size: 14px;
  273. font-family: Microsoft YaHei;
  274. font-weight: 400;
  275. color: #333333;
  276. line-height: 24px;
  277. height: 48px;
  278. overflow: hidden;
  279. .note {
  280. display: inline-block;
  281. width: 48px;
  282. height: 20px;
  283. background: #fff8e8;
  284. border: 1px solid #ffb001;
  285. border-radius: 10px;
  286. text-align: center;
  287. color: #ffb001;
  288. line-height: 18px;
  289. font-size: 12px;
  290. }
  291. }
  292. &__desc {
  293. height: 32px;
  294. margin-left: 8px;
  295. display: flex;
  296. align-items: center;
  297. .price {
  298. font-size: 18px;
  299. font-family: Microsoft YaHei;
  300. font-weight: bold;
  301. color: #ff2d55;
  302. line-height: 32px;
  303. span {
  304. font-size: 18px;
  305. &::before {
  306. content: "¥";
  307. font-size: 14px;
  308. font-weight: bold;
  309. }
  310. }
  311. i {
  312. // font-size: 18px;
  313. font-style: normal;
  314. }
  315. }
  316. .linePrice {
  317. color: #999999;
  318. font-size: 16px;
  319. text-decoration: line-through;
  320. margin-left: 10px;
  321. }
  322. }
  323. &__btns {
  324. margin: 0 8px;
  325. display: flex;
  326. justify-content: space-between;
  327. .add {
  328. display: block;
  329. width: 108px;
  330. height: 32px;
  331. line-height: 30px;
  332. border: 1px solid #bfbfbf;
  333. background: #fff;
  334. border-radius: 8px;
  335. font-size: 16px;
  336. color: #333333;
  337. text-align: center;
  338. }
  339. .buynow {
  340. display: block;
  341. width: 108px;
  342. height: 32px;
  343. line-height: 30px;
  344. background: #3f8dfd;
  345. border-radius: 8px;
  346. font-size: 16px;
  347. color: #fff;
  348. text-align: center;
  349. transition: all 0.3s;
  350. &:hover {
  351. background: #2b6dd6;
  352. }
  353. }
  354. }
  355. }
  356. </style>