Blame view

antis-ncc-admin/src/views/lqTkjlb/Form.vue 10.8 KB
96009bc9   hexiaodong   hxd
1
  <template>
557dc5cd   李宇   最新
2
  	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="600px" v-loading="loading">
96009bc9   hexiaodong   hxd
3
4
  		<el-row :gutter="15" class="" >
  				<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
557dc5cd   李宇   最新
5
6
7
8
9
  					<el-col :span="24">
  						<el-form-item label="拓客活动" prop="eventId">
  							<el-select v-model="dataForm.eventId" placeholder="请选择拓客活动" clearable :style='{"width":"100%"}' filterable >
  								<el-option v-for="(item, index) in tkhdOptions" :key="index" :label="item.EventName" :value="item.EventId" ></el-option>
  							</el-select>
96009bc9   hexiaodong   hxd
10
11
12
  						</el-form-item>
  					</el-col>
  					<el-col :span="24">
557dc5cd   李宇   最新
13
14
  						<el-form-item label="拓客人员" prop="expansionUserId">
  							<user-select v-model="dataForm.expansionUserId" placeholder="请选择" clearable >
96009bc9   hexiaodong   hxd
15
16
17
  							</user-select>
  						</el-form-item>
  					</el-col>
557dc5cd   李宇   最新
18
19
20
  					<!-- <el-col :span="24">
  						<el-form-item label="拓客时间" prop="expansionTime">
  							<el-date-picker v-model="dataForm.expansionTime" placeholder="请选择" :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" readonly disabled >
96009bc9   hexiaodong   hxd
21
22
  							</el-date-picker>
  						</el-form-item>
557dc5cd   李宇   最新
23
  					</el-col> -->
96009bc9   hexiaodong   hxd
24
  					<el-col :span="24">
557dc5cd   李宇   最新
25
26
  						<el-form-item label="顾客姓名" prop="customerName">
  							<el-input v-model="dataForm.customerName" placeholder="请输入" clearable :style='{"width":"100%"}' >
96009bc9   hexiaodong   hxd
27
28
29
30
  							</el-input>
  						</el-form-item>
  					</el-col>
  					<el-col :span="24">
557dc5cd   李宇   最新
31
32
  						<el-form-item label="电话号码" prop="customerPhone">
  							<el-input v-model="dataForm.customerPhone" placeholder="请输入" clearable :style='{"width":"100%"}' >
96009bc9   hexiaodong   hxd
33
34
35
  							</el-input>
  						</el-form-item>
  					</el-col>
2d733a6a   李宇   最新
36
  					<!-- <el-col :span="24">
557dc5cd   李宇   最新
37
38
  						<el-form-item label="购买张数" prop="buyNumber">
  							<el-input v-model="dataForm.buyNumber" placeholder="请输入" clearable :style='{"width":"100%"}' >
96009bc9   hexiaodong   hxd
39
40
  							</el-input>
  						</el-form-item>
2d733a6a   李宇   最新
41
  					</el-col> -->
96009bc9   hexiaodong   hxd
42
  					<el-col :span="24">
557dc5cd   李宇   最新
43
44
  						<el-form-item label="支付方式" prop="paymentMethod">
  							<el-select v-model="dataForm.paymentMethod" placeholder="请选择" clearable :style='{"width":"100%"}' filterable >
96009bc9   hexiaodong   hxd
45
46
47
48
49
  								<el-option v-for="(item, index) in zffsOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
  							</el-select>
  						</el-form-item>
  					</el-col>
  					<el-col :span="24">
557dc5cd   李宇   最新
50
51
  						<el-form-item label="是否加微信" prop="isAddWeChat">
  							<el-select v-model="dataForm.isAddWeChat" placeholder="请选择" clearable :style='{"width":"100%"}' >
96009bc9   hexiaodong   hxd
52
53
54
55
56
  								<el-option v-for="(item, index) in sfjwxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
  							</el-select>
  						</el-form-item>
  					</el-col>
  					<el-col :span="24">
557dc5cd   李宇   最新
57
58
  						<el-form-item label="备注" prop="remarks">
  							<el-input v-model="dataForm.remarks" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
96009bc9   hexiaodong   hxd
59
60
61
62
63
64
  							</el-input>
  						</el-form-item>
  					</el-col>
  				</el-form>
  		</el-row>
  		<span slot="footer" class="dialog-footer">
557dc5cd   李宇   最新
65
66
  			<el-button @click="visible = false" :disabled="loading">取 消</el-button>
  			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail" :loading="loading">确 定</el-button>
96009bc9   hexiaodong   hxd
67
68
69
70
71
72
73
  		</span>
  	</el-dialog>
  </template>
  <script>
  	import request from '@/utils/request'
  	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
  	import { previewDataInterface } from '@/api/systemData/dataInterface'
557dc5cd   李宇   最新
74
75
  	import { getLqEventList } from '@/api/extend/lqevent'
  	import { UserSettingInfo } from '@/api/permission/userSetting'
96009bc9   hexiaodong   hxd
76
77
78
79
80
81
82
83
  	export default {
  		components: {},
  		props: [],
  		data() {
  			return {
  				loading: false,
  				visible: false,
  				isDetail: false,
557dc5cd   李宇   最新
84
85
86
87
88
89
90
91
92
93
94
95
96
  						dataForm: {
  							id: undefined,
  							eventId: undefined,
  							expansionUserId: undefined,
  							// expansionTime: this.getCurrentTimestamp(),
  							expansionTime: undefined,
  							customerName: undefined,
  							customerPhone: undefined,
  							buyNumber: 1,
  							paymentMethod: '微信',
  							isAddWeChat: '否',
  							remarks: undefined,
  						},
96009bc9   hexiaodong   hxd
97
  				rules: {
557dc5cd   李宇   最新
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  					eventId: [
  						{ required: true, message: '请选择拓客活动', trigger: 'change' }
  					],
  					expansionUserId: [
  						{ required: true, message: '请选择拓客人员', trigger: 'change' }
  					],
  					customerName: [
  						{ required: true, message: '请输入顾客姓名', trigger: 'blur' }
  					],
  					customerPhone: [
  						{ required: true, message: '请输入电话号码', trigger: 'blur' },
  						{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
  					],
  					buyNumber: [
  						{ required: true, message: '请输入购买张数', trigger: 'blur' },
  						{ pattern: /^[1-9]\d*$/, message: '请输入正确的购买张数', trigger: 'blur' }
  					]
96009bc9   hexiaodong   hxd
115
116
117
  				},
  				zffsOptions:[{"fullName":"微信","id":"微信"},{"fullName":"支付宝","id":"支付宝"},{"fullName":"现金","id":"现金"},{"fullName":"银行转账","id":"银行转账"}],
  				sfjwxOptions:[{"fullName":"是","id":"是"},{"fullName":"否","id":"否"}],
557dc5cd   李宇   最新
118
119
  				tkhdOptions:[],
  				userinfo: {},
96009bc9   hexiaodong   hxd
120
121
122
123
124
  			}
  		},
  		computed: {},
          watch: {},
          created() {
557dc5cd   李宇   最新
125
  			this.int()
96009bc9   hexiaodong   hxd
126
127
128
129
  		},
  		mounted() {
          },
  		methods: {
557dc5cd   李宇   最新
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
  			// 获取当前时间戳
  			getCurrentTimestamp() {
  				return new Date().getTime()
  			},
  			int() {
  				UserSettingInfo().then(response => {
  					this.userinfo = response.data
  					this.dataForm.expansionUserId = this.userinfo.id
  					this.getTkhdOptions()
  				})
  			},
  			// 获取拓客活动选项
  			getTkhdOptions() {
  				// 获取当前日期作为查询参数
  				const today = new Date()
  				const startTime = this.formatDate(today)
  				const endTime = this.formatDate(today)
  				
  				request({
  					url: '/api/Extend/lqevent/user/'+this.userinfo.id+'/current',
  					method: 'GET'
  				}).then(response => {
  					if (response.code === 200 && response.data) {
  						this.tkhdOptions = response.data || []
  						// 默认选择第一个活动
  						if (this.tkhdOptions.length > 0 && !this.dataForm.eventId) {
  							this.dataForm.eventId = this.tkhdOptions[0].EventId
  						}
  					}
  				})
  			},
  			
  			// 格式化日期为 YYYY-MM-DD 格式
  			formatDate(date) {
  				const year = date.getFullYear()
  				const month = String(date.getMonth() + 1).padStart(2, '0')
  				const day = String(date.getDate()).padStart(2, '0')
  				return `${year}-${month}-${day} `
  			},
96009bc9   hexiaodong   hxd
169
170
171
172
173
174
175
176
177
  			goBack() {
                  this.$emit('refresh')
              },
  			init(id, isDetail) {
  				this.dataForm.id = id || 0;
                  this.visible = true;
                  this.isDetail = isDetail || false;
  				this.$nextTick(() => {
  					this.$refs['elForm'].resetFields();
557dc5cd   李宇   最新
178
179
180
181
182
183
184
185
  					// 如果是新建记录,重新设置当前时间和默认活动
  					if (!this.dataForm.id) {
  						this.dataForm.expansionTime = this.getCurrentTimestamp()
  						// 设置默认活动
  						if (this.tkhdOptions.length > 0) {
  							this.dataForm.eventId = this.tkhdOptions[0].EventId
  						}
  					}
96009bc9   hexiaodong   hxd
186
  					if (this.dataForm.id) {
557dc5cd   李宇   最新
187
  						this.loading = true
96009bc9   hexiaodong   hxd
188
189
190
191
  						request({
  							url: '/api/Extend/LqTkjlb/' + this.dataForm.id,
  							method: 'get'
  						}).then(res =>{
557dc5cd   李宇   最新
192
193
194
195
196
197
198
199
200
201
  							this.loading = false
  							if (res.code === 200 && res.data) {
  								this.dataForm = res.data;
  							} else {
  								this.$message.error('获取数据失败')
  							}
  						}).catch(err => {
  							this.loading = false
  							this.$message.error('获取数据失败,请重试')
  							console.error('获取拓客记录详情失败:', err)
96009bc9   hexiaodong   hxd
202
203
204
205
  						})
  					}
  				})
  			},
2d733a6a   李宇   最新
206
207
208
209
210
211
212
213
214
  			formatTime(time) {
  				return new Date(time).toLocaleString('zh-CN', {
  					year: 'numeric',
  					month: '2-digit',
  					day: '2-digit',
  					hour: '2-digit',
  					minute: '2-digit'
  				})
  			},
96009bc9   hexiaodong   hxd
215
216
217
  			dataFormSubmit() {
  				this.$refs['elForm'].validate((valid) => {
                      if (valid) {
557dc5cd   李宇   最新
218
  						this.loading = true
96009bc9   hexiaodong   hxd
219
220
221
222
223
224
                          if (!this.dataForm.id) {
                              request({
                                  url: `/api/Extend/LqTkjlb`,
                                  method: 'post',
                                  data: this.dataForm,
                              }).then((res) => {
557dc5cd   李宇   最新
225
  								this.loading = false
96009bc9   hexiaodong   hxd
226
                                  this.$message({
557dc5cd   李宇   最新
227
                                      message: res.msg || '创建成功',
96009bc9   hexiaodong   hxd
228
229
230
                                      type: 'success',
                                      duration: 1000,
                                      onClose: () => {
557dc5cd   李宇   最新
231
232
                                          this.visible = false
                                          this.$emit('refresh', true)
96009bc9   hexiaodong   hxd
233
234
                                      }
                                  })
2d733a6a   李宇   最新
235
236
  								let tkinfo = res.data;
  								let datanew = {
ca55440e   李宇   推送地址
237
  									"webhookUrl": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=496f1add-122b-43fc-9e38-0ca79c48b33f",
2d733a6a   李宇   最新
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  									"content": 
  `🎉 拓客记录
  ⏩门店:${tkinfo.storeinfo.Dm}
  ⏩拓客人员:${this.userinfo.realName || '未知'}
  ⏩战队:${tkinfo.entity.TeamName || '未知'}
  ⏩顾客姓名:${this.dataForm.customerName}
  ⏩电话号码:${this.dataForm.customerPhone}
  ⏩购买张数:${this.dataForm.buyNumber}
  ⏩拓客时间:${this.formatTime(tkinfo.entity.ExpansionTime)}
  ⏩支付方式:${this.dataForm.paymentMethod}
  ⏩是否加微信:${this.dataForm.isAddWeChat}
  ⏩备注:${this.dataForm.remarks || ''}`
  		
  								};
  								const resultnew = request({
  									url: 'http://wx.lvqianmeiye.com/api/Bot/send-text',
  									data: datanew,
  									method: 'POST'
  								});
557dc5cd   李宇   最新
257
258
259
260
261
                              }).catch(err => {
  								console.log(err)
  								this.loading = false
  								this.$message.error(err?err+'':'创建失败,请重试')
  							})
96009bc9   hexiaodong   hxd
262
263
264
265
266
267
                          } else {
                              request({
                                  url: '/api/Extend/LqTkjlb/' + this.dataForm.id,
                                  method: 'PUT',
                                  data: this.dataForm
                              }).then((res) => {
557dc5cd   李宇   最新
268
  								this.loading = false
96009bc9   hexiaodong   hxd
269
                                  this.$message({
557dc5cd   李宇   最新
270
                                      message: res.msg || '更新成功',
96009bc9   hexiaodong   hxd
271
272
273
274
275
276
277
                                      type: 'success',
                                      duration: 1000,
                                      onClose: () => {
                                          this.visible = false
                                          this.$emit('refresh', true)
                                      }
                                  })
557dc5cd   李宇   最新
278
279
280
281
282
                              }).catch(err => {
  								console.log(err)
  								this.loading = false
  								this.$message.error(err?err+'':'更新失败,请重试')
  							})
96009bc9   hexiaodong   hxd
283
284
285
286
287
288
289
                          }
                      }
                  })
  			},
  		}
  	}
  </script>