MyOrder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <div class="my-order" ref="container">
  3. <NavBar title="订单中心"></NavBar>
  4. <div class="header bg-color-red">
  5. <div class="picTxt acea-row row-between-wrapper">
  6. <div class="text">
  7. <div class="name">订单信息</div>
  8. <div>
  9. 累计订单:{{ orderData.order_count || 0 }} 总消费:¥{{
  10. orderData.sum_price || 0
  11. }}
  12. </div>
  13. </div>
  14. <div class="pictrue"><img src="@assets/images/orderTime.png" /></div>
  15. </div>
  16. </div>
  17. <div class="nav acea-row row-around">
  18. <div
  19. class="item"
  20. :class="{ on: type === 0 }"
  21. @click="$router.replace({ path: '/order/list/0' })"
  22. >
  23. <div>待付款</div>
  24. <div class="num">{{ orderData.unpaid_count || 0 }}</div>
  25. </div>
  26. <div
  27. class="item"
  28. :class="{ on: type === 1 }"
  29. @click="$router.replace({ path: '/order/list/1' })"
  30. >
  31. <div>待发货</div>
  32. <div class="num">{{ orderData.unshipped_count || 0 }}</div>
  33. </div>
  34. <div
  35. class="item"
  36. :class="{ on: type === 2 }"
  37. @click="$router.replace({ path: '/order/list/2' })"
  38. >
  39. <div>待收货</div>
  40. <div class="num">{{ orderData.received_count || 0 }}</div>
  41. </div>
  42. <div
  43. class="item"
  44. :class="{ on: type === 3 }"
  45. @click="$router.replace({ path: '/order/list/3' })"
  46. >
  47. <div>待评价</div>
  48. <div class="num">{{ orderData.evaluated_count || 0 }}</div>
  49. </div>
  50. <div
  51. class="item"
  52. :class="{ on: type === 4 }"
  53. @click="$router.replace({ path: '/order/list/4' })"
  54. >
  55. <div>已完成</div>
  56. <div class="num">{{ orderData.complete_count || 0 }}</div>
  57. </div>
  58. </div>
  59. <div class="list">
  60. <div class="item" v-for="order in orderList" :key="order.id">
  61. <div class="title acea-row row-between-wrapper">
  62. <div class="acea-row row-middle">
  63. <span
  64. class="sign cart-color acea-row row-center-wrapper"
  65. v-if="order.combination_id > 0"
  66. >拼团</span
  67. ><span
  68. class="sign cart-color acea-row row-center-wrapper"
  69. v-if="order.seckill_id > 0"
  70. >秒杀</span
  71. ><span
  72. class="sign cart-color acea-row row-center-wrapper"
  73. v-if="order.bargain_id > 0"
  74. >砍价</span
  75. >
  76. {{ order._add_time }}
  77. </div>
  78. <div class="font-color-red">{{ order._status._title }}</div>
  79. </div>
  80. <div @click="$router.push({ path: '/order/detail/' + order.order_id })">
  81. <div
  82. class="item-info acea-row row-between row-top"
  83. v-for="cart in order.cartInfo"
  84. :key="cart.id"
  85. >
  86. <div class="pictrue">
  87. <img
  88. :src="cart.productInfo.image"
  89. @click.stop="
  90. $router.push({ path: '/detail/' + cart.productInfo.id })
  91. "
  92. v-if="
  93. cart.combination_id === 0 &&
  94. cart.bargain_id === 0 &&
  95. cart.seckill_id === 0
  96. "
  97. />
  98. <img
  99. :src="cart.productInfo.image"
  100. @click.stop="
  101. $router.push({
  102. path: '/activity/group_detail/' + cart.combination_id
  103. })
  104. "
  105. v-else-if="cart.combination_id > 0"
  106. />
  107. <img
  108. :src="cart.productInfo.image"
  109. @click.stop="
  110. $router.push({
  111. path: '/activity/dargain_detail/' + cart.bargain_id
  112. })
  113. "
  114. v-else-if="cart.bargain_id > 0"
  115. />
  116. <img
  117. :src="cart.productInfo.image"
  118. @click.stop="
  119. $router.push({
  120. path: '/activity/seckill_detail/' + cart.seckill_id
  121. })
  122. "
  123. v-else-if="cart.seckill_id > 0"
  124. />
  125. </div>
  126. <div class="text acea-row row-between">
  127. <div class="name line2">
  128. {{ cart.productInfo.store_name }}
  129. </div>
  130. <div class="money">
  131. <div>
  132. ¥{{
  133. cart.productInfo.attrInfo
  134. ? cart.productInfo.attrInfo.price
  135. : cart.productInfo.price
  136. }}
  137. </div>
  138. <div>x{{ cart.cart_num }}</div>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="totalPrice">
  144. 共{{ order.cartInfo.length || 0 }}件商品,总金额
  145. <span class="money font-color-red">¥{{ order.pay_price }}</span>
  146. </div>
  147. <div class="bottom acea-row row-right row-middle">
  148. <template v-if="order._status._type === 0">
  149. <div class="bnt cancelBnt" @click="cancelOrder(order)">
  150. 取消订单
  151. </div>
  152. <div class="bnt bg-color-red" @click="paymentTap(order)">
  153. 立即付款
  154. </div>
  155. </template>
  156. <template
  157. v-if="order._status._type === 1 || order._status._type === 9"
  158. >
  159. <div
  160. class="bnt bg-color-red"
  161. @click="$router.push({ path: '/order/detail/' + order.order_id })"
  162. >
  163. 查看详情
  164. </div>
  165. </template>
  166. <template v-if="order._status._type === 2">
  167. <div
  168. class="bnt default"
  169. @click="
  170. $router.push({ path: '/order/logistics/' + order.order_id })
  171. "
  172. v-if="order.delivery_type === 'express'"
  173. >
  174. 查看物流
  175. </div>
  176. <div class="bnt bg-color-red" @click="takeOrder(order)">
  177. 确认收货
  178. </div>
  179. </template>
  180. <template v-if="order._status._type === 3">
  181. <div
  182. class="bnt default"
  183. @click="
  184. $router.push({ path: '/order/logistics/' + order.order_id })
  185. "
  186. v-if="order.delivery_type === 'express'"
  187. >
  188. 查看物流
  189. </div>
  190. <div
  191. class="bnt bg-color-red"
  192. @click="$router.push({ path: '/order/detail/' + order.order_id })"
  193. >
  194. 去评价
  195. </div>
  196. </template>
  197. <template v-if="order._status._type === 4">
  198. <div
  199. class="bnt bg-color-red"
  200. @click="$router.push({ path: '/order/detail/' + order.order_id })"
  201. >
  202. 查看订单
  203. </div>
  204. </template>
  205. </div>
  206. </div>
  207. </div>
  208. <div class="noCart" v-if="orderList.length === 0 && page > 1">
  209. <div class="pictrue"><img src="@assets/images/noOrder.png" /></div>
  210. </div>
  211. <Loading :loaded="loaded" :loading="loading"></Loading>
  212. <Payment
  213. v-model="pay"
  214. :types="payType"
  215. @checked="toPay"
  216. :balance="userInfo.now_money"
  217. ></Payment>
  218. <GeneralWindow
  219. :generalActive="generalActive"
  220. @closeGeneralWindow="closeGeneralWindow"
  221. :generalContent="generalContent"
  222. ></GeneralWindow>
  223. </div>
  224. </template>
  225. <script>
  226. import { getOrderData, getOrderList } from "@api/order";
  227. import {
  228. cancelOrderHandle,
  229. payOrderHandle,
  230. takeOrderHandle
  231. } from "@libs/order";
  232. import Loading from "@components/Loading";
  233. import Payment from "@components/Payment";
  234. import NavBar from "@components/NavBar";
  235. import { mapGetters } from "vuex";
  236. import { isWeixin } from "@utils";
  237. import GeneralWindow from "@components/GeneralWindow";
  238. const STATUS = [
  239. "待付款",
  240. "待发货",
  241. "待收货",
  242. "待评价",
  243. "已完成",
  244. "",
  245. "",
  246. "",
  247. "",
  248. "待付款"
  249. ];
  250. const NAME = "MyOrder";
  251. export default {
  252. name: NAME,
  253. data() {
  254. return {
  255. offlinePayStatus: 2,
  256. orderData: {},
  257. type: parseInt(this.$route.params.type) || 0,
  258. page: 1,
  259. limit: 20,
  260. loaded: false,
  261. loading: false,
  262. orderList: [],
  263. pay: false,
  264. payType: ["yue", "weixin"],
  265. from: isWeixin() ? "weixin" : "weixinh5",
  266. generalActive: false,
  267. generalContent: {
  268. promoterNum: "",
  269. title: ""
  270. }
  271. };
  272. },
  273. components: {
  274. Loading,
  275. Payment,
  276. GeneralWindow,
  277. NavBar
  278. },
  279. computed: mapGetters(["userInfo"]),
  280. watch: {
  281. $route(n) {
  282. if (n.name === NAME) {
  283. const type = parseInt(this.$route.params.type) || 0;
  284. if (this.type !== type) {
  285. this.changeType(type);
  286. }
  287. this.getOrderData();
  288. }
  289. }
  290. },
  291. methods: {
  292. setOfflinePayStatus: function(status) {
  293. var that = this;
  294. that.offlinePayStatus = status;
  295. if (status === 1) {
  296. if (that.payType.indexOf("offline") < 0) {
  297. that.payType.push("offline");
  298. }
  299. }
  300. },
  301. getOrderData() {
  302. getOrderData().then(res => {
  303. this.orderData = res.data;
  304. });
  305. },
  306. takeOrder(order) {
  307. this.$dialog.loading.open("正在加载中");
  308. takeOrderHandle(order.order_id)
  309. .then(res => {
  310. if (
  311. (res.data.gain_integral != "0.00" &&
  312. res.data.gain_coupon != "0.00") ||
  313. (res.data.gain_integral > 0 && res.data.gain_coupon > 0)
  314. ) {
  315. this.$dialog.loading.close();
  316. this.generalActive = true;
  317. this.generalContent = {
  318. promoterNum: `恭喜您获得${res.data.gain_coupon}元优惠券以及${
  319. res.data.gain_integral
  320. }积分,购买商品时可抵现哦~`,
  321. title: "恭喜您获得优惠礼包"
  322. };
  323. return;
  324. } else if (
  325. res.data.gain_integral != "0.00" ||
  326. res.data.gain_integral > 0
  327. ) {
  328. this.$dialog.loading.close();
  329. this.generalActive = true;
  330. this.generalContent = {
  331. promoterNum: `恭喜您获得${
  332. res.data.gain_integral
  333. }积分,购买商品时可抵现哦~`,
  334. title: "赠送积分"
  335. };
  336. return;
  337. } else if (
  338. res.data.gain_coupon != "0.00" ||
  339. res.data.gain_coupon > 0
  340. ) {
  341. this.$dialog.loading.close();
  342. this.generalActive = true;
  343. this.generalContent = {
  344. promoterNum: `恭喜您获得${
  345. res.data.gain_coupon
  346. }元优惠券,购买商品时可抵现哦~`,
  347. title: "恭喜您获得优惠券"
  348. };
  349. return;
  350. } else {
  351. this.$dialog.loading.close();
  352. this.$dialog.success("收货成功");
  353. }
  354. this.getOrderData();
  355. this.orderList = [];
  356. this.page = 1;
  357. this.loaded = false;
  358. this.loading = false;
  359. this.getOrderList();
  360. })
  361. .catch(err => {
  362. this.$dialog.loading.close();
  363. this.$dialog.error(err.msg);
  364. });
  365. },
  366. closeGeneralWindow(msg) {
  367. this.generalActive = msg;
  368. this.reload();
  369. this.getOrderData();
  370. },
  371. reload() {
  372. this.changeType(this.type);
  373. },
  374. changeType(type) {
  375. this.type = type;
  376. this.orderList = [];
  377. this.page = 1;
  378. this.loaded = false;
  379. this.loading = false;
  380. this.getOrderList();
  381. },
  382. getOrderList() {
  383. if (this.loading || this.loaded) return;
  384. this.loading = true;
  385. const { page, limit, type } = this;
  386. getOrderList({
  387. page,
  388. limit,
  389. type
  390. }).then(res => {
  391. this.orderList = this.orderList.concat(res.data);
  392. this.page++;
  393. this.loaded = res.data.length < this.limit;
  394. this.loading = false;
  395. });
  396. },
  397. getStatus(order) {
  398. return STATUS[order._status._type];
  399. },
  400. cancelOrder(order) {
  401. cancelOrderHandle(order.order_id)
  402. .then(() => {
  403. this.orderList.splice(this.orderList.indexOf(order), 1);
  404. })
  405. .catch(() => {
  406. this.reload();
  407. });
  408. },
  409. paymentTap: function(order) {
  410. var that = this;
  411. if (
  412. !(
  413. order.combination_id > 0 ||
  414. order.bargain_id > 0 ||
  415. order.seckill_id > 0
  416. )
  417. ) {
  418. that.setOfflinePayStatus(order.offlinePayStatus);
  419. }
  420. this.pay = true;
  421. this.toPay = type => {
  422. payOrderHandle(order.order_id, type, that.from)
  423. .then(() => {
  424. const type = parseInt(this.$route.params.type) || 0;
  425. that.changeType(type);
  426. that.getOrderData();
  427. })
  428. .catch(() => {
  429. const type = parseInt(that.$route.params.type) || 0;
  430. that.changeType(type);
  431. that.getOrderData();
  432. });
  433. };
  434. },
  435. toPay() {}
  436. },
  437. mounted() {
  438. this.getOrderData();
  439. this.getOrderList();
  440. this.$scroll(this.$refs.container, () => {
  441. !this.loading && this.getOrderList();
  442. });
  443. }
  444. };
  445. </script>
  446. <style scoped>
  447. .noCart {
  448. margin-top: 0.17rem;
  449. padding-top: 0.1rem;
  450. }
  451. .noCart .pictrue {
  452. width: 4rem;
  453. height: 3rem;
  454. margin: 0.7rem auto 0.5rem auto;
  455. }
  456. .noCart .pictrue img {
  457. width: 100%;
  458. height: 100%;
  459. }
  460. </style>