移动系统liao
2025-08-25 b1df5d6fdff809f634286ef7976d9b520cef7172
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
<script lang="ts" name="fBS_Customer" setup>
import { ref, reactive, onMounted } from "vue";
import type { FormRules } from "element-plus";
import { formatDate } from '/@/utils/formatTime';
import { useFBS_CustomerApi } from '/@/api/Customer/fBS_Customer';
import { useFBS_CusExtendApi } from '/@/api/Customer/fBS_CusExtend';
import { auth } from '/@/utils/authFunction';
import { ElMessageBox, ElMessage } from "element-plus";
import { downloadStreamFile } from "/@/utils/download";
import editDialog from '/@/views/Customer/fBS_CusExtend/component/fBS_Customer/component/editDialog.vue'
import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
import ModifyRecord from '/@/components/table/modifyRecord.vue';
import ImportData from "/@/components/table/importData.vue";
 
const fBS_CusExtendApi = useFBS_CusExtendApi();
 
const fBS_CustomerApi = useFBS_CustomerApi();
const printDialogRef = ref();
const editDialogRef = ref();
const importDataRef = ref();
const state = reactive({
    title: '',
    loading: false,
    showDialog: false,
    ruleForm: {} as any,
    stores: {},
    dropdownData: {} as any,
    exportLoading: false,
    tableLoading: false,
    showAdvanceQueryUI: false,
    selectData: [] as any[],
    tableQueryParams: {} as any,
    tableParams: {
        page: 1,
        pageSize: 20,
        total: 0,
        field: 'createTime', // 默认的排序字段
        order: 'descending', // 排序方向
        descStr: 'descending', // 降序排序的关键字符
    },
    tableData: [],
    listRow:{}
});
 
// 页面加载时
onMounted(async () => {
});
 
/**
 * 根据id对数组元素进行操作:存在则替换,不存在则添加,指定删除则移除
 * @param {Array} array - 要操作的原数组
 * @param {Object} item - 要操作的元素,必须包含id属性
 * @param {boolean} [deleteFlag=false] - 是否执行删除操作
 * @returns {Array} 处理后的数组
 */
function operateByid(array, item, deleteFlag = false) {
    // 检查元素是否包含id
    // if (!item || !('id' in item)) {
    //     console.warn('元素必须包含id属性');
    //     return [...array];
    // }
    
    // 创建原数组的副本,避免直接修改原数组
    const newArray = [...array];
    // 查找数组中是否存在相同id的元素
    const index = newArray.findIndex(i => i.id === item.id);
    
    if (deleteFlag) {
        // 如果需要删除且元素存在,则从数组中移除
        if (index !== -1) {
            newArray.splice(index, 1);
        }
    } else {
        if (index !== -1) {
            // 存在则替换
            newArray[index] = item;
        } else {
            // 不存在则添加
            newArray.push(item);
        }
    }
    
    return newArray;
}
// 查询操作
const handleQuery = async (params: any = {}, deleteFlag:false) => {
  state.tableLoading = true;
  state.tableData = operateByid(state.tableData,params,deleteFlag)
  console.log(params);
  
  state.tableLoading = false;
};
 
// 列排序
const sortChange = async (column: any) => {
  state.tableParams.field = column.prop;
  state.tableParams.order = column.order;
  await handleQuery();
};
 
// 删除
const delFBS_Customer = (row: any) => {
    console.log(row,'rowrow');
    
  ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(async () => {
    await fBS_CusExtendApi.delCustormerUser(row.id);
    handleQuery(row,true);
    ElMessage.success("删除成功");
  }).catch(() => {});
};
 
// 批量删除
const batchDelFBS_Customer = () => {
  ElMessageBox.confirm(`确定要删除${state.selectData.length}条记录吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(async () => {
    await fBS_CustomerApi.batchDelete(state.selectData.map(u => ({ id: u.id }) )).then(res => {
      ElMessage.success(`成功批量删除${res.data.result}条记录`);
      handleQuery();
    });
  }).catch(() => {});
};
 
// // 设置状态
// const changeFBS_CustomerStatus = async (row: any) => {
//   await fBS_CusExtendApi.setStatus({ id: row.id, status: row.status }).then(() => ElMessage.success('状态设置成功'));
// };
 
// 导出数据
const exportFBS_CustomerCommand = async (command: string) => {
  try {
    state.exportLoading = true;
    if (command === 'select') {
      const params = Object.assign({}, state.tableQueryParams, state.tableParams, { selectKeyList: state.selectData.map(u => u.id) });
      await fBS_CustomerApi.exportData(params).then(res => downloadStreamFile(res));
    } else if (command === 'current') {
      const params = Object.assign({}, state.tableQueryParams, state.tableParams);
      await fBS_CustomerApi.exportData(params).then(res => downloadStreamFile(res));
    } else if (command === 'all') {
      const params = Object.assign({}, state.tableQueryParams, state.tableParams, { page: 1, pageSize: 99999999 });
      await fBS_CustomerApi.exportData(params).then(res => downloadStreamFile(res));
    }
  } finally {
    state.exportLoading = false;
  }
}
 
handleQuery();
//父级传递来的函数,用于回调
const emit = defineEmits(["reloadTable"]);
const ruleFormRef = ref();
 
 
 
 
// 页面加载时
onMounted(async () => {
});
 
// 打开弹窗
const openDialog = async (row: any, title: string) => {
    state.title = title;
    let res = JSON.parse(JSON.stringify(row))
    state.tableData = res.custormerUsers
    state.listRow = row
    // state.ruleForm = row.id ? await fBS_CustomerApi.detail(row.id).then(res => res.data.result) : JSON.parse(JSON.stringify(row));
    state.showDialog = true;
};
 
// 关闭弹窗
const closeDialog = () => {
    emit("reloadTable");
    state.showDialog = false;
};
 
// 提交
const submit = async () => {
    closeDialog();
};
 
//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
<template>
    <div class="fBS_Customer-container">
        <el-dialog v-model="state.showDialog" :width="1200" draggable @close="closeDialog" :close-on-click-modal="false">
            <template #header>
                <div style="color: #fff">
                    <span>{{ state.title }}</span>
                </div>
            </template>
            <div class="flex-end">
                <el-button @click="editDialogRef.openDialog(null, '新增用户',state.listRow)" v-auth="'fBS_Customer:add'" type="primary" v-reclick="1000">新建</el-button>
            </div>
            <el-card class="full-table" shadow="hover" style="margin-top: 5px">
                <el-table :data="state.tableData" @selection-change="(val: any[]) => { state.selectData = val; }"
                    style="width: 100%" v-loading="state.tableLoading" tooltip-effect="light" row-key="id"
                    @sort-change="sortChange" border>
                    <el-table-column type="selection" width="40" align="center"
                        v-if="false" />
                    <!-- <el-table-column type="index" label="序号" width="55" align="center" /> -->
                    <el-table-column prop='name' label='姓名' sortable='custom' show-overflow-tooltip />
                    <el-table-column prop='isManager' label='角色' sortable='custom' show-overflow-tooltip >
                    <template #default="scope">
                        <el-switch 
                        disabled="disabled"
                        v-model="scope.row.isManager" 
                        :active-value='true'
                        :inactive-value='false'
                        active-text="管理员"
                        inactive-text="员工" 
                        size="small"
                        inline-prompt
                        />
                    </template>
                        </el-table-column>
                    <el-table-column prop='phoneNumber' label='手机号码' show-overflow-tooltip />
                    <el-table-column prop='isEn' label='是否启用' v-auth="'fBS_Customer:setStatus'" show-overflow-tooltip>
                        <template #default="scope">
                            <el-tag :type="scope.row.isEn?'primary':'error'">{{ scope.row.isEn?'是':'否' }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop='remark' label='备注' show-overflow-tooltip />
                    <el-table-column label="操作" width="70" align="center" fixed="right" show-overflow-tooltip
                        v-if="auth('fBS_Customer:update') || auth('fBS_Customer:delete')">
                        <template #default="scope">
                            <el-button icon="ele-Edit" size="small" text type="primary"
                                @click="editDialogRef.openDialog(scope.row, '编辑用户信息')" v-auth="'fBS_Customer:update'">
                            </el-button>
                            <el-button icon="ele-Delete" size="small" text type="primary"
                                @click="delFBS_Customer(scope.row)" v-auth="'fBS_Customer:delete'"> </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                
                <ImportData ref="importDataRef" :import="fBS_CustomerApi.importData"
                    :download="fBS_CustomerApi.downloadTemplate" v-auth="'fBS_Customer:import'"
                    @refresh="handleQuery" />
                <printDialog ref="printDialogRef" :title="'打印客户表'" @reloadTable="handleQuery" />
                <editDialog ref="editDialogRef" @reloadTable="handleQuery" />
            </el-card>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="submit">取 消</el-button>
                    <el-button @click="submit" type="primary" v-reclick="1000">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
    width: 100%;
}
</style>