index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <template>
  2. <div class="my-order">
  3. <div class="my-order__header">
  4. <el-tabs :value="activeName" @tab-click="tabChange">
  5. <el-tab-pane
  6. v-for="(tab, tabIndex) in list"
  7. :key="tabIndex"
  8. :label="tab.count ? `${tab.label}(${tab.count})` : `${tab.label}`"
  9. :name="tab.name"
  10. ></el-tab-pane>
  11. </el-tabs>
  12. </div>
  13. <div class="my-order__body">
  14. <div class="list" v-if="orderList.length == 0">
  15. <div class="no-data">您暂无相关订单哦~</div>
  16. </div>
  17. <div class="list" v-else>
  18. <template v-if="activeName == '2' && orderList.length">
  19. <el-button
  20. type="primary"
  21. class="invoice"
  22. @click="go('/person-center/my-invoice')"
  23. >发票申请</el-button
  24. >
  25. </template>
  26. <div class="order-item" v-for="(item, index) in orderList" :key="index">
  27. <div class="order-item__header">
  28. <div class="state">
  29. 订单号:
  30. <div class="note">{{ item.orderSn }}</div>
  31. </div>
  32. <div class="time">
  33. {{ $tools.timestampToTime(item.createTime) }}
  34. </div>
  35. </div>
  36. <div class="order-item__body clearfix">
  37. <template v-if="activeName != '4'">
  38. <div class="order-item__body__goodslist">
  39. <div
  40. class="goods-item clearfix"
  41. v-for="(items, itemIndex) in item.orderGoodsList"
  42. :key="itemIndex"
  43. >
  44. <div class="img">
  45. <img
  46. :src="$tools.splitImgHost(items.coverUrl, true)"
  47. alt=""
  48. />
  49. </div>
  50. <div class="text">
  51. <div class="title">{{ items.goodsName }}</div>
  52. <div class="desc">
  53. 应付金额:
  54. <span class="note">¥{{ items.goodsRealPrice }}</span>
  55. </div>
  56. </div>
  57. <div
  58. class="btn btn--nobg"
  59. @click="refund(item.orderSn, items.goodsId)"
  60. v-if="
  61. items.refundStatus === 0 &&
  62. (item.orderFrom === 2 || item.orderFrom === 3) &&
  63. (item.orderStatus === 1 ||
  64. item.orderStatus === 2 ||
  65. item.orderStatus === 3) &&
  66. (items.goodsType == '1' || items.goodsType == '2')
  67. "
  68. >
  69. 申请退款
  70. </div>
  71. <div class="state" v-if="items.refundStatus == 2">已退款</div>
  72. </div>
  73. </div>
  74. <div class="price-wrap">
  75. <div class="btns">
  76. <div class="price-text">实付金额</div>
  77. <div class="price-number">¥{{ item.payPrice }}</div>
  78. </div>
  79. </div>
  80. <div
  81. class="btns-wrap"
  82. v-if="
  83. (item.orderStatus === 0 &&
  84. (item.orderFrom === 2 || item.orderFrom === 3)) ||
  85. ((item.orderStatus === -1 || item.orderStatus === -2) &&
  86. (item.orderFrom === 2 || item.orderFrom === 3))
  87. "
  88. >
  89. <div class="btns">
  90. <el-button
  91. type="primary"
  92. class="btn"
  93. v-if="
  94. item.orderStatus === 0 &&
  95. (item.orderFrom === 2 || item.orderFrom === 3)
  96. "
  97. @click="pay(item)"
  98. >
  99. 立即支付
  100. </el-button>
  101. <div
  102. class="btn btn--nobg"
  103. v-if="
  104. item.orderStatus === 0 &&
  105. (item.orderFrom === 2 || item.orderFrom === 3)
  106. "
  107. @click="cancelOrder(item)"
  108. >
  109. 取消订单
  110. </div>
  111. <div
  112. class="btn btn--nobg"
  113. v-if="
  114. (item.orderStatus === -1 || item.orderStatus === -2) &&
  115. (item.orderFrom === 2 || item.orderFrom === 3)
  116. "
  117. @click="delOrder(item)"
  118. >
  119. 删除订单
  120. </div>
  121. <!-- <div class="btn btn--warm">开始学习</div> -->
  122. </div>
  123. </div>
  124. </template>
  125. <template v-else>
  126. <div class="order-item__body__goodslist">
  127. <div class="goods-item clearfix">
  128. <div class="img">
  129. <img
  130. :src="$tools.splitImgHost(item.coverUrl, true)"
  131. alt=""
  132. />
  133. </div>
  134. <div class="text">
  135. <div class="title">{{ item.goodsName }}</div>
  136. <div class="desc">
  137. <!-- 应付金额:
  138. <span class="note">¥99.99</span> -->
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="refund-wrap">
  144. <div class="btns">
  145. <div class="price-text">已退款</div>
  146. <div class="price-number">¥{{ item.refundFee }}</div>
  147. </div>
  148. </div>
  149. </template>
  150. </div>
  151. </div>
  152. <div class="pagination">
  153. <el-pagination
  154. @current-change="currentChange"
  155. background
  156. layout="prev, pager, next"
  157. :total="total"
  158. :pager-count="5"
  159. :page-size="formData.pageSize"
  160. >
  161. </el-pagination>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </template>
  167. <script>
  168. import { mapMutations } from "vuex";
  169. export default {
  170. name: "MyOrder",
  171. data() {
  172. return {
  173. orderList: [],
  174. activeName: "1",
  175. formData: {
  176. status: "0,1",
  177. pageNum: 1,
  178. pageSize: 10,
  179. },
  180. total: 0,
  181. loading: null,
  182. list: [
  183. {
  184. label: "待支付",
  185. count: 0,
  186. name: "1",
  187. },
  188. {
  189. label: "已支付",
  190. count: 0,
  191. name: "2",
  192. },
  193. {
  194. label: "已取消",
  195. count: 0,
  196. name: "3",
  197. },
  198. {
  199. label: "已退款",
  200. count: 0,
  201. name: "4",
  202. },
  203. ],
  204. };
  205. },
  206. mounted() {
  207. if (this.$route.query.state) {
  208. this.activeName = this.$route.query.state;
  209. }
  210. this.getOrderNum();
  211. this.getOrderList();
  212. },
  213. methods: {
  214. ...mapMutations(["setCheckGoodsList"]),
  215. getOrderNum() {
  216. this.$request
  217. .getorderlists({
  218. status: "0,1",
  219. pageNum: 1,
  220. pageSize: 1,
  221. orderStatus: "0",
  222. })
  223. .then((res) => {
  224. this.list[0].count = res.total;
  225. });
  226. this.$request
  227. .getorderlists({
  228. status: "0,1",
  229. pageNum: 1,
  230. pageSize: 1,
  231. orderStatus: "1,2,3,4",
  232. })
  233. .then((res) => {
  234. this.list[1].count = res.total;
  235. });
  236. this.$request
  237. .getorderlists({
  238. status: "0,1",
  239. pageNum: 1,
  240. pageSize: 1,
  241. orderStatus: "-1,-2",
  242. })
  243. .then((res) => {
  244. this.list[2].count = res.total;
  245. });
  246. this.$request
  247. .orderRefundList({
  248. pageNum: 1,
  249. pageSize: 1,
  250. })
  251. .then((res) => {
  252. this.list[3].count = res.total;
  253. })
  254. .catch(this.hideLoading);
  255. },
  256. currentChange(e) {
  257. this.formData.pageNum = e;
  258. if (this.activeName == "4") {
  259. //退款订单
  260. this.formData.status = "";
  261. this.orderRefundList();
  262. } else {
  263. //其他订单
  264. this.formData.status = "0,1";
  265. this.getOrderList();
  266. }
  267. },
  268. tabChange(e) {
  269. if (this.activeName == e.name) {
  270. return;
  271. }
  272. this.formData.pageNum = 1;
  273. this.activeName = e.name;
  274. if (this.activeName == "4") {
  275. //退款订单
  276. this.formData.status = "";
  277. this.formData.pageNum = 1;
  278. this.orderRefundList();
  279. } else {
  280. //其他订单
  281. this.formData.status = "0,1";
  282. this.getOrderList();
  283. }
  284. },
  285. pay(item) {
  286. this.setCheckGoodsList([]);
  287. this.$router.push({
  288. path: "/payment",
  289. name: "支付",
  290. params: {
  291. total: item.payPrice,
  292. orderSn: item.orderSn,
  293. },
  294. });
  295. },
  296. refund(orderSn, goodsId) {
  297. this.$confirm("确定要退款吗?", "提示", {
  298. confirmButtonText: "确认",
  299. cancelButtonText: "取消",
  300. closeOnClickModal: false,
  301. closeOnPressEscape: false,
  302. distinguishCancelAndClose: false,
  303. showClose: false,
  304. })
  305. .then((_) => {
  306. this.showLoading();
  307. this.$request
  308. .refundSmallOrder({ orderSn: orderSn, goodsId: goodsId })
  309. .then((res) => {
  310. this.hideLoading();
  311. this.$message({
  312. type: "success",
  313. message: "退款成功",
  314. });
  315. this.getOrderNum();
  316. this.getOrderList();
  317. })
  318. .catch((err) => {
  319. this.hideLoading();
  320. this.$message({
  321. type: "warning",
  322. message: "不可以退款哦",
  323. });
  324. });
  325. })
  326. .catch((err) => {});
  327. },
  328. delOrder(item) {
  329. this.$confirm("确定要删除该订单吗?", "提示", {
  330. confirmButtonText: "确认",
  331. cancelButtonText: "取消",
  332. closeOnClickModal: false,
  333. closeOnPressEscape: false,
  334. distinguishCancelAndClose: false,
  335. showClose: false,
  336. })
  337. .then((_) => {
  338. this.showLoading();
  339. this.$request
  340. .eddOrder({ orderId: item.orderId, status: -1 })
  341. .then((res) => {
  342. this.$message({
  343. type: "success",
  344. message: "订单删除成功",
  345. });
  346. this.hideLoading();
  347. this.getOrderNum();
  348. this.getOrderList();
  349. })
  350. .catch((err) => {
  351. this.hideLoading();
  352. this.$message({
  353. type: "warning",
  354. message: err.msg,
  355. });
  356. });
  357. })
  358. .catch((err) => {
  359. this.hideLoading();
  360. });
  361. },
  362. orderRefundList() {
  363. this.showLoading();
  364. this.formData.orderStatus = "";
  365. this.$request
  366. .orderRefundList(this.formData)
  367. .then((res) => {
  368. this.hideLoading();
  369. this.orderList = res.rows;
  370. this.total = res.total;
  371. })
  372. .catch(this.hideLoading);
  373. },
  374. /**
  375. * 取消订单
  376. */
  377. cancelOrder(item) {
  378. this.$confirm("确定要取消该订单吗?", "提示", {
  379. confirmButtonText: "确认",
  380. cancelButtonText: "取消",
  381. closeOnClickModal: false,
  382. closeOnPressEscape: false,
  383. distinguishCancelAndClose: false,
  384. showClose: false,
  385. })
  386. .then((_) => {
  387. this.showLoading();
  388. this.$request
  389. .eddOrder({ orderId: item.orderId, orderStatus: -1 })
  390. .then((res) => {
  391. this.hideLoading();
  392. this.getOrderNum();
  393. this.$message({
  394. type: "success",
  395. message: "订单取消成功",
  396. });
  397. this.getOrderList();
  398. })
  399. .catch((err) => {
  400. this.hideLoading();
  401. this.$message({
  402. type: "warning",
  403. message: err.msg,
  404. });
  405. });
  406. })
  407. .catch((_) => {});
  408. },
  409. showLoading(obj) {
  410. this.loading = this.$loading({
  411. lock: true,
  412. text: (obj && obj.text) || "loading",
  413. spinner: "el-icon-loading",
  414. background: "rgba(0, 0, 0, 0)",
  415. target: document.querySelector(".my-order__body"),
  416. });
  417. },
  418. hideLoading() {
  419. this.loading.close();
  420. },
  421. //获取订单
  422. getOrderList() {
  423. this.showLoading();
  424. if (this.activeName == "1") {
  425. this.formData.orderStatus = "0";
  426. }
  427. if (this.activeName == "2") {
  428. this.formData.orderStatus = "1,2,3,4";
  429. }
  430. if (this.activeName == "3") {
  431. this.formData.orderStatus = "-1,-2";
  432. }
  433. this.$request
  434. .getorderlists(this.formData)
  435. .then((res) => {
  436. this.orderList = res.rows;
  437. this.total = res.total;
  438. this.hideLoading();
  439. })
  440. .catch(this.hideLoading);
  441. },
  442. },
  443. };
  444. </script>
  445. <!-- Add "scoped" attribute to limit CSS to this component only -->
  446. <style scoped lang="scss">
  447. .my-order {
  448. &__header {
  449. /deep/ .el-tabs__header {
  450. margin-bottom: 0;
  451. }
  452. /deep/ .el-tabs__item {
  453. padding: 0 30px !important;
  454. }
  455. }
  456. &__body {
  457. .invoice {
  458. margin-top: 10px;
  459. }
  460. .list {
  461. .order-item {
  462. margin-top: 24px;
  463. background: #fafbfc;
  464. border: 1px solid #eeeeee;
  465. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  466. border-radius: 8px;
  467. overflow: hidden;
  468. &__header {
  469. height: 40px;
  470. border-bottom: 1px solid #eee;
  471. padding: 0 18px;
  472. .state {
  473. margin-top: 8px;
  474. float: left;
  475. font-size: 14px;
  476. font-family: Microsoft YaHei;
  477. font-weight: 400;
  478. color: #666666;
  479. .note {
  480. vertical-align: middle;
  481. display: inline-block;
  482. font-size: 14px;
  483. font-family: Microsoft YaHei;
  484. font-weight: 400;
  485. color: #3f8dfd;
  486. line-height: 24px;
  487. }
  488. }
  489. .time {
  490. float: right;
  491. line-height: 40px;
  492. text-align: right;
  493. font-size: 12px;
  494. font-family: Microsoft YaHei;
  495. font-weight: 400;
  496. color: #666666;
  497. }
  498. }
  499. &__body {
  500. display: flex;
  501. &__goodslist {
  502. flex: 1;
  503. .goods-item {
  504. margin-bottom: 20px;
  505. border-top: 1px solid #eee;
  506. border-bottom: 1px solid #eee;
  507. &:nth-last-of-type(1) {
  508. margin: 0;
  509. border-bottom: 0;
  510. }
  511. &:nth-of-type(1) {
  512. border-top: 0;
  513. }
  514. .img {
  515. float: left;
  516. width: 160px;
  517. height: 90px;
  518. display: table-cell;
  519. img {
  520. max-width: 100%;
  521. max-height: 100%;
  522. display: inline-block;
  523. vertical-align: middle;
  524. }
  525. }
  526. .text {
  527. float: left;
  528. margin-left: 12px;
  529. .title {
  530. margin-top: 10px;
  531. font-size: 16px;
  532. font-family: Microsoft YaHei;
  533. font-weight: bold;
  534. color: #333333;
  535. }
  536. .desc {
  537. margin-top: 30px;
  538. font-size: 14px;
  539. .note {
  540. color: #ff3b30;
  541. }
  542. }
  543. }
  544. .state {
  545. font-size: 14px;
  546. margin: 30px 0 0 0;
  547. float: right;
  548. width: 122px;
  549. height: 32px;
  550. line-height: 32px;
  551. text-align: center;
  552. }
  553. .btn {
  554. float: right;
  555. cursor: pointer;
  556. margin: 30px 0 0 0;
  557. width: 122px;
  558. height: 32px;
  559. font-size: 14px;
  560. background: #3f8dfd;
  561. border-radius: 16px;
  562. text-align: center;
  563. line-height: 32px;
  564. color: #fff;
  565. &--warm {
  566. background: #ff3b30;
  567. }
  568. &--nobg {
  569. background: none;
  570. color: #333;
  571. }
  572. }
  573. }
  574. }
  575. .refund-wrap {
  576. width: 320px;
  577. display: table;
  578. border-left: 1px solid #eee;
  579. .btns {
  580. display: table-cell;
  581. vertical-align: middle;
  582. text-align: center;
  583. .price-text {
  584. margin: 2px 0;
  585. width: 100%;
  586. height: 32px;
  587. font-size: 14px;
  588. display: inline-block;
  589. text-align: center;
  590. line-height: 32px;
  591. color: #333333;
  592. }
  593. .price-number {
  594. margin: 2px 0;
  595. width: 100%;
  596. height: 32px;
  597. font-weight: bold;
  598. display: inline-block;
  599. text-align: center;
  600. line-height: 32px;
  601. font-size: 16px;
  602. color: #333333;
  603. }
  604. }
  605. }
  606. .price-wrap {
  607. display: table;
  608. width: 160px;
  609. border-left: 1px solid #eee;
  610. .btns {
  611. display: table-cell;
  612. vertical-align: middle;
  613. text-align: center;
  614. .price-text {
  615. margin: 2px 0;
  616. width: 150px;
  617. height: 32px;
  618. font-size: 14px;
  619. display: inline-block;
  620. text-align: center;
  621. line-height: 32px;
  622. color: #333333;
  623. }
  624. .price-number {
  625. font-weight: bold;
  626. margin: 2px 0;
  627. width: 150px;
  628. height: 32px;
  629. font-size: 14px;
  630. display: inline-block;
  631. text-align: center;
  632. line-height: 32px;
  633. color: #ff3b30;
  634. }
  635. }
  636. }
  637. .btns-wrap {
  638. display: table;
  639. width: 160px;
  640. border-left: 1px solid #eee;
  641. .btns {
  642. display: table-cell;
  643. vertical-align: middle;
  644. text-align: center;
  645. .btn {
  646. cursor: pointer;
  647. margin: 2px 0;
  648. width: 122px;
  649. height: 32px;
  650. font-size: 14px;
  651. padding: 0;
  652. border-radius: 16px;
  653. display: inline-block;
  654. text-align: center;
  655. line-height: 32px;
  656. color: #fff;
  657. &--warm {
  658. background: #ff3b30;
  659. }
  660. &--nobg {
  661. background: none;
  662. color: #333;
  663. }
  664. }
  665. }
  666. }
  667. }
  668. }
  669. }
  670. .no-data {
  671. text-align: center;
  672. padding: 50px 0;
  673. color: #666;
  674. font-size: 16px;
  675. }
  676. .pagination {
  677. padding: 30px 0;
  678. text-align: center;
  679. }
  680. }
  681. }
  682. </style>