IndexSkuDialog.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <div class="check_sku">
  3. <el-dialog
  4. title="选择需要购买的课程"
  5. :visible.sync="skuModal"
  6. width="680px"
  7. class="appoint-modal"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. :before-close="cancel"
  11. >
  12. <div v-loading="loading" class="contents">
  13. <!-- <div v-if="Object.keys(skuItem).length" class="pop_prices">
  14. <div class="lefts">
  15. <img :src="$tools.splitImgHost(skuItem.coverUrl)" class="imgs" />
  16. </div>
  17. <div class="rights">
  18. <div class="goods_titles">{{ skuItem.goodsName }}</div>
  19. <div class="goods_price">¥{{ skuItem.standPrice }}</div>
  20. </div>
  21. </div> -->
  22. <div class="check_con">
  23. <div
  24. v-for="(item, index) in specList"
  25. :key="index"
  26. class="check_items"
  27. >
  28. <div class="grades">{{ item.name }}</div>
  29. <div class="mains" v-if="index == 0">
  30. <div class="grade_names">
  31. <div
  32. class="course_items"
  33. v-for="(child, c_index) in item.specAttrList"
  34. :key="c_index"
  35. :class="{ nactive: child.check }"
  36. @click="selectSku(child, index)"
  37. >
  38. {{ child.name }}
  39. </div>
  40. </div>
  41. </div>
  42. <div v-if="index == 1" class="check_box">
  43. <el-checkbox-group v-model="checkedCities">
  44. <el-checkbox v-for="city in cities" :label="city" :key="city">
  45. <div class="box_centen">{{ city }}<span>¥1234.88</span></div>
  46. </el-checkbox>
  47. </el-checkbox-group>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. <div slot="footer" class="dialog-footer f_c_b">
  53. <!-- <el-button
  54. type="primary"
  55. size="small"
  56. :disabled="
  57. Object.keys(skuItem).length == 0 || specList.length != isCheckSku
  58. "
  59. @click="confirms()"
  60. >确 定</el-button
  61. > -->
  62. <div class="price">
  63. <div>
  64. <span>总价:</span><span><i>¥</i>1788.88</span>
  65. </div>
  66. <p>已选择2个商品</p>
  67. </div>
  68. <el-button
  69. :disabled="
  70. Object.keys(skuItem).length == 0 || specList.length != isCheckSku
  71. "
  72. style="width: 136px"
  73. type="primary"
  74. >{{ isCarOrBuy == 1 ? "加入购物车" : "立即购买" }}</el-button
  75. >
  76. </div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. export default {
  82. name: "checkSku",
  83. props: {
  84. skuModal: {
  85. type: Boolean,
  86. default: false,
  87. },
  88. specTemplateId: {
  89. type: [String, Number],
  90. default: "",
  91. },
  92. isCarOrBuy: {
  93. type: Number,
  94. default: 1,
  95. },
  96. },
  97. data() {
  98. return {
  99. loading: false,
  100. skuItem: {},
  101. specList: [], // 规格列表
  102. checkedCities: ["上海"],
  103. cities: ["上海", "北京", "广州", "深圳"],
  104. };
  105. },
  106. watch: {
  107. skuModal(newV, oldV) {
  108. if (newV) {
  109. this.getSpecDetail();
  110. }
  111. },
  112. },
  113. computed: {
  114. isCheckSku() {
  115. let checkCout = 0;
  116. this.specList.forEach((item, index) => {
  117. if (item.specAttrList && item.specAttrList.length) {
  118. item.specAttrList.forEach((child, c_index) => {
  119. if (child.check) {
  120. checkCout++;
  121. }
  122. });
  123. }
  124. });
  125. return checkCout;
  126. },
  127. },
  128. methods: {
  129. cancel() {
  130. this.skuItem = {};
  131. this.$emit("update:skuModal", false);
  132. },
  133. getSpecDetail() {
  134. // || 35
  135. this.loading = true;
  136. this.$axios({
  137. url: `/app/common/spec/${this.specTemplateId}`,
  138. method: "get",
  139. noToken: true,
  140. })
  141. .then((res) => {
  142. this.loading = false;
  143. if (res.code == 200) {
  144. let data = res.data;
  145. if (data) {
  146. this.specList = data && (data.specList || []);
  147. this.specList.forEach((item, index) => {
  148. item.specAttrList.forEach((child, i_index) => {
  149. this.$set(
  150. this.specList[index].specAttrList[i_index],
  151. "check",
  152. false
  153. );
  154. });
  155. });
  156. }
  157. }
  158. })
  159. .catch(() => {
  160. this.loading = false;
  161. });
  162. },
  163. selectSku(item, index) {
  164. this.specList[index].specAttrList.forEach((i_item, i_index) => {
  165. if (item.specAttributeId == i_item.specAttributeId) {
  166. this.$set(this.specList[index].specAttrList[i_index], "check", true);
  167. } else {
  168. this.$set(this.specList[index].specAttrList[i_index], "check", false);
  169. }
  170. });
  171. // console.log('this.specList', this.specList, this.isCheckSku)
  172. if (this.specList.length == this.isCheckSku) {
  173. let specAttrIds = [];
  174. this.specList.forEach((item) => {
  175. let result = item.specAttrList.find((e) => e.check);
  176. if (result) {
  177. specAttrIds.push(result.specAttributeId);
  178. }
  179. });
  180. this.getGoodsInfos(specAttrIds);
  181. }
  182. },
  183. // 获取规格属性值对应的商品信息
  184. getGoodsInfos(specAttrIds) {
  185. this.loading = true;
  186. this.$axios({
  187. url: "/app/common/attr/goods",
  188. method: "get",
  189. params: {
  190. specTemplateId: this.specTemplateId,
  191. specAttrIds: specAttrIds.join(","),
  192. },
  193. noToken: true,
  194. })
  195. .then((res) => {
  196. this.loading = false;
  197. if (res.code == 200) {
  198. this.skuItem = res.data || {};
  199. } else {
  200. this.skuItem = {};
  201. this.$message.warning("商品已下架, 请重新选择");
  202. }
  203. })
  204. .catch((err) => {
  205. this.loading = false;
  206. this.skuItem = {};
  207. this.$message.warning("商品已下架, 请重新选择");
  208. });
  209. },
  210. confirms() {
  211. if (this.specList.length != this.isCheckSku) {
  212. this.$message.warning("请先选择所有的规格");
  213. return;
  214. }
  215. if (this.skuItem.goodsStatus == 0) {
  216. this.$message.warning("商品已下架, 请重新选择");
  217. return;
  218. }
  219. let sysTime = this.$tools.timest();
  220. if (
  221. sysTime <= this.skuItem.validityStartTime ||
  222. sysTime >= this.skuItem.validityEndTime
  223. ) {
  224. this.$message.warning("商品不在有效期, 请重新选择");
  225. return;
  226. }
  227. if (this.isCarOrBuy == 1) {
  228. // 加入购物车
  229. // console.log('this.skuItem.goodsId', this.skuItem.goodsId)
  230. this.$emit("toShopCart", this.skuItem.goodsId);
  231. } else {
  232. this.$emit("togoBuy", this.skuItem);
  233. }
  234. this.cancel();
  235. },
  236. },
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .appoint-modal {
  241. /deep/ {
  242. .el-dialog__header {
  243. padding: 20px 28px;
  244. border-bottom: 1px solid #d9d9d9;
  245. .el-dialog__title {
  246. color: #222222;
  247. font-size: 20px;
  248. }
  249. }
  250. .el-checkbox {
  251. width: 100%;
  252. background: #f8f8f8;
  253. margin-bottom: 16px;
  254. padding: 0 28px 0 16px;
  255. box-sizing: border-box;
  256. color: #222222;
  257. border-radius: 8px;
  258. display: flex;
  259. align-items: center;
  260. .el-checkbox__label {
  261. flex: 1;
  262. }
  263. &:nth-last-of-type(1) {
  264. margin-bottom: 0;
  265. }
  266. }
  267. .is-checked {
  268. background: #ebf2ff;
  269. }
  270. }
  271. .dialog-footer {
  272. padding: 0 8px;
  273. .price {
  274. p {
  275. font-size: 16px;
  276. color: #666666;
  277. text-align: left;
  278. }
  279. div {
  280. span {
  281. &:nth-of-type(1) {
  282. color: #222222;
  283. font-size: 16px;
  284. }
  285. &:nth-of-type(2) {
  286. i {
  287. font-size: 17px;
  288. font-style: normal;
  289. }
  290. font-weight: bold;
  291. color: #eb445a;
  292. font-size: 28px;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. .f_c_b {
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. }
  303. }
  304. .contents {
  305. width: 100%;
  306. padding: 0 8px;
  307. .check_con {
  308. width: 100%;
  309. .check_items {
  310. margin-bottom: 32px;
  311. &:nth-last-of-type(1) {
  312. margin-bottom: 10px;
  313. }
  314. }
  315. .grades {
  316. font-size: 16px;
  317. color: #606266;
  318. margin-bottom: 16px;
  319. // margin-top: 32px;
  320. }
  321. .mains {
  322. width: 100%;
  323. max-height: 200px;
  324. overflow-y: auto;
  325. }
  326. .check_box {
  327. max-height: 400px;
  328. overflow-y: auto;
  329. &::-webkit-scrollbar {
  330. display: none;
  331. }
  332. .box_centen {
  333. height: 44px;
  334. line-height: 42px;
  335. display: flex;
  336. justify-content: space-between;
  337. span {
  338. font-weight: bold;
  339. color: #eb445a;
  340. font-size: 16px;
  341. font-family: DIN Alternate-Bold, DIN Alternate;
  342. }
  343. }
  344. }
  345. .grade_names {
  346. width: 100%;
  347. display: flex;
  348. flex-wrap: wrap;
  349. }
  350. .course_items {
  351. padding: 10px 16px;
  352. border-radius: 8px;
  353. margin-right: 16px;
  354. background: #f8f8f8;
  355. font-size: 14px;
  356. font-weight: 500;
  357. color: #222222;
  358. text-align: center;
  359. cursor: pointer;
  360. &.nactive {
  361. background: #ebf2ff;
  362. color: #3f8dfd;
  363. }
  364. }
  365. }
  366. }
  367. </style>