index.vue 17 KB

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