<template>
|
<el-dialog
|
:title="'修改时间'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
:append-to-body="true"
|
width="700px"
|
@close="handClose"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
@keyup.enter.native="dataFormSubmit()"
|
label-width="120px"
|
>
|
<el-form-item label="创建时间" prop="create_time">
|
<el-date-picker
|
v-model="dataForm.create_time"
|
type="datetime"
|
placeholder="选择创建时间"
|
format="yyyy-MM-dd HH:mm:ss"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
style="width: 100%"
|
>
|
</el-date-picker>
|
</el-form-item>
|
<el-form-item label="处理时间" prop="handle_time">
|
<el-date-picker
|
v-model="dataForm.handle_time"
|
type="datetime"
|
placeholder="选择处理时间"
|
format="yyyy-MM-dd HH:mm:ss"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
style="width: 100%"
|
>
|
</el-date-picker>
|
</el-form-item>
|
<el-form-item label="关闭时间" prop="close_time">
|
<el-date-picker
|
v-model="dataForm.close_time"
|
type="datetime"
|
placeholder="选择关闭时间"
|
format="yyyy-MM-dd HH:mm:ss"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
style="width: 100%"
|
>
|
</el-date-picker>
|
</el-form-item>
|
<el-form-item label="支付时间" prop="pay_time">
|
<el-date-picker
|
v-model="dataForm.pay_time"
|
type="datetime"
|
placeholder="选择支付时间"
|
format="yyyy-MM-dd HH:mm:ss"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
style="width: 100%"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
|
</span>
|
</el-dialog>
|
</template>
|
|
<script>
|
import { Debounce } from "@/utils/debounce";
|
export default {
|
data() {
|
return {
|
visible: false,
|
dataForm: {
|
order_no: "",
|
create_time: "",
|
handle_time: "",
|
close_time: "",
|
pay_time: "",
|
},
|
dataRule: {},
|
};
|
},
|
methods: {
|
// 格式化时间为 yyyy-MM-dd HH:mm:ss 格式
|
formatDateTimeForPicker(dateTime) {
|
if (!dateTime) return "";
|
|
let date;
|
// 如果是字符串格式(可能包含T)
|
if (typeof dateTime === "string") {
|
// 替换T为空格,移除毫秒和时区
|
const cleaned = dateTime.replace("T", " ").replace(/\.\d{3}Z?$/, "").replace(/Z$/, "");
|
// 如果已经是 yyyy-MM-dd HH:mm:ss 格式,直接返回
|
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(cleaned)) {
|
return cleaned;
|
}
|
date = new Date(dateTime);
|
} else if (dateTime instanceof Date) {
|
date = dateTime;
|
} else {
|
return "";
|
}
|
|
// 检查日期是否有效
|
if (isNaN(date.getTime())) {
|
return "";
|
}
|
|
// 格式化为 yyyy-MM-dd HH:mm:ss
|
const year = date.getFullYear();
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
const day = String(date.getDate()).padStart(2, "0");
|
const hours = String(date.getHours()).padStart(2, "0");
|
const minutes = String(date.getMinutes()).padStart(2, "0");
|
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
},
|
init(row) {
|
this.dataForm = {
|
order_no: row.order_no || "",
|
create_time: this.formatDateTimeForPicker(row.create_time),
|
handle_time: this.formatDateTimeForPicker(row.handle_time),
|
close_time: this.formatDateTimeForPicker(row.close_time),
|
pay_time: this.formatDateTimeForPicker(row.pay_time),
|
};
|
this.visible = true;
|
},
|
handClose() {
|
// 关闭时重置表单
|
this.$nextTick(() => {
|
if (this.$refs["dataForm"]) {
|
this.$refs["dataForm"].clearValidate();
|
}
|
});
|
},
|
// 表单提交
|
dataFormSubmit: Debounce(function () {
|
this.$refs["dataForm"].validate((valid) => {
|
if (!valid) {
|
return;
|
}
|
|
// 格式化时间字段,确保不包含"T"
|
const formatTime = (time) => {
|
if (!time) return "";
|
return time.toString().replace("T", " ").replace(/\.\d{3}Z?$/, "");
|
};
|
|
this.$http({
|
url: this.$http.adornUrl(`/c2cOrder/updateDate`),
|
method: "post",
|
data: this.$http.adornData({
|
orderNo: this.dataForm.order_no,
|
createDate: formatTime(this.dataForm.create_time),
|
handleTime: formatTime(this.dataForm.handle_time),
|
closeDate: formatTime(this.dataForm.close_time),
|
payDate: formatTime(this.dataForm.pay_time),
|
}),
|
}).then(({ data }) => {
|
if (data.code == 0) {
|
this.$message({
|
message: "修改时间成功",
|
type: "success",
|
duration: 1500,
|
onClose: () => {
|
this.visible = false;
|
this.$emit("refreshDataList", this.page);
|
},
|
});
|
} else {
|
this.$message({
|
message: data.msg || "修改时间失败",
|
type: "error",
|
duration: 1500,
|
});
|
}
|
});
|
});
|
}),
|
},
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
::v-deep .el-dialog__body {
|
padding: 20px 20px;
|
}
|
|
::v-deep .avue-crud__menu {
|
height: auto;
|
min-height: 0px;
|
}
|
</style>
|