shizhongqi 4 лет назад
Родитель
Сommit
6b5b9078bb
2 измененных файлов с 69 добавлено и 2 удалено
  1. 5 0
      ghsApp/src/api/order/index.js
  2. 64 2
      ghsApp/src/pagesOrder/detail.vue

+ 5 - 0
ghsApp/src/api/order/index.js

@@ -48,6 +48,11 @@ export const updateOrder = data => {
 	return https.post("/order/update-order", data);
 };
 
+//取消订单
+export const cancelOrder = data => {
+	return https.post("/order/cancel-order", data)
+}
+
 /** *
  * 商城下单-相关信息 m
  */

+ 64 - 2
ghsApp/src/pagesOrder/detail.vue

@@ -222,6 +222,9 @@
 
 		</view>
 		<div class="app-footer">
+			<button @click="cancelOrderFn(detailInfo.cgInfo.id)" v-if="showCancelBtn && showCancelOrder(detailInfo.cgInfo)" class="admin-button-com default" :class="active">
+				取消订单
+			</button>
 			<template v-for="s in detailInfo.buttonList">
 				<button :key="s.type" @click="clickBtn(s, detailInfo)" v-if="s.show == 1" :disabled="s.disable === 1" class="admin-button-com default" :class="s.disable === 1?'active':''">
 					{{ s.type === "print" ? s.name+`(${detailInfo.printNum})` : s.name}}
@@ -251,7 +254,7 @@ import { clearOrderApi } from "@/api/arrears/index";
 import productMins from "@/mixins/product";
 import { ORDER_STATUS } from "@/utils/declare";
 import BLE from "@/mixins/BLE";
-import { cloudPrintOrder } from "@/api/order";
+import { cloudPrintOrder, cancelOrder } from "@/api/order";
 import { hasHitNavigate } from "@/api/map";
 export default {
 	name: "orderDetail",
@@ -274,7 +277,8 @@ export default {
 			detailInfo: {},
 			freeShipModal: false,
 			loading: false,
-			settlePrice:0
+			settlePrice:0,
+			showCancelBtn: true
 		};
 	},
   onPullDownRefresh() {
@@ -337,6 +341,64 @@ export default {
 		modalCancel() {
 			this.freeShipModal = false;
 		},
+		cancelOrderFn(cgId) {
+			let that = this
+			that.$util.confirmModal({content:'确认取消此采购单?'},() => {
+				var params = {id:cgId}
+				cancelOrder(params).then((res) => {
+					if(res.code == 1){
+						this.showCancelBtn = false
+						this.detailInfo.status = 5
+						this.$msg("采购单取消成功")
+					}
+				}).catch((error) => {
+					console.error(error);
+				})
+			})
+		},
+		showCancelOrder(cgInfo) {
+			if (cgInfo == undefined) {
+				return false
+			}
+			var status = cgInfo.status
+			var deadline = cgInfo.deadline
+			if (status != 1) {
+				return false
+			}
+
+			if (deadline == "" || deadline == undefined) {
+				return false
+			}
+			var orderTimestamp = this.formatDate(deadline)
+			var currTimestam = new Date().getTime() / 1000
+			var diff = orderTimestamp - currTimestam
+
+			//console.log(orderTimestamp)
+			//console.log(currTimestam)
+			//console.log(diff)
+			if (diff > 120) {
+				return true
+			}
+
+			return false
+		},
+		formatDate(deadline) {
+			var timeStr = String(deadline)
+			const [dateComponents, timeComponents] = timeStr.split(' ');
+			//console.log(dateComponents);
+			//console.log(timeComponents);
+
+			const [year, month, day] = dateComponents.split('-');
+			const [hours, minutes, seconds] = timeComponents.split(':');
+
+			const date = new Date(+year, month - 1, +day, +hours, +minutes, +seconds);
+			//console.log(date);
+
+			// Get Unix timestamp
+			const unixTimestamp = Math.floor(date.getTime() / 1000);
+			//console.log(unixTimestamp);
+			return unixTimestamp;
+		},
 		clickBtn(s, item) {
 			this.orderId = item.id;
 			if (s.type === "selfGet") {