expansion-template.html
8.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>拓客数据录入</title>
<!-- 引入配置文件 -->
<script src="config.js"></script>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input, select, textarea { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; }
button { background: #007bff; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; }
button:hover { background: #0056b3; }
.message { padding: 10px; margin: 10px 0; border-radius: 4px; }
.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
</style>
</head>
<body>
<h1>拓客数据录入</h1>
<!-- 配置区域 -->
<div style="background: #f8f9fa; padding: 15px; border-radius: 4px; margin-bottom: 20px;">
<h3>后端服务配置</h3>
<div class="form-group">
<label for="apiUrl">API地址:</label>
<input type="text" id="apiUrl" placeholder="后端服务地址">
</div>
<button onclick="testConnection()">测试连接</button>
</div>
<!-- 消息显示区域 -->
<div id="messageBox"></div>
<!-- 拓客表单 -->
<form id="expansionForm">
<div class="form-group">
<label for="tksj">拓客时间:</label>
<input type="datetime-local" id="tksj" required>
</div>
<div class="form-group">
<label for="tkry">拓客人员:</label>
<input type="text" id="tkry" placeholder="请输入拓客人员姓名" required>
</div>
<div class="form-group">
<label for="gkxm">顾客姓名:</label>
<input type="text" id="gkxm" placeholder="请输入顾客姓名" required>
</div>
<div class="form-group">
<label for="dhhm">电话号码:</label>
<input type="tel" id="dhhm" placeholder="请输入电话号码" maxlength="11" required>
</div>
<div class="form-group">
<label for="gmzs">购买张数:</label>
<input type="number" id="gmzs" min="1" placeholder="请输入购买张数" required>
</div>
<div class="form-group">
<label for="zffs">支付方式:</label>
<select id="zffs" required>
<option value="">请选择支付方式</option>
<option value="现金">现金</option>
<option value="微信">微信</option>
<option value="支付宝">支付宝</option>
</select>
</div>
<div class="form-group">
<label for="sfjwx">是否加微信:</label>
<select id="sfjwx" required>
<option value="">请选择</option>
<option value="是">是</option>
<option value="否">否</option>
</select>
</div>
<div class="form-group">
<label for="bz">备注:</label>
<textarea id="bz" rows="3" placeholder="请输入备注信息"></textarea>
</div>
<button type="submit">提交数据</button>
</form>
<script>
// 页面加载时设置默认时间和配置
document.addEventListener('DOMContentLoaded', function() {
const now = new Date();
const localDateTime = new Date(now.getTime() - now.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
document.getElementById('tksj').value = localDateTime;
// 加载配置
loadConfig();
});
// 加载配置
function loadConfig() {
// 优先使用localStorage中的配置,如果没有则使用配置文件中的默认值
const savedApiUrl = localStorage.getItem('expansionTemplateApiUrl');
const defaultApiUrl = window.APP_CONFIG ? window.APP_CONFIG.getApiBaseUrl() : 'http://localhost:5000';
const apiUrl = savedApiUrl || defaultApiUrl;
document.getElementById('apiUrl').value = apiUrl;
// 显示当前环境信息
if (window.APP_CONFIG) {
console.log('当前环境:', window.APP_CONFIG.getEnvName());
console.log('默认API地址:', window.APP_CONFIG.getApiBaseUrl());
}
}
// 显示消息
function showMessage(message, type = 'info') {
const messageBox = document.getElementById('messageBox');
messageBox.innerHTML = `<div class="message ${type}">${message}</div>`;
if (type === 'success' || type === 'error') {
setTimeout(() => {
messageBox.innerHTML = '';
}, 5000);
}
}
// 测试连接
async function testConnection() {
const apiUrl = document.getElementById('apiUrl').value.trim();
if (!apiUrl) {
showMessage('请输入API地址', 'error');
return;
}
try {
showMessage('正在测试连接...', 'info');
const response = await fetch(`${apiUrl}/api/Extend/LqTkjlb`, {
method: 'GET'
});
if (response.ok) {
showMessage('✅ 连接成功!后端服务正常运行', 'success');
} else {
showMessage(`❌ 连接失败: HTTP ${response.status}`, 'error');
}
} catch (error) {
showMessage('❌ 连接失败: ' + error.message, 'error');
}
}
// 处理表单提交
document.getElementById('expansionForm').addEventListener('submit', async function(e) {
e.preventDefault();
const apiUrl = document.getElementById('apiUrl').value.trim();
if (!apiUrl) {
showMessage('请先配置API地址', 'error');
return;
}
// 收集表单数据
const formData = {
tksj: new Date(document.getElementById('tksj').value).getTime(),
tkry: document.getElementById('tkry').value,
gkxm: document.getElementById('gkxm').value,
dhhm: document.getElementById('dhhm').value,
gmzs: parseInt(document.getElementById('gmzs').value),
zffs: document.getElementById('zffs').value,
sfjwx: document.getElementById('sfjwx').value,
bz: document.getElementById('bz').value || ''
};
try {
showMessage('正在提交数据...', 'info');
const response = await fetch(`${apiUrl}/api/Extend/LqTkjlb`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
if (response.ok) {
const result = await response.json();
showMessage('✅ 数据提交成功!已保存到数据库', 'success');
console.log('提交结果:', result);
// 重置表单
this.reset();
// 重新设置默认时间
const now = new Date();
const localDateTime = new Date(now.getTime() - now.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
document.getElementById('tksj').value = localDateTime;
} else {
const errorText = await response.text();
showMessage(`❌ 提交失败: HTTP ${response.status} - ${errorText}`, 'error');
}
} catch (error) {
showMessage('❌ 提交失败: ' + error.message, 'error');
console.error('提交错误:', error);
}
});
</script>
</body>
</html>