sen
2025-09-10 b3540bbb650eda7ce2a846709ccdf84af2992fb3
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<template>
  <basicContainer>
    <avue-crud :option="option" :table-loading="pageF.loading" :data="tableData" :page="page"
      :permission="permissionList" :before-open="beforeOpen" v-model="form" ref="crudRef" @row-update="rowUpdate"
      @row-save="rowSave" @refresh-change="refreshChange" @row-del="rowDel" @search-change="searchChange"
      @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
      @size-change="sizeChange" @on-load="onLoad">
      <template #menu-left>
        <!-- <el-button type="success" icon="Edit" :disabled="pageF.single" v-hasPermi="['cwgl:smartLockerApplication:edit']"
          @click="handleUpdate">修改
        </el-button> -->
        <!-- <el-button type="danger" icon="Delete" :disabled="pageF.multiple" @click="handleDelete"
          v-hasPermi="['cwgl:smartLockerApplication:remove']">删除
        </el-button> -->
        <!-- <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['cwgl:smartLockerApplication:export']">导出
        </el-button> -->
      </template>
      <template #menu="{ size, row, index }">
 
        <el-link class="link-btn"  v-if="row.status == 0" type="primary" :underline="false" plain  @click="handleInvalid(row)"
          v-hasPermi="['cwgl:smartLockerApplication:invalid']"> 作废
        </el-link>
      </template>
    </avue-crud>
  </basicContainer>
</template>
 
<script setup name="smartLockerApplication" lang="ts">
import { SmartLockerApplicationI, addSmartLockerApplication, delSmartLockerApplication, exportSmartLockerApplication, getSmartLockerApplication, listSmartLockerApplication, updateSmartLockerApplication, smartLockerApplicationQuery,
  smartLockerApplicationInvalid
 } from "@/api/cwgl/smartLockerApplication";
import useCurrentInstance from "@/utils/useCurrentInstance";
import { computed, reactive, ref, toRefs } from "vue";
import { PagesInterface, PageQueryInterface } from "@/utils/globalInterface";
import { usePagePlus } from "@/hooks/usePagePlus";
import { hasPermission } from "@/utils/permissionUtils";
 
const { proxy } = useCurrentInstance();
const crudRef = ref();
 
const permissionList = computed(() => {
  return {
    addBtn: hasPermission(["cwgl:smartLockerApplication:add"]),
    delBtn: hasPermission(["cwgl:smartLockerApplication:remove"]),
    editBtn: hasPermission(["cwgl:smartLockerApplication:edit"]),
    viewBtn: hasPermission(["cwgl:smartLockerApplication:query"]),
  }
})
 
const data = reactive({
  form: <SmartLockerApplicationI>{},
  queryParams: <SmartLockerApplicationI & PageQueryInterface>{},
  page: <PagesInterface>{
    pageSize: 10,
    total: 0,
    currentPage: 1,
  },
  selectionList: [],
})
const { queryParams, form, page, selectionList } = toRefs(data);
const option = ref({
  pageKey: 'SmartLockerApplication',
  rowKey: 'id',
  searchLabelWidth: 100,
  labelWidth: 120,
  addBtn: true,     // 隐藏新增按钮
  editBtn: false,    // 隐藏编辑按钮
  viewBtn: false,
  delBtn: false,
 
  column: {
    // id: {
    //   label: 'ID',
    // },
    commandType: {
      label: '指令类型',
      search: true,
      minWidth: 120,
      dataType: 'string',
      type: 'select',
      // addDisplay: false,  // 新增时不显示
      // editDisplay: false, // 修改时不显示
      dicUrl: '/system/dict/data/type/sys_command_type',
    },
    applicantCode: {
      label: '申领人编码',
      minWidth: 180,
      rules: [
        {
          required: true,
          message: "申领人编码不能为空", trigger: "blur"
        }
      ],
    },
    applicantName: {
      label: '申领人姓名',
      minWidth: 180,
      rules: [
        {
          required: true,
          message: "申领人姓名不能为空", trigger: "blur"
        }
      ],
    },
    itemType: {
      label: '领取物品类型',
      search: true,
      minWidth: 120,
      dataType: 'string',
      type: 'select',
      rules: [
        {
          required: true,
          message: "领取物品类型不能为空", trigger: "change"
        }
      ],
      // addDisplay: false,  // 新增时不显示
      // editDisplay: false, // 修改时不显示
      dicUrl: '/system/dict/data/type/sys_item_type',
      change: (val: any) => {
        if (val.value === '1') {
          if (form.value.itemName !== '' && form.value.itemName !== undefined) {
 
          }
        }
 
      }
    },
    itemName: {
      label: '物品名称',
      showOverflowTooltip: true,
      minWidth: 180,
      rules: [
        {
          required: true,
          message: "物品名称不能为空", trigger: "blur"
        }
      ],
      change: (val: any) => {
        // 判断 itemType 是否为 '0',并且 itemName 有值
        if (form.value.itemType === '0' && val) {
          // 在这里添加你的请求接口逻辑
          debouncedItemNameChange(val.value);
          // 示例请求调用(需要替换为实际的API调用)
          // yourApiRequestFunction(val).then(response => {
          //   // 处理响应
          // }).catch(error => {
          //   // 处理错误
          // });
        }
      }
    },
    lockerNo: {
      label: '智能柜编号',
      minWidth: 180,
      rules: [
        {
          required: true,
          message: "智能柜编号不能为空", trigger: "blur"
        }
      ],
    },
    lockerPort: {
      label: '智能柜格口号',
      minWidth: 180,
      rules: [
        {
          required: true,
          message: "智能柜格口号不能为空", trigger: "blur"
        }
      ],
    },
    deadlineTime: {
      label: '领取截止时间',
      minWidth: 180,
      type: 'datetime',  // 改为 datetime 类型
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      addDisplay: true,  // 新增时不显示
      minWidth: 200,
        rules: [
        {
          required: true,
          message: "领取截止时间不能为空", trigger: "blur"
        }
      ],
    },
    cancelTime: {
      label: '作废时间',
      minWidth: 180,
      type: 'datetime',  // 改为 datetime 类型
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      addDisplay: false,  // 新增时不显示
 
      minWidth: 200,
    },
    receiveTime: {
      label: '领取时间',
      minWidth: 180,
      type: 'datetime',  // 改为 datetime 类型
      format: 'YYYY-MM-DD HH:mm:ss',
      addDisplay: false,  // 新增时不显示
 
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      minWidth: 200,
    },
    createTime: {
      label: '创建时间',
      minWidth: 180,
      addDisplay: false,  // 新增时不显示
 
      type: 'datetime',  // 改为 datetime 类型
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      minWidth: 200,
      rules: [
        {
          required: true,
          message: "创建时间不能为空", trigger: "blur"
        }
      ],
    },
    status: {
      label: '状态',
      search: true,
      minWidth: 120,
      fixed: 'right',
      dataType: 'string',
      type: 'select',
      addDisplay: false,  // 新增时不显示
      dicUrl: '/system/dict/data/type/sys_apply_status',
    },
    // updateTime: {
    //   label: '更新时间',
    // },
    // remark: {
    //   label: '备注',
    //   type: 'textarea', minRows: 3, maxRows: 5,
    // },
    // createBy: {
    //   label: '创建人',
    // },
    // updateBy: {
    //   label: '更新人',
    // },
    // deleted: {
    //   label: '删除标记(0:正常;1:删除)',
    // },
  }
})
 
const { tableData, pageF, rowSave, rowUpdate, rowDel, beforeOpen, searchChange,
  searchReset, selectionChange, onLoad, currentChange, sizeChange, handleDelete, handleExport, handleUpdate, refreshChange } = usePagePlus({
    form: form,
    option: option,
    queryParams: queryParams,
    idKey: 'id',
    page: page.value,
    getListApi: listSmartLockerApplication,
    getDetailApi: getSmartLockerApplication,
    exportApi: exportSmartLockerApplication,
    deleteApi: delSmartLockerApplication,
    addApi: addSmartLockerApplication,
    updateApi: updateSmartLockerApplication,
    handleUpdateFunc: () => {
      crudRef.value.rowEdit(selectionList.value[0]);
    },
    handleBeforeOpenFunc: (done: Function, type: string) => {
      if (done == 'add') {
        option.value.column.lockerNo.value = '接驳站智能钥匙柜'
        option.value.column.deadlineTime.value =formatDateTime(new Date(Date.now() + 24 * 60 * 60 * 1000));
       
        
      }
    },
    handleSelectionChangeFunc: (selection: any) => {
      selectionList.value = selection;
    }
  })
 
  const formatDateTime = (date) => {
  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}`;
};
// 在 script setup 部分定义防抖节流函数
let debounceTimer: NodeJS.Timeout | null = null;
let throttleTimer: NodeJS.Timeout | null = null;
// 防抖函数
const debounce = (func: Function, delay: number) => {
  return function (...args: any[]) {
    if (debounceTimer) {
      clearTimeout(debounceTimer);
    }
    debounceTimer = setTimeout(() => {
      func.apply(this, args);
    }, delay);
  };
};
 
// 节流函数
const throttle = (func: Function, delay: number) => {
  return function (...args: any[]) {
    if (!throttleTimer) {
      throttleTimer = setTimeout(() => {
        func.apply(this, args);
        throttleTimer = null;
      }, delay);
    }
  };
};
 
// 定义实际要执行的函数
const handleItemNameChange = (val: any) => {
  // 判断 itemType 是否为 '0',并且 itemName 有值
  if (form.value.itemType === '0' && val) {
    // 在这里添加你的请求接口逻辑
    smartLockerApplicationQuery({ licensePlateNumber: val }).then(response => {
      if(response.code == 200){
         form.value.lockerPort = response.data || '';
      }
      // 处理响应
    })
  }
};
 
// 创建防抖版本的函数(推荐使用防抖)
const debouncedItemNameChange = debounce(handleItemNameChange, 500);
const handleInvalid = (row: any) => {
  proxy.$modal.confirm(`是否作废该申领人编码 :${row.applicantCode}?`).then(function () {
    return smartLockerApplicationInvalid(row.id);
  }).then((res) => {
    onLoad(page.value);
    proxy.$modal.msgSuccess(res.msg);
  })
 
}
 
</script>