<template>
|
<el-dialog
|
:title="dataForm.uuid ? '编辑盘前配置' : '新增盘前配置'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
append-to-body
|
width="560px"
|
@close="handClose"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
label-width="130px"
|
@keyup.enter.native="dataFormSubmit()"
|
>
|
<el-form-item label="美股代码" prop="symbol">
|
<el-select
|
v-model="dataForm.symbol"
|
placeholder="请选择美股"
|
filterable
|
:disabled="!!dataForm.uuid"
|
class="full-width"
|
>
|
<el-option
|
v-for="item in symbolOptions"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="盘前开始时间" prop="startTime">
|
<el-input
|
v-model="dataForm.startTime"
|
placeholder="美东时间 HH:mm,如 4:00"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="盘前结束时间" prop="endTime">
|
<el-input
|
v-model="dataForm.endTime"
|
placeholder="美东时间 HH:mm,如 9:30"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="盘前固定价格" prop="prePrice">
|
<el-input
|
v-model="dataForm.prePrice"
|
type="number"
|
placeholder="必须大于 0"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="启用" prop="enabled">
|
<el-switch
|
v-model="dataForm.enabled"
|
:active-value="1"
|
:inactive-value="0"
|
></el-switch>
|
</el-form-item>
|
<div class="tip-text">盘前时段按美东时间 America/New_York 计算,支持跨午夜时段。</div>
|
</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,
|
symbolOptions: [],
|
dataForm: {
|
uuid: "",
|
symbol: "",
|
startTime: "",
|
endTime: "",
|
prePrice: "",
|
enabled: 1,
|
},
|
dataRule: {
|
symbol: [{ required: true, message: "请选择美股", trigger: "change" }],
|
startTime: [
|
{ required: true, message: "盘前开始时间不能为空", trigger: "blur" },
|
],
|
endTime: [
|
{ required: true, message: "盘前结束时间不能为空", trigger: "blur" },
|
],
|
prePrice: [
|
{ required: true, message: "盘前价格不能为空", trigger: "blur" },
|
],
|
},
|
};
|
},
|
methods: {
|
init(uuid) {
|
this.visible = true;
|
this.loadSymbolOptions();
|
if (uuid) {
|
this.loadDetail(uuid);
|
} else {
|
this.dataForm = {
|
uuid: "",
|
symbol: "",
|
startTime: "",
|
endTime: "",
|
prePrice: "",
|
enabled: 1,
|
};
|
}
|
this.$nextTick(() => {
|
if (this.$refs.dataForm) {
|
this.$refs.dataForm.clearValidate();
|
}
|
});
|
},
|
loadSymbolOptions() {
|
this.$http({
|
url: this.$http.adornUrl("/normal/adminItemAction!/list"),
|
method: "get",
|
params: this.$http.adornParams({
|
type: "US-stocks",
|
current: 1,
|
size: 10000,
|
}),
|
}).then(({ data }) => {
|
if (data.code == 0 && data.data.records) {
|
this.symbolOptions = data.data.records.map((item) => ({
|
label: `${item.symbol} ${item.name || ""}`,
|
value: item.symbol,
|
}));
|
}
|
});
|
},
|
loadDetail(uuid) {
|
this.$http({
|
url: this.$http.adornUrl("/normal/adminItemPreMarketAction!/get.action"),
|
method: "get",
|
params: this.$http.adornParams({ uuid }),
|
}).then(({ data }) => {
|
if (data.code == 0 && data.data) {
|
this.dataForm = {
|
uuid: data.data.uuid,
|
symbol: data.data.symbol,
|
startTime: data.data.startTime,
|
endTime: data.data.endTime,
|
prePrice: data.data.prePrice,
|
enabled: data.data.enabled == null ? 1 : data.data.enabled,
|
};
|
} else {
|
this.$message({
|
message: data.msg || "加载失败",
|
type: "error",
|
});
|
}
|
});
|
},
|
handClose() {
|
this.dataForm = {
|
uuid: "",
|
symbol: "",
|
startTime: "",
|
endTime: "",
|
prePrice: "",
|
enabled: 1,
|
};
|
this.$nextTick(() => {
|
if (this.$refs.dataForm) {
|
this.$refs.dataForm.clearValidate();
|
}
|
});
|
},
|
dataFormSubmit: Debounce(function () {
|
this.$refs.dataForm.validate((valid) => {
|
if (!valid) {
|
return;
|
}
|
const payload = {
|
symbol: this.dataForm.symbol,
|
startTime: this.dataForm.startTime,
|
endTime: this.dataForm.endTime,
|
prePrice: Number(this.dataForm.prePrice),
|
enabled: this.dataForm.enabled,
|
};
|
if (this.dataForm.uuid) {
|
payload.uuid = this.dataForm.uuid;
|
}
|
this.$http({
|
url: this.$http.adornUrl(
|
"/normal/adminItemPreMarketAction!/save.action"
|
),
|
method: "post",
|
data: this.$http.adornData(payload),
|
}).then(({ data }) => {
|
if (data.code == 0) {
|
this.$message({
|
message: "保存成功",
|
type: "success",
|
duration: 1500,
|
onClose: () => {
|
this.visible = false;
|
this.$emit("refreshDataList");
|
},
|
});
|
} else {
|
this.$message({
|
message: data.msg,
|
type: "error",
|
});
|
}
|
});
|
});
|
}),
|
},
|
};
|
</script>
|
|
<style scoped>
|
.full-width {
|
width: 100%;
|
}
|
.tip-text {
|
color: #909399;
|
font-size: 12px;
|
line-height: 1.6;
|
padding-left: 130px;
|
}
|
</style>
|