index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <template>
  2. <div class="cart">
  3. <Header></Header>
  4. <section class="section">
  5. <div class="container">
  6. <div class="section__header">
  7. <div class="cart-icon">
  8. <i class="img el-icon-shopping-cart-2"></i>
  9. </div>
  10. <div class="title">
  11. 我的购物车
  12. <span class="number">
  13. {{ goodsList.length ? `(${goodsList.length}) ` : "" }}
  14. </span>
  15. </div>
  16. <div class="total">
  17. <div class="total__number">
  18. 已选
  19. <span>{{ multipleSelection.length }}件</span>
  20. 商品
  21. </div>
  22. <div class="total__price">
  23. 总金额:
  24. <span>¥{{ total | toFixed }}</span>
  25. </div>
  26. </div>
  27. <div class="pay-btn" @click="pay">去支付</div>
  28. </div>
  29. <div class="section__body">
  30. <el-table
  31. ref="multipleTable"
  32. :data="goodsList"
  33. tooltip-effect="dark"
  34. style="width: 100%"
  35. @selection-change="handleSelectionChange"
  36. >
  37. <el-table-column
  38. type="selection"
  39. header-align="center"
  40. align="center"
  41. width="60"
  42. >
  43. </el-table-column>
  44. <el-table-column label="商品信息" header-align="center">
  45. <template slot-scope="scope">
  46. <div class="goods">
  47. <div class="goods__img">
  48. <img
  49. :src="$tools.splitImgHost(scope.row.coverUrl, true, 213)"
  50. alt=""
  51. />
  52. </div>
  53. <div class="goods__info">
  54. <div class="title">
  55. {{ scope.row.goodsName }}
  56. <span class="note">60学时</span>
  57. <span class="note">继续教育</span>
  58. </div>
  59. <div class="desc">
  60. 项目类型-业务层级
  61. <span class="note">
  62. 报名截止时间:{{ scope.row.date }}
  63. </span>
  64. </div>
  65. <div
  66. class="selection"
  67. v-if="
  68. scope.row.templateType == 'class' &&
  69. scope.row.goodsType == 1
  70. "
  71. >
  72. <el-select
  73. class="select"
  74. v-model="scope.row.gradeId"
  75. placeholder="请选择班级"
  76. size="small"
  77. @click.native="selectClick(scope.row, 'class')"
  78. >
  79. <el-option
  80. v-for="item in scope.row.gradeList"
  81. :key="item.gradeId"
  82. :label="item.className"
  83. :value="item.gradeId"
  84. >
  85. </el-option>
  86. </el-select>
  87. </div>
  88. <div
  89. class="selection"
  90. v-if="
  91. scope.row.templateType == 'apply' &&
  92. scope.row.goodsType == 1
  93. "
  94. >
  95. <el-select
  96. v-model="scope.row.educationId"
  97. placeholder="请选择考期"
  98. size="small"
  99. @click.native="selectClick(scope.row, 'exam')"
  100. >
  101. <el-option
  102. v-for="item in scope.row.examineList"
  103. :key="item.educationId"
  104. :label="item.examineName"
  105. :value="item.educationId"
  106. >
  107. </el-option>
  108. </el-select>
  109. <el-cascader
  110. size="small"
  111. :props="props"
  112. :ref="'cascader' + scope.$index"
  113. :options="provinceList"
  114. v-model="scope.row.area"
  115. @change="areaChange(scope.row, scope.$index)"
  116. clearable
  117. placeholder="请选择报考地区"
  118. ></el-cascader>
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. </el-table-column>
  124. <el-table-column
  125. prop="name"
  126. label="金额"
  127. header-align="center"
  128. align="center"
  129. width="120"
  130. >
  131. <template slot-scope="scope">
  132. <a class="goods_price"> ¥{{ scope.row.standPrice }} </a>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. prop="address"
  137. label="编辑"
  138. width="120"
  139. header-align="center"
  140. align="center"
  141. show-overflow-tooltip
  142. >
  143. <template slot-scope="scope">
  144. <a @click="del(scope.row)">删除</a>
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. </div>
  149. <div class="section__footer">
  150. <div class="title">
  151. <el-checkbox v-model="checked" @change="allCheckChange(checked)"
  152. >全选</el-checkbox
  153. >
  154. </div>
  155. <div class="total">
  156. <div class="total__number">
  157. 已选
  158. <span>{{ multipleSelection.length }}件</span>
  159. 商品
  160. </div>
  161. <div class="total__price">
  162. 总金额:
  163. <span>¥{{ total | toFixed }}</span>
  164. </div>
  165. </div>
  166. <div class="pay-btn" @click="pay">去支付</div>
  167. </div>
  168. </div>
  169. </section>
  170. <ToolBar></ToolBar>
  171. <Footer></Footer>
  172. </div>
  173. </template>
  174. <script>
  175. import Footer from "@/components/footer/index";
  176. import Header from "@/components/header/index";
  177. import ToolBar from "@/components/toolbar/index";
  178. import { mapMutations } from "vuex";
  179. export default {
  180. name: "login",
  181. components: {
  182. Footer,
  183. Header,
  184. ToolBar,
  185. },
  186. data() {
  187. return {
  188. checked: false,
  189. multipleSelection: [],
  190. goodsList: [],
  191. total: 0,
  192. provinceList: [],
  193. props: {
  194. lazy: true,
  195. lazyLoad: this.lazyLoad,
  196. },
  197. };
  198. },
  199. mounted() {
  200. this.getProvinceList();
  201. this.cartList();
  202. },
  203. methods: {
  204. ...mapMutations(["setCheckGoodsList"]),
  205. areaChange(row, index) {
  206. console.log(row);
  207. let node = this.$refs["cascader" + index].getCheckedNodes()[0]; //选中的根节点
  208. console.log(node);
  209. row.applyAreas = {
  210. areaName: node.parent.label,
  211. areaId: node.parent.value,
  212. cityId: node.value,
  213. cityName: node.label,
  214. };
  215. },
  216. lazyLoad(node, resolve) {
  217. const { level } = node;
  218. console.log(node);
  219. if (level == 0) {
  220. // this.$request.getProvinceList().then((res) => {
  221. // const nodes = res.rows.map((item) => ({
  222. // value: item.areaId,
  223. // label: `${item.areaName}`,
  224. // leaf: level >= 1,
  225. // }));
  226. // resolve(nodes);
  227. // });
  228. } else if (level == 1) {
  229. this.$request.getCityList({ parentId: node.value }).then((res) => {
  230. const nodes = res.rows.map((item) => ({
  231. value: item.areaId,
  232. label: `${item.areaName}`,
  233. leaf: level >= 1,
  234. }));
  235. resolve(nodes);
  236. });
  237. }
  238. },
  239. /**
  240. * 点击select获取对应列表
  241. */
  242. selectClick(row, type) {
  243. if (type == "class") {
  244. //选择班级
  245. console.log(row);
  246. if (!row.gradeList.length) {
  247. this.$request.goodsGradeList({ goodsId: row.goodsId }).then((res) => {
  248. row.gradeList = res.rows;
  249. if (row.gradeList.length == 0) {
  250. let item = {
  251. className: "系统分班",
  252. gradeId: 0,
  253. };
  254. row.gradeList.push(item);
  255. }
  256. });
  257. }
  258. } else if (type == "apply") {
  259. //选择考试地点
  260. } else if (type == "exam") {
  261. //选择考期
  262. this.$request
  263. .getExamineList({ projectId: row.projectId })
  264. .then((res) => {
  265. row.examineList = res.rows;
  266. });
  267. }
  268. },
  269. /**
  270. * 获取所有省份
  271. */
  272. getProvinceList() {
  273. this.$request.getProvinceList().then((res) => {
  274. this.provinceList = res.rows.map((item) => ({
  275. value: item.areaId,
  276. label: `${item.areaName}`,
  277. leaf: false,
  278. }));
  279. });
  280. },
  281. /**
  282. * 全选和取消全选
  283. */
  284. allCheckChange(val) {
  285. if (val) {
  286. this.goodsList.forEach((row, i) => {
  287. this.$refs.multipleTable.toggleRowSelection(row, true);
  288. });
  289. } else {
  290. this.$refs.multipleTable.clearSelection();
  291. }
  292. },
  293. /**
  294. * 获取购物车列表
  295. */
  296. cartList() {
  297. this.$request.cartList().then((res) => {
  298. res.rows.forEach((item) => {
  299. item.area = [];
  300. item.gradeId = "";
  301. item.gradeList = [];
  302. item.examDate = "";
  303. item.examineList = [];
  304. });
  305. this.goodsList = res.rows;
  306. });
  307. },
  308. toggleSelection(rows) {
  309. if (rows) {
  310. rows.forEach((row) => {
  311. this.$refs.multipleTable.toggleRowSelection(row);
  312. });
  313. } else {
  314. this.$refs.multipleTable.clearSelection();
  315. }
  316. },
  317. handleSelectionChange(val) {
  318. this.multipleSelection = val;
  319. if (
  320. this.multipleSelection.length > 0 &&
  321. this.multipleSelection.length == this.goodsList.length
  322. ) {
  323. this.checked = true;
  324. } else {
  325. this.checked = false;
  326. }
  327. this.caculate();
  328. },
  329. caculate() {
  330. this.total = 0;
  331. this.multipleSelection.forEach((item) => {
  332. this.total += item.standPrice;
  333. });
  334. },
  335. pay() {
  336. if (this.$refs.multipleTable.selection.length == 0) {
  337. this.$message({
  338. message: "请选择商品",
  339. type: "warning",
  340. });
  341. return;
  342. }
  343. for (let i = 0; i < this.$refs.multipleTable.selection.length; i++) {
  344. let item = this.$refs.multipleTable.selection[i];
  345. if (item.templateType == "class" && item.goodsType == 1) {
  346. if (!item.gradeId && item.gradeId !== 0) {
  347. this.$message({
  348. message: "请选择班级",
  349. type: "warning",
  350. });
  351. return;
  352. }
  353. }
  354. if (item.templateType == "apply" && item.goodsType == 1) {
  355. // if (!item.applyAreas.areaName) {
  356. // uni.showModal({
  357. // title: '提示',
  358. // content: '请选择报考地区',
  359. // showCancel: false
  360. // });
  361. // return false;
  362. // }
  363. if (!item.applyAreas.areaName) {
  364. this.$message({
  365. message: "请选择考期",
  366. type: "warning",
  367. });
  368. return false;
  369. }
  370. }
  371. }
  372. let selectGoodsList = JSON.parse(
  373. JSON.stringify(this.$refs.multipleTable.selection)
  374. );
  375. selectGoodsList.forEach((item) => {
  376. if (item.goodsType == 1) {
  377. if (item.templateType == "class") {
  378. let goodsInputData = {
  379. type: "class",
  380. gradeId: item.gradeId,
  381. gradeJson: JSON.stringify(
  382. item.gradeList.find((grade) => grade.gradeId == item.gradeId)
  383. ),
  384. };
  385. item.goodsInputData = goodsInputData;
  386. }
  387. if (item.templateType == "apply") {
  388. let goodsInputData = {
  389. type: "apply",
  390. applyAreasJson: JSON.stringify(item.applyAreas),
  391. examDateJson: JSON.stringify(
  392. item.examineList.find(
  393. (exam) => exam.educationId == item.educationId
  394. )
  395. ),
  396. };
  397. item.goodsInputData = goodsInputData;
  398. }
  399. }
  400. });
  401. this.setCheckGoodsList(selectGoodsList);
  402. this.$router.push({
  403. path: "/payment",
  404. });
  405. },
  406. del(row) {
  407. this.$confirm("确认删除商品?")
  408. .then((_) => {
  409. this.$request.cartDelete(row.id).then((res) => {
  410. this.$message.con;
  411. this.cartList();
  412. });
  413. })
  414. .catch((_) => {});
  415. },
  416. },
  417. };
  418. </script>
  419. <!-- Add "scoped" attribute to limit CSS to this component only -->
  420. <style scoped lang="scss">
  421. .cart {
  422. .section {
  423. &__header {
  424. height: 80px;
  425. background: #ebf3ff;
  426. display: flex;
  427. align-items: center;
  428. padding: 0 20px;
  429. .cart-icon {
  430. width: 40px;
  431. height: 40px;
  432. background: #3f8dfd;
  433. box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
  434. border-radius: 50%;
  435. text-align: center;
  436. line-height: 40px;
  437. .img {
  438. vertical-align: middle;
  439. display: inline-block;
  440. color: #fff;
  441. font-size: 24px;
  442. }
  443. }
  444. .title {
  445. font-size: 30px;
  446. font-family: Microsoft YaHei;
  447. font-weight: 400;
  448. color: #333333;
  449. flex: 1;
  450. margin-left: 20px;
  451. .number {
  452. font-size: 24px;
  453. font-family: Microsoft YaHei;
  454. font-weight: 400;
  455. color: #333333;
  456. }
  457. }
  458. .total {
  459. display: flex;
  460. &__number {
  461. span {
  462. font-size: 24px;
  463. font-family: Microsoft YaHei;
  464. font-weight: 400;
  465. color: #333333;
  466. }
  467. }
  468. &__price {
  469. margin-left: 20px;
  470. span {
  471. font-size: 24px;
  472. font-family: Microsoft YaHei;
  473. font-weight: 400;
  474. color: #ff3b30;
  475. }
  476. }
  477. }
  478. .pay-btn {
  479. cursor: pointer;
  480. width: 80px;
  481. height: 40px;
  482. background: #ff3b30;
  483. border-radius: 20px;
  484. text-align: center;
  485. line-height: 40px;
  486. color: #fff;
  487. margin-left: 20px;
  488. }
  489. }
  490. &__body {
  491. .goods {
  492. display: flex;
  493. &__img {
  494. width: 213px;
  495. height: 120px;
  496. background: #000;
  497. }
  498. &__info {
  499. margin-left: 10px;
  500. flex: 1;
  501. .title {
  502. margin-top: 10px;
  503. font-size: 16px;
  504. font-family: Microsoft YaHei;
  505. font-weight: bold;
  506. color: #333333;
  507. .note {
  508. margin-left: 10px;
  509. padding: 1px 5px;
  510. border: 1px solid #333333;
  511. border-radius: 4px;
  512. font-size: 12px;
  513. font-family: Microsoft YaHei;
  514. font-weight: 400;
  515. color: #333333;
  516. }
  517. }
  518. .desc {
  519. margin-top: 10px;
  520. font-size: 14px;
  521. font-family: Microsoft YaHei;
  522. font-weight: 400;
  523. color: #333333;
  524. .note {
  525. font-size: 14px;
  526. font-family: Microsoft YaHei;
  527. font-weight: 400;
  528. color: #999999;
  529. }
  530. }
  531. .selection {
  532. margin-top: 10px;
  533. width: 5f00px;
  534. .select {
  535. width: 400px;
  536. }
  537. }
  538. }
  539. }
  540. .goods_price {
  541. font-size: 16px;
  542. font-family: Microsoft YaHei;
  543. font-weight: bold;
  544. color: #ff3b30;
  545. }
  546. }
  547. &__footer {
  548. height: 80px;
  549. background: #ffffff;
  550. display: flex;
  551. align-items: center;
  552. padding: 0 20px;
  553. .cart-icon {
  554. width: 40px;
  555. height: 40px;
  556. background: #3f8dfd;
  557. box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
  558. border-radius: 50%;
  559. }
  560. .title {
  561. font-size: 30px;
  562. font-family: Microsoft YaHei;
  563. font-weight: 400;
  564. color: #333333;
  565. flex: 1;
  566. }
  567. .total {
  568. display: flex;
  569. &__number {
  570. span {
  571. font-size: 24px;
  572. font-family: Microsoft YaHei;
  573. font-weight: 400;
  574. color: #333333;
  575. }
  576. }
  577. &__price {
  578. margin-left: 20px;
  579. span {
  580. font-size: 24px;
  581. font-family: Microsoft YaHei;
  582. font-weight: 400;
  583. color: #ff3b30;
  584. }
  585. }
  586. }
  587. .pay-btn {
  588. cursor: pointer;
  589. width: 80px;
  590. height: 40px;
  591. background: #ff3b30;
  592. border-radius: 20px;
  593. text-align: center;
  594. line-height: 40px;
  595. color: #fff;
  596. margin-left: 20px;
  597. }
  598. }
  599. }
  600. }
  601. </style>