Переглянути джерело

修改程序,将前台写死内容改成可配置

张庆宇 2 тижднів тому
джерело
коміт
ce3865e580
3 змінених файлів з 383 додано та 714 видалено
  1. 242
    249
      src/components/FormBox.vue
  2. 1
    1
      src/components/TableBox.vue
  3. 140
    464
      src/views/sto/main/customer.vue

+ 242
- 249
src/components/FormBox.vue Переглянути файл

@@ -1,20 +1,27 @@
1
-<!-- vue3不支持defineEmits动态添加    暂时无法使用配置按钮 -->
1
+<!-- FormBox.vue -->
2 2
 <template>
3 3
 	<div>
4 4
 		<div v-if="dialog">
5
-			<el-dialog :close-on-click-modal="false" draggable title="编辑" v-model="dialogVisible" width="1300px"
6
-				top="5vh">
5
+			<el-dialog 
6
+        :close-on-click-modal="false" 
7
+        draggable 
8
+        :title="dialogTitle" 
9
+        v-model="dialogVisible" 
10
+        width="1000px"
11
+        top="10vh"
12
+        @close="handleDialogClose"
13
+      >
7 14
 				<el-card :body-style="cardBodyStyle">
8
-					<el-form v-if="formItems && formItems.length > 0" :model="form" label-width="auto"
15
+					<el-form v-if="formItems && formItems.length > 0" :model="formData" label-width="auto"
9 16
 						label-position="right">
10 17
 						<div v-for="(itemList, indexList) in formList" :key="indexList">
11 18
 							<el-row style="margin-bottom: 5px;" :gutter="10">
12 19
 								<el-col v-for="(item, index) in itemList" :key="index" :span="item.span">
13 20
 									<el-form-item :label="item.label" :prop="item.prop">
14 21
 										<!--文本-->
15
-										<el-input v-if="item.type === 'input'" v-model="form[item.prop]" clearable
22
+										<el-input v-if="item.type === 'input'" v-model="formData[item.prop]" clearable
16 23
 											placeholder="请输入" style="width:100%; ">
17
-											<template #append v-if="item.searchButton?item.searchButton:false">
24
+											<template #append v-if="item.searchButton==true||item.searchButton=='1'?true:false">
18 25
 												<el-button @click="emit(item.searchCallback)">
19 26
 													<el-icon>
20 27
 														<Search />
@@ -22,33 +29,37 @@
22 29
 											</template>
23 30
 										</el-input>
24 31
 										<!-- 下拉 -->
25
-										<el-select v-if="item.type === 'select'" v-model="form[item.prop]" clearable
32
+										<el-select v-if="item.type === 'select'" v-model="formData[item.prop]" clearable
26 33
 											style="width:100%; ">
27 34
 											<el-option v-for="(option,i) in item.options" :key="i"
28 35
 												:value="option[item.optionValue?item.optionValue:'value']"
29 36
 												:label="option[item.optionLabel?item.optionLabel:'label']" />
30 37
 										</el-select>
31 38
 										<!-- 单选 -->
32
-										<el-radio-group v-if="item.type === 'radio'" v-model="form[item.prop]"
39
+										<el-radio-group v-if="item.type === 'radio'" v-model="formData[item.prop]"
33 40
 											style="width:100%; ">
34 41
 											<el-radio v-for="(option,i) in item.options" :key="i"
35
-												:label="option[item.optionValue?item.optionValue:'value']">{{option[item.optionLabel?item.optionLabel:'label']}}
42
+												:label="option[item.optionValue?item.optionValue:'value']">
43
+												{{option[item.optionLabel?item.optionLabel:'label']}}
36 44
 											</el-radio>
37 45
 										</el-radio-group>
38 46
 										<!--日期-->
39
-										<el-date-picker v-if="item.type === 'date'" v-model="form[item.prop]"
47
+										<el-date-picker v-if="item.type === 'date'" v-model="formData[item.prop]"
40 48
 											type="date" clearable value-format="YYYY-MM-DD" format="YYYY-MM-DD"
41 49
 											style="width:100%; " />
42
-										<!--日期-->
43
-										<el-date-picker v-if="item.type === 'daterange'" v-model="form[item.prop]"
50
+										<!--日期范围-->
51
+										<el-date-picker v-if="item.type === 'daterange'" v-model="formData[item.prop]"
44 52
 											type="daterange" clearable range-separator="至" start-placeholder="开始日期"
45 53
 											end-placeholder="结束日期" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
46 54
 											style="width:100%; "></el-date-picker>
47
-										<!--日期-->
48
-										<el-date-picker v-if="item.type === 'datetimerange'" v-model="form[item.prop]"
55
+										<!--日期时间范围-->
56
+										<el-date-picker v-if="item.type === 'datetimerange'" v-model="formData[item.prop]"
49 57
 											type="daterange" range-separator="至" start-placeholder="开始时间"
50 58
 											end-placeholder="结束时间" value-format="YYYY-MM-DD HH:mm:ss"
51 59
 											format="YYYY-MM-DD HH:mm:ss" style="width: 350px; " />
60
+										<!--文本-->
61
+										<el-input v-if="item.type === 'textarea'" type="textarea" v-model="formData[item.prop]" clearable
62
+											placeholder="请输入" style="width:100%; " :rows="4"/>
52 63
 									</el-form-item>
53 64
 								</el-col>
54 65
 							</el-row>
@@ -56,269 +67,251 @@
56 67
 					</el-form>
57 68
 				</el-card>
58 69
 
59
-
60 70
 				<template #footer>
61 71
 					<div class="dialog-footer">
62
-						<el-button type="success" @click="handleSave(ruleFormRef)">保存</el-button>
63
-						<el-button type="danger" @click="()=>dialogVisible=false">取消</el-button>
72
+						<el-button type="success" @click="handleSave">保存</el-button>
73
+						<el-button type="danger" @click="handleClose">取消</el-button>
64 74
 					</div>
65 75
 				</template>
66 76
 			</el-dialog>
67 77
 		</div>
68
-
69
-		<div v-else>
70
-			<el-card :body-style="cardBodyStyle">
71
-				<el-form v-if="formItems && formItems.length > 0" :model="form" label-width="auto"
72
-					label-position="right">
73
-					<div v-for="(itemList, indexList) in formList" :key="indexList">
74
-						<el-row style="margin-bottom: 5px;" :gutter="10">
75
-							<el-col v-for="(item, index) in itemList" :key="index" :span="item.span">
76
-								<el-form-item :label="item.label" :prop="item.prop">
77
-									<!--文本-->
78
-									<el-input v-if="item.type === 'input'" v-model="form[item.prop]" clearable
79
-										placeholder="请输入" style="width:100%; ">
80
-										<template #append v-if="item.searchButton?item.searchButton:false">
81
-											<el-button @click="emit(item.searchCallback)">
82
-												<el-icon>
83
-													<Search />
84
-												</el-icon></el-button>
85
-										</template>
86
-									</el-input>
87
-									<!-- 下拉 -->
88
-									<el-select v-if="item.type === 'select'" v-model="form[item.prop]" clearable
89
-										style="width:100%; ">
90
-										<el-option v-for="(option,i) in item.options" :key="i"
91
-											:value="option[item.optionValue?item.optionValue:'value']"
92
-											:label="option[item.optionLabel?item.optionLabel:'label']" />
93
-									</el-select>
94
-									<!-- 单选 -->
95
-									<el-radio-group v-if="item.type === 'radio'" v-model="form[item.prop]"
96
-										style="width:100%; ">
97
-										<el-radio v-for="(option,i) in item.options" :key="i"
98
-											:label="option[item.optionValue?item.optionValue:'value']">{{option[item.optionLabel?item.optionLabel:'label']}}
99
-										</el-radio>
100
-									</el-radio-group>
101
-									<!--日期-->
102
-									<el-date-picker v-if="item.type === 'date'" v-model="form[item.prop]"
103
-										type="date" clearable value-format="YYYY-MM-DD" format="YYYY-MM-DD"
104
-										style="width:100%; " />
105
-									<!--日期-->
106
-									<el-date-picker v-if="item.type === 'daterange'" v-model="form[item.prop]"
107
-										type="daterange" clearable range-separator="至" start-placeholder="开始日期"
108
-										end-placeholder="结束日期" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
109
-										style="width:100%; "></el-date-picker>
110
-									<!--日期-->
111
-									<el-date-picker v-if="item.type === 'datetimerange'" v-model="form[item.prop]"
112
-										type="daterange" range-separator="至" start-placeholder="开始时间"
113
-										end-placeholder="结束时间" value-format="YYYY-MM-DD HH:mm:ss"
114
-										format="YYYY-MM-DD HH:mm:ss" style="width: 350px; " />
115
-								</el-form-item>
116
-							</el-col>
117
-						</el-row>
118
-					</div>
119
-				</el-form>
120
-			</el-card>
121
-		</div>
122
-
123
-
78
+		<!-- 非弹窗模式省略... -->
124 79
 	</div>
125 80
 </template>
81
+
126 82
 <script setup>
127
-	import {
128
-		ref,
129
-		getCurrentInstance,
130
-		onMounted,
131
-		reactive,
132
-		computed
133
-	} from 'vue'
134
-	const {
135
-		proxy
136
-	} = getCurrentInstance()
137
-	import style from '@/tools/style'
138
-	const cardBodyStyle = ref(style.card)
139
-	onMounted(() => {
140
-		// init()
141
-		getMenuForm()
142
-	})
143
-	const props = defineProps({
144
-		// formItem: {
145
-		// 	type: Array,
146
-		// 	default: () => []
147
-		// },
148
-		formData: {
149
-			type: Object,
150
-			default: () => {}
151
-		},
152
-		formName: { // form查询数据
153
-			type: String,
154
-			default: () => ''
155
-		},
156
-		dialog: {
157
-			type: Boolean,
158
-			default: () => false
159
-		}
160
-	})
161
-	const emit = defineEmits()
162
-	// const form = reactive(JSON.parse(JSON.stringify(props.formData))) // form查询数据
163
-	const form = computed(() => {
164
-		return props.formData
165
-	})
166
-	const formList = ref([])
167
-	const span = ref(5)
83
+import {
84
+  ref,
85
+  getCurrentInstance,
86
+  onMounted,
87
+  watch,
88
+  nextTick
89
+} from 'vue'
90
+import { Search } from '@element-plus/icons-vue'
91
+
92
+const {
93
+  proxy
94
+} = getCurrentInstance()
95
+
96
+import style from '@/tools/style'
97
+const cardBodyStyle = ref(style.card)
168 98
 
99
+// Props
100
+const props = defineProps({
101
+  formData: {
102
+    type: Object,
103
+    default: () => ({})
104
+  },
105
+  formName: {
106
+    type: String,
107
+    default: () => ''
108
+  },
109
+  dialog: {
110
+    type: Boolean,
111
+    default: () => false
112
+  },
113
+  title: {
114
+    type: String,
115
+    default: '编辑'
116
+  }
117
+})
169 118
 
119
+// Emits
120
+const emit = defineEmits(['save', 'update:dialog', 'close'])
170 121
 
171
-	const formItems = ref([])
172
-	const getMenuForm = () => {
173
-		var url = 'framework/MenuForm/queryMenuForm'
174
-		var param = {
175
-			menuId: localStorage.getItem('menuId'),
176
-			formType: '录入',
177
-			formName: props.formName
178
-		}
179
-		proxy.$axios.get(url, param).then(response => {
180
-			if (response.data.code == '0') {
181
-				formItems.value = response.data.data
182
-				init()
183
-			} else {
184
-				ElMessage.error('操作失败!' + response.data.msg)
185
-			}
186
-		})
187
-	}
122
+// 响应式数据
123
+const formItems = ref([])
124
+const formList = ref([])
125
+const dicTypes = ref([])
126
+const urls = ref([])
127
+const dialogVisible = ref(false)
128
+const dialogTitle = ref('编辑')
188 129
 
130
+// 监听 dialog prop 变化
131
+watch(() => props.dialog, (newVal) => {
132
+  console.log('FormBox dialog prop changed:', newVal)
133
+  dialogVisible.value = newVal
134
+  if (newVal) {
135
+    dialogTitle.value = props.formData?.id ? '编辑客户' : '新增客户'
136
+  }
137
+}, { immediate: true })
189 138
 
139
+// 监听内部 dialogVisible 变化
140
+watch(dialogVisible, (newVal) => {
141
+  console.log('FormBox dialogVisible changed:', newVal)
142
+  emit('update:dialog', newVal)
143
+  if (!newVal) {
144
+    emit('close')
145
+  }
146
+})
190 147
 
148
+onMounted(() => {
149
+  if (props.formName) {
150
+    getMenuForm()
151
+  }
152
+})
191 153
 
154
+// 获取表单配置
155
+const getMenuForm = () => {
156
+  var url = 'framework/MenuForm/queryMenuForm'
157
+  var param = {
158
+    menuId: localStorage.getItem('menuId'),
159
+    formType: '录入',
160
+    formName: props.formName
161
+  }
162
+  proxy.$axios.get(url, param).then(response => {
163
+    if (response.data.code == '0') {
164
+      formItems.value = response.data.data
165
+      init()
166
+    } else {
167
+      ElMessage.error('操作失败!' + response.data.msg)
168
+    }
169
+  })
170
+}
192 171
 
193
-	const dicTypes = ref([])
194
-	const urls = ref([])
195
-	const init = async () => {
196
-		var colsCount = 4
197
-		var length = Math.ceil(formItems.value.length / colsCount)
198
-		var arr = []
199
-		for (var i = 0; i < length; i++) {
200
-			arr.push([])
201
-		}
202
-		var col = 0
203
-		formItems.value.forEach((item, index) => {
204
-			col = Math.floor(index / colsCount)
205
-			if (item.type == 'datetimerange') {
206
-				item.span = 12
207
-			} else {
208
-				item.span = 6
209
-			}
210
-			if ((item.type == 'select' || item.type == 'radio') && item.dicType && item.dicType != null &&
211
-				item
212
-				.dicType != '') {
213
-				dicTypes.value.push(item.dicType)
214
-			}
172
+// 初始化表单布局
173
+const init = async () => {
174
+  var colsCount = 4
175
+  var length = Math.ceil(formItems.value.length / colsCount)
176
+  var arr = []
177
+  for (var i = 0; i < length; i++) {
178
+    arr.push([])
179
+  }
180
+  var col = 0
181
+  formItems.value.forEach((item, index) => {
182
+    col = Math.floor(index / colsCount)
183
+	if(item.formType == "录入" && item.type != 'textarea'){
184
+		item.span = 12
185
+	}else if (item.type == 'datetimerange') {
186
+      item.span = 12
187
+    } else if(item.type == 'textarea'){
188
+		item.span = 24
189
+	} else {
190
+      item.span = 6
191
+    }
192
+	
193
+    if ((item.type == 'select' || item.type == 'radio') && item.dicType && item.dicType != null &&
194
+      item.dicType != '') {
195
+      dicTypes.value.push(item.dicType)
196
+    }
215 197
 
216
-			if ((item.type == 'select' || item.type == 'radio') && item.url && item.url != null && item
217
-				.url != '') {
218
-				urls.value.push({
219
-					'url': item.url,
220
-					'param': item.param,
221
-					'optionLabel': item.optionLabel,
222
-					'optionValue': item.optionValue,
223
-				})
224
-			}
225
-			arr[col].push(item)
226
-		})
227
-		formList.value = arr
198
+    if ((item.type == 'select' || item.type == 'radio') && item.url && item.url != null && item.url != '') {
199
+      urls.value.push({
200
+        'url': item.url,
201
+        'param': item.param,
202
+        'optionLabel': item.optionLabel,
203
+        'optionValue': item.optionValue,
204
+      })
205
+    }
206
+    arr[col].push(item)
207
+  })
208
+  formList.value = arr
228 209
 
229
-		console.log('dicTypes.value:' + JSON.stringify(dicTypes.value))
230
-		if (dicTypes.value.length > 0) {
231
-			getDic()
232
-		}
233
-		console.log('urls.value:' + JSON.stringify(urls.value))
234
-		if (urls.value.length > 0) {
235
-			for (var item of urls.value) {
236
-				await getOption(item)
237
-			}
238
-		}
239
-	}
240
-	const dialogVisible = ref(false)
241
-	const open = () => {
242
-		dialogVisible.value = true
243
-	}
244
-	const close = () => {
245
-		dialogVisible.value = false
246
-	}
210
+  if (dicTypes.value.length > 0) {
211
+    getDic()
212
+  }
213
+  
214
+  if (urls.value.length > 0) {
215
+    for (var item of urls.value) {
216
+      await getOption(item)
217
+    }
218
+  }
219
+}
247 220
 
248
-	const getDic = () => {
249
-		var url = 'framework/Common/querySelectorList'
250
-		var param = {
251
-			type: JSON.stringify(dicTypes.value)
252
-		}
253
-		proxy.$axios.get(url, param).then(response => {
254
-			if (response.data.code == '0') {
221
+// 获取字典数据
222
+const getDic = () => {
223
+  var url = 'framework/Common/querySelectorList'
224
+  var param = {
225
+    type: JSON.stringify(dicTypes.value)
226
+  }
227
+  proxy.$axios.get(url, param).then(response => {
228
+    if (response.data.code == '0') {
229
+      for (let key in response.data.data) {
230
+        for (var item of formItems.value) {
231
+          if ((item.type == 'select' || item.type == 'radio') && item.dicType && item.dicType != null && item.dicType != '') {
232
+            if (key == item.dicType) {
233
+              item.options = response.data.data[key]
234
+              item.optionLabel = 'dicName'
235
+              item.optionValue = 'dicCode'
236
+            }
237
+          }
238
+        }
239
+      }
240
+    } else {
241
+      ElMessage.error('操作失败!' + response.data.msg)
242
+    }
243
+  })
244
+}
255 245
 
256
-				// console.log(response.data.data)
246
+// 获取选项数据
247
+const getOption = (item) => {
248
+  return new Promise((resolve) => {
249
+    var url = item.url
250
+    var param = item.param
251
+    proxy.$axios.get(url, param).then(response => {
252
+      if (response.data.code == '0') {
253
+        for (var form of formItems.value) {
254
+          if (form.url == item.url) {
255
+            form.options = response.data.data
256
+            form.optionLabel = item.optionLabel
257
+            form.optionValue = item.optionValue
258
+          }
259
+        }
260
+        resolve()
261
+      } else {
262
+        ElMessage.error('操作失败!' + response.data.msg)
263
+        resolve()
264
+      }
265
+    }).catch(() => {
266
+      resolve()
267
+    })
268
+  })
269
+}
257 270
 
258
-				for (let key in response.data.data) {
259
-					// console.log('key:' + key)
260
-					for (var item of formItems.value) {
261
-						if ((item.type == 'select' || item.type == 'radio') && item.dicType && item.dicType !=
262
-							null && item.dicType != '') {
263
-							// console.log('item.dicType:' + item.dicType)
264
-							if (key == item.dicType) {
265
-								item.options = response.data.data[key]
266
-								item.optionLabel = 'dicName'
267
-								item.optionValue = 'dicCode'
268
-							}
269
-						}
270
-					}
271
-				}
272
-				// console.log('props.formItem:' + JSON.stringify(props.formItem))
271
+// 保存
272
+const handleSave = () => {
273
+  console.log('保存表单数据:', props.formData)
274
+  emit('save', props.formData)
275
+}
273 276
 
274
-			} else {
275
-				ElMessage.error('操作失败!' + response.data.msg)
276
-			}
277
-		})
278
-	}
277
+// 关闭弹窗
278
+const handleClose = () => {
279
+  dialogVisible.value = false
280
+}
279 281
 
280
-	const getOption = (item) => { // 清空搜索栏
281
-		var url = item.url
282
-		var param = item.param
283
-		proxy.$axios.get(url, param).then(response => {
284
-			if (response.data.code == '0') {
285
-				for (var form of formItems.value) {
286
-					if (form.url == item.url) {
287
-						form.options = response.data.data
288
-						form.optionLabel = item.optionLabel
289
-						form.optionValue = item.optionValue
290
-					}
291
-				}
292
-			} else {
293
-				ElMessage.error('操作失败!' + response.data.msg)
294
-			}
295
-		})
296
-	}
282
+// 弹窗关闭事件
283
+const handleDialogClose = () => {
284
+  dialogVisible.value = false
285
+}
297 286
 
298
-	const handleSave = () => {
299
-		emit('save', form.value)
300
-	}
301
-	defineExpose({
302
-		open,
303
-		close,
304
-		form
305
-	})
287
+// 暴露给父组件的方法
288
+const open = () => {
289
+  dialogVisible.value = true
290
+}
291
+
292
+const close = () => {
293
+  dialogVisible.value = false
294
+}
295
+
296
+defineExpose({
297
+  open,
298
+  close
299
+})
306 300
 </script>
307 301
 
308 302
 <style>
309
-	.search-bar {
310
-		display: flex;
311
-		flex-direction: row;
312
-
313
-	}
303
+.search-bar {
304
+  display: flex;
305
+  flex-direction: row;
306
+}
314 307
 
315
-	.search-bar .form {
316
-		display: flex;
317
-		flex-direction: row;
318
-	}
308
+.search-bar .form {
309
+  display: flex;
310
+  flex-direction: row;
311
+}
319 312
 
320
-	.search-bar .button {
321
-		display: flex;
322
-		flex-direction: row;
323
-	}
313
+.search-bar .button {
314
+  display: flex;
315
+  flex-direction: row;
316
+}
324 317
 </style>

+ 1
- 1
src/components/TableBox.vue Переглянути файл

@@ -52,7 +52,7 @@
52 52
 	onMounted(() => {
53 53
 		// init()
54 54
 		getMenuTable()
55
-		getTableData()
55
+		//getTableData()
56 56
     updateViewportHeight()
57 57
 	})
58 58
 

+ 140
- 464
src/views/sto/main/customer.vue Переглянути файл

@@ -1,528 +1,204 @@
1 1
 <template>
2 2
   <div>
3
-    <el-card :body-style="cardBodyStyle">
4
-      <el-form :model="query" label-width="auto" label-position="right">
5
-        <el-row :gutter="10">
6
-          <el-col :span="5">
7
-            <el-form-item label="客户名称" style="margin-bottom: 0px;" >
8
-              <el-input v-model="query.customerNm" clearable placeholder="请输入客户名称" style="width:100%;"></el-input>
9
-            </el-form-item>
10
-          </el-col>
11
-          <el-col :span="4">
12
-            <el-form-item label="" style="margin-bottom: 0px; margin-top: 5px;">
13
-              <el-button type="primary" @click="handleSearch">查询</el-button>
14
-              <el-button type="success" @click="insertDialog">新增</el-button>
15
-            </el-form-item>
16
-          </el-col>
17
-        </el-row>
18
-      </el-form>
19
-    </el-card>
20
-    <ButtonBox @search="handleSearch" @add="insertDialog"></ButtonBox>
21
-    <el-card :body-style="cardBodyStyle">
22
-      <el-table :data="tableData" border highlight-current-row   @selection-change="handleSelectionChange" :height="height"  >
23
-        <el-table-column type="selection" fixed></el-table-column>
24
-        <el-table-column type="index" label="序号" align="center" width="60">
25
-          <template #default="scope">
26
-            <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
27
-          </template>
28
-        </el-table-column>
29
-        <el-table-column v-if="true" prop="customerNm" label="客户名称" width="150" header-align="center"
30
-                         align="center" show-overflow-tooltip>
31
-        </el-table-column>
32
-        <el-table-column v-if="true" prop="customerShortNm" label="客户简称" width="150" header-align="center"
33
-                         align="center" show-overflow-tooltip>
34
-        </el-table-column>
35
-        <el-table-column v-if="true" prop="contactPerson" label="联系人" width="150" header-align="center"
36
-                         align="center" show-overflow-tooltip>
37
-        </el-table-column>
38
-        <el-table-column v-if="true" prop="contactInfo" label="联系方式" width="150" header-align="center"
39
-                         align="center" show-overflow-tooltip>
40
-        </el-table-column>
41
-        <el-table-column v-if="true" prop="defaultAddress" label="默认地址" header-align="center"
42
-                         align="center" show-overflow-tooltip>
43
-        </el-table-column>
44
-        <el-table-column label="操作" header-align="center" align="center" width="200px" fixed="right">
45
-          <template #default="scope">
46
-            <el-button plain type="warning" @click="handleEdit(scope.row)">编辑</el-button>
47
-            <el-button plain type="danger" @click="handleRemove(scope.row )">删除</el-button>
48
-          </template>
49
-        </el-table-column>
50
-      </el-table>
51
-    </el-card>
52
-    <el-card :body-style="cardBodyStyle">
53
-      <el-pagination :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes" :total="totalRows"
54
-                     background="background" layout="total, sizes, prev, pager, next, jumper"
55
-                     @size-change="handleSizeChange"
56
-                     @current-change="handleCurrentChange">
57
-      </el-pagination>
58
-    </el-card>
59
-
60
-    <el-dialog class="diaClass"  :close-on-click-modal="false" draggable title="新增" v-model="dialogVisible" width="40%" top="5vh"
61
-               @open="openDialog">
62
-      <el-card  >
63
-      <el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
64
-        <el-row>
65
-          <el-col :span="12">
66
-            <el-form-item label="客户名称" prop="customerNm">
67
-              <el-input v-model="form.customerNm" maxlength="100" placeholder="请输入客户名称"></el-input>
68
-            </el-form-item>
69
-          </el-col>
70
-          <el-col :span="12">
71
-            <el-form-item label="客户简称" prop="customerShortNm">
72
-              <el-input v-model="form.customerShortNm" maxlength="100"  placeholder="请输入客户简称"></el-input>
73
-            </el-form-item>
74
-          </el-col>
75
-          <el-col :span="12">
76
-            <el-form-item label="联系人" prop="contactPerson">
77
-              <el-input v-model="form.contactPerson"  maxlength="50" placeholder="请输入联系人"></el-input>
78
-            </el-form-item>
79
-          </el-col>
80
-          <el-col :span="12">
81
-            <el-form-item label="联系方式" prop="contactInfo">
82
-              <el-input v-model="form.contactInfo" maxlength="50" placeholder="请输入联系方式"></el-input>
83
-            </el-form-item>
84
-          </el-col>
85
-          <el-col :span="24">
86
-            <el-form-item label="默认地址" prop="defaultAddress">
87
-              <el-input
88
-                  v-model="form.defaultAddress"
89
-                  :autosize="{ minRows: 2, maxRows: 4 }"
90
-                  type="textarea"
91
-                  placeholder="请输入默认地址"
92
-                  maxlength="2"
93
-                  show-word-limit
94
-              />
95
-            </el-form-item>
96
-          </el-col>
97
-
98
-        </el-row>
99
-      </el-form>
100
-
101
-      </el-card>
102
-      <template #footer>
103
-        <div class="dialog-footer">
104
-          <el-button type="success" plain @click="handleInsert(ruleFormRef)">保存</el-button>
105
-          <el-button type="danger" plain @click="handleCancelSave">取消</el-button>
106
-        </div>
107
-      </template>
108
-    </el-dialog>
109
-    <el-dialog class="diaClass"  :close-on-click-modal="false" draggable title="编辑" v-model="dialogVisibleEdit" width="40%" top="5vh"
110
-               @open="openDialog">
111
-      <el-card :body-style="cardBodyStyle">
112
-      <el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
113
-        <el-row>
114
-          <el-col :span="12">
115
-            <el-form-item label="客户名称" prop="customerNm">
116
-              <el-input v-model="form.customerNm" placeholder="请输入客户名称"></el-input>
117
-            </el-form-item>
118
-          </el-col>
119
-          <el-col :span="12">
120
-            <el-form-item label="客户简称" prop="customerShortNm">
121
-              <el-input v-model="form.customerShortNm" placeholder="请输入客户简称"></el-input>
122
-            </el-form-item>
123
-          </el-col>
124
-          <el-col :span="12">
125
-            <el-form-item label="联系人" prop="contactPerson">
126
-              <el-input v-model="form.contactPerson" placeholder="请输入联系人"></el-input>
127
-            </el-form-item>
128
-          </el-col>
129
-          <el-col :span="12">
130
-            <el-form-item label="联系方式" prop="contactInfo">
131
-              <el-input v-model="form.contactInfo" placeholder="请输入联系方式"></el-input>
132
-            </el-form-item>
133
-          </el-col>
134
-          <el-col :span="24">
135
-            <el-form-item label="默认地址" prop="defaultAddress">
136
-              <el-input
137
-                  v-model="form.defaultAddress"
138
-                  :autosize="{ minRows: 2, maxRows: 4 }"
139
-                  type="textarea"
140
-                  placeholder="请输入默认地址"
141
-              />
142
-            </el-form-item>
143
-          </el-col>
144
-
145
-        </el-row>
146
-      </el-form>
147
-
148
-      </el-card>
149
-      <template #footer>
150
-        <div class="dialog-footer">
151
-          <el-button type="success" plain @click="handleSave(ruleFormRef)">保存</el-button>
152
-          <el-button type="danger" plain @click="handleCancelSave2">取消</el-button>
153
-        </div>
154
-      </template>
155
-    </el-dialog>
3
+    <SearchBox ref="SearchBoxRef" formName="selectTop" :formData="query" @showPop="showPop" @reset="reset"></SearchBox>
4
+    <ButtonBox @search="handleSearch" @add="insertDialog" @start="start('0')" @remove="shutdwon('1')" @edit="editDialog"></ButtonBox>
156 5
   </div>
6
+  <div>
7
+    <TableBox ref="TableBoxRef" :tableData="tableDate" @edit="handleEdit" @remove="handleRemove" :page="pageType" :url="url" :param="query"></TableBox>
157 8
 
9
+    <FormBox ref="FormBoxRef" formName="input" :formData="form" :dialog="dialog" @save="handleSave" 
10
+      @update:dialog="(val) => dialog = val" :title="dialogTitle"></FormBox>
11
+  </div>
158 12
 </template>
159 13
 
160 14
 <script setup>
161
-import {getCurrentInstance, onMounted, reactive, ref} from 'vue'
15
+import { getCurrentInstance, ref, watch } from 'vue'
16
+import { ElMessage, ElMessageBox } from 'element-plus'
162 17
 import tools from '@/tools'
163
-import ButtonBox from "@/components/ButtonBox.vue";
164
-
165
-const {
166
-  proxy
167
-} = getCurrentInstance()
18
+import ButtonBox from "@/components/ButtonBox.vue"
19
+import SearchBox from "@/components/SearchBox.vue"
20
+import FormBox from '@/components/FormBox.vue'
21
+import TableBox from '@/components/TableBox.vue'
168 22
 
169
-const cardBodyStyle = ref(tools.style.card)
170
-const inputStyle = ref(tools.style.input)
23
+const { proxy } = getCurrentInstance()
171 24
 
25
+// 查询参数
26
+const query = ref({
27
+  customerNm: ''
28
+})
172 29
 
173
-
174
-const url = ref('/sto/Customer/query')
175
-
176
-/**
177
- *   查询
178
- */
179
-
30
+// 表单数据 - 确保包含所有动态配置的字段
180 31
 const form = ref({
181
-  customerNm: '',
182
-  customerShortNm: '',
183
-  contactPerson: '',
184
-  contactInfo: '',
185
-  defaultAddress: ''
186
-});
187
-
188
-const query = ref({
32
+  id: '',
189 33
   customerNm: '',
190 34
   customerShortNm: '',
191 35
   contactPerson: '',
192 36
   contactInfo: '',
193 37
   defaultAddress: ''
194 38
 })
195
-const tableData = ref([])
196
-const TableBoxRef = ref(null)
197
-const handleSearch = () => {
198
-  // TableBoxRef.value.search()
199
-  getTableData()
200
-}
201 39
 
40
+// 控制弹窗显示
41
+const dialog = ref(false)
202 42
 
43
+// 弹窗标题
44
+const dialogTitle = ref('新增客户')
203 45
 
46
+// 表格相关配置
47
+const url = ref('sto/Customer/query')
48
+const tName = ref('sto_customer')
49
+const pageType = ref(true)
204 50
 
205
-/**
206
- * 分页
207
- */
208
-const currentPage = ref(1)
209
-const totalRows = ref(0)
210
-const pageSizes = ref([ 10, 20, 30, 40])
211
-const pageSize = ref(10)
212
-const handleSizeChange = (val) => {
213
-  pageSize.value = val
214
-  getTableData()
215
-}
216
-const handleCurrentChange = (val) => {
217
-  currentPage.value = val
218
-  getTableData()
219
-}
220
-/**
221
- * 分页
222
- */
223
-
224
-
225
-/**
226
- * 新增
227
- */
228
-const dialogVisible = ref(false)
229
-const dialogVisibleEdit = ref(false)
230
-
231
-const ruleFormRef = ref()
232
-
233
-const rules = reactive({
234
-  customerNm: [
235
-    {required: true, message: '不允许为空', trigger: 'blur'},
236
-  ],
237
-  customerShortNm: [
238
-    {required: true, message: '不允许为空', trigger: 'blur'},
239
-  ],
240
-  contactPerson: [
241
-    {required: true, message: '不允许为空', trigger: 'blur'},
242
-  ],
243
-  contactInfo: [
244
-    {required: true, message: '不允许为空', trigger: 'blur'},
245
-  ],
246
-  // defaultAddress: [
247
-  //   {required: true, message: '不允许为空', trigger: 'blur'},
248
-  // ],
51
+// 组件引用
52
+const TableBoxRef = ref(null)
53
+const FormBoxRef = ref(null)
249 54
 
55
+// 监听弹窗状态
56
+watch(dialog, (newVal) => {
57
+  console.log('弹窗状态变化:', newVal)
250 58
 })
251 59
 
60
+// ========== 弹窗相关方法 ==========
61
+
62
+// 新增弹窗
252 63
 const insertDialog = () => {
64
+  console.log('打开新增弹窗')
65
+  
66
+  // 重置表单数据
253 67
   form.value = {
68
+    id: '',
254 69
     customerNm: '',
255 70
     customerShortNm: '',
256 71
     contactPerson: '',
257 72
     contactInfo: '',
258 73
     defaultAddress: ''
259 74
   }
260
-  dialogVisible.value = true
75
+  
76
+  dialogTitle.value = '新增客户'
77
+  dialog.value = true
78
+  
79
+  console.log('dialog.value:', dialog.value)
80
+  console.log('form.value:', form.value)
81
+}
82
+
83
+// 编辑弹窗(通过顶部按钮)
84
+const editDialog = () => {
85
+  if (TableBoxRef.value?.multipleSelection?.length > 0) {
86
+    const selectedRow = TableBoxRef.value.multipleSelection[0]
87
+    handleEdit(selectedRow)
88
+  } else {
89
+    ElMessage.warning('请先选择要编辑的行')
90
+  }
261 91
 }
262
-/**
263
- * 新增
264
- */
265
-
266
-
267
-/**
268
- * 保存、修改、删除
269
- */
270
-const refUpload = ref()
271
-
272
-const openDialog = () => {
273 92
 
93
+// 表格行编辑(通过表格内的编辑按钮)
94
+const handleEdit = (row) => {
95
+  console.log('编辑行数据:', row)
96
+  
97
+  // 确保所有字段都有值
98
+  form.value = {
99
+    id: row.id || '',
100
+    customerNm: row.customerNm || '',
101
+    customerShortNm: row.customerShortNm || '',
102
+    contactPerson: row.contactPerson || '',
103
+    contactInfo: row.contactInfo || '',
104
+    defaultAddress: row.defaultAddress || ''
105
+  }
106
+  
107
+  dialogTitle.value = '编辑客户'
108
+  dialog.value = true
109
+  
110
+  console.log('编辑弹窗已打开,form:', form.value)
274 111
 }
275 112
 
276
-
277
-const handleSave = (ruleFormRef) => {
278
-  if (!ruleFormRef) return
279
-  ruleFormRef.validate((valid) => {
280
-    if (valid) {
281
-      console.log('submit!')
282
-      var url = 'sto/Customer/save'
283
-      var param = {
284
-        json: JSON.stringify(form.value),
285
-
286
-      }
287
-      proxy.$axios.post(url, param).then(response => {
288
-        if (response.data.code == 0) {
289
-          ElMessage({
290
-            message: '保存成功',
291
-            type: 'success',
292
-          })
293
-          dialogVisibleEdit.value = false
294
-          handleSearch()
295
-        } else {
296
-          ElMessage({
297
-            type: 'error',
298
-            message: '操作失败' + response.data.msg
299
-          })
300
-        }
301
-      });
302
-    } else {
303
-      console.log('error submit!')
304
-      return false
113
+// 保存表单
114
+const handleSave = async (formData) => {
115
+  try {
116
+    const url = 'sto/Customer/save'
117
+    var param = {
118
+      json: JSON.stringify(formData),
305 119
     }
306
-  })
307
-};
308
-const handleInsert = (ruleFormRef) => {
309
-  if (!ruleFormRef) return
310
-  ruleFormRef.validate((valid) => {
311
-    if (valid) {
312
-      console.log('submit!')
313
-      var url = 'sto/Customer/save'
314
-      var param = {
315
-        json: JSON.stringify(form.value),
316
-
120
+    console.log(JSON.stringify(formData))
121
+    
122
+    proxy.$axios.post(url, param).then(response => {
123
+      if (response.data.code == 0) {
124
+        ElMessage({
125
+          message: '保存成功',
126
+          type: 'success',
127
+        })
128
+        dialog.value = false
129
+        handleSearch()
130
+      } else {
131
+        ElMessage({
132
+          type: 'error',
133
+          message: '操作失败' + response.data.msg
134
+        })
317 135
       }
318
-      console.log('form.value!' ,form.value)
319
-      proxy.$axios.post(url, param).then(response => {
320
-        if (response.data.code == 0) {
321
-          ElMessage({
322
-            message: '保存成功',
323
-            type: 'success',
324
-          })
325
-          dialogVisible.value = false
326
-          handleSearch()
327
-        } else {
328
-          ElMessage({
329
-            type: 'error',
330
-            message: '操作失败' + response.data.msg
331
-          })
332
-        }
333
-      });
334
-    } else {
335
-      console.log('error submit!')
336
-      return false
337
-    }
338
-  })
339
-};
340
-
341
-const handleCancelSave = () => {
342
-  dialogVisible.value = false
343
-}
344
-const handleCancelSave2 = () => {
345
-  dialogVisibleEdit.value = false
136
+    });
137
+  } catch (error) {
138
+    ElMessage.error('操作失败: ' + error.message)
139
+    console.error('保存失败:', error)
140
+  }
346 141
 }
347 142
 
348
-const handleEdit = (row) => {
349
-  var url = 'sto/Customer/queryByPK'
350
-  var param = {
351
-    id: row.id
143
+// ========== 表格相关方法 ==========
144
+
145
+// 搜索
146
+const handleSearch = () => {
147
+  //console.log('执行搜索')
148
+  if (TableBoxRef.value?.search) {
149
+    TableBoxRef.value.search()
352 150
   }
353
-  proxy.$axios.get(url, param).then(response => {
354
-    if (response.data.code == '0') {
355
-      form.value = response.data.data
356
-      console.log(form.value)
357
-      dialogVisibleEdit.value = true
358
-    } else {
359
-      ElMessage.error('操作失败!' + response.data.msg)
360
-    }
361
-  })
362 151
 }
363 152
 
153
+// 删除处理
364 154
 const handleRemove = (row) => {
365 155
   var url = 'sto/Customer/remove'
366 156
   var param = {
367 157
     id: row.id
368 158
   }
369
-  ElMessageBox.confirm(
370
-      '确定删除本条记录?',
371
-      '提示', {
372
-        confirmButtonText: '确认',
373
-        cancelButtonText: '取消',
374
-        type: 'warning',
375
-        draggable: true,
376
-      }
377
-  )
378
-      .then(() => {
379
-        proxy.$axios.get(url, param).then(response => {
380
-          if (response.data.code == '0') {
381
-            console.log(response.data.data)
382
-            ElMessage({
383
-              type: 'success',
384
-              message: '删除成功!',
385
-            });
386
-            getTableData()
387
-          } else {
388
-            ElMessage.error('操作失败!' + response.data.msg)
389
-          }
390
-        })
391
-      })
392
-      .catch(() => {
393
-        ElMessage({
394
-          type: 'info',
395
-          message: '已取消',
396
-        })
397
-      })
398
-
399
-
400
-}
401
-
402
-
403
-/**
404
- * 保存、修改、删除
405
- */
406
-
407
-const multipleSelection = ref([])
408
-const handleSelectionChange = (val) => {
409
-  multipleSelection.value = val
410
-}
411
-
412
-const handleRemoveBatch = () => {
413
-  console.log('handleRemoveBatch')
414
-
415
-  if (multipleSelection.value.length < 1) {
416
-    ElMessage({
417
-      type: 'warning',
418
-      message: '请选择要删除的数据!'
419
-    })
420
-    return
421
-  }
422
-
423
-  ElMessageBox.confirm('此操作将删除该数据, 是否继续?', '提示', {
159
+  ElMessageBox.confirm(`确定删除客户 "${row.customerNm}" 吗?`, '删除确认', {
424 160
     confirmButtonText: '确定',
425 161
     cancelButtonText: '取消',
426 162
     type: 'warning'
427
-  }).then(() => {
428
-    var ids = []
429
-    multipleSelection.value.forEach((item, index) => {
430
-      ids.push(item.id)
431
-    })
432
-    /* var url = 'cot/SignRequest/removeBatch'*/
433
-    var param = {
434
-      ids: JSON.stringify(ids)
163
+  }).then(async () => {
164
+    try {
165
+      proxy.$axios.get(url, param).then(response => {
166
+        if (response.data.code == '0') {
167
+          console.log(response.data.data)
168
+          ElMessage({
169
+            type: 'success',
170
+            message: '删除成功!',
171
+          });
172
+          handleSearch()
173
+        } else {
174
+          ElMessage.error('操作失败!' + response.data.msg)
175
+        }
176
+      })
177
+    } catch (error) {
178
+      ElMessage.error('删除失败: ' + error.message)
435 179
     }
436
-    proxy.$axios.post(url, param).then(response => {
437
-      if (response.data.code == '0') {
438
-        ElMessage({
439
-          type: 'success',
440
-          message: '操作成功!',
441
-        });
442
-        getTableData()
443
-        dialogVisible.value = false
444
-      } else {
445
-        ElMessage({
446
-          type: 'error',
447
-          message: '操作失败!' + response.data.msg
448
-        });
449
-      }
450
-    })
451
-  }).catch(() => {
452
-    ElMessage({
453
-      type: 'info',
454
-      message: '已取消删除'
455
-    })
456 180
   })
457 181
 }
458 182
 
459
-const handleEditBatch = () => {
460
-  console.log('handleEditBatch')
461
-  if (multipleSelection.value.length != 1) {
462
-    ElMessage({
463
-      type: 'warning',
464
-      message: '请选择一条数据编辑!'
465
-    })
466
-    return
467
-  }
468
-  handleEdit(multipleSelection.value[0])
183
+// 行选择变化
184
+const handleSelectionChange = (selectedRows) => {
185
+  console.log('选中行:', selectedRows)
469 186
 }
470 187
 
471
-const handleUpload = () => {
472
-  console.log('handleUpload')
473
-}
188
+// ========== 其他方法 ==========
474 189
 
475
-const handleDownload = () => {
476
-  console.log('handleDownload')
190
+const reset = () => {
191
+  query.value = { customerNm: '' }
192
+  handleSearch()
477 193
 }
478 194
 
479
-const handleImport = () => {
480
-  console.log('handleImport')
481
-}
482
-
483
-const handleExport = () => {
484
-  console.log('handleExport')
485
-}
486
-const getTableData = () => {
487
-  var url = 'sto/Customer/query'
488
-  var param = {
489
-    page: currentPage.value,
490
-    rows: pageSize.value,
491
-    customerNm: query.value.customerNm,
492
-    customerShortNm: query.value.customerShortNm,
493
-    contactPerson: query.value.contactPerson,
494
-    contactInfo: query.value.contactInfo,
495
-    defaultAddress: query.value.defaultAddress,
496
-    json: JSON.stringify(query.value)
497
-  }
498
-  proxy.$axios.get(url, param).then(response => {
499
-    if (response.data.code == '0') {
500
-      tableData.value = response.data.data.records
501
-      totalRows.value = response.data.data.total
502
-    } else {
503
-      ElMessage.error('操作失败!' + response.data.msg)
504
-    }
505
-  })
195
+const start = (type) => {
196
+  console.log('启用操作:', type)
197
+  // TODO: 实现启用逻辑
506 198
 }
507
-const height = ref(600)
508
-const updateViewportHeight = () => {
509
-  height.value = window.innerHeight * 0.65
510
-  console.log( window.innerHeight);
511
-};
512
-onMounted(() => {
513
-  getTableData()
514
-  updateViewportHeight()
515
-})
516
-</script>
517 199
 
518
-<style scoped>
519
-::v-deep .diaClass .el-form-item {
520
-  width: 100%
521
-}
522
-::v-deep .el-autocomplete{
523
-  width: 100%;
524
-}
525
-::v-deep .el-dialog__body {
526
-  background-color: #F2F6FC;
200
+const shutdwon = (type) => {
201
+  console.log('停用操作:', type)
202
+  // TODO: 实现停用逻辑
527 203
 }
528
-</style>
204
+</script>

Завантаження…
Відмінити
Зберегти