客户新增和编辑
parent
137a003eb0
commit
c6fae04a5b
|
@ -0,0 +1,4 @@
|
||||||
|
import axios from 'axios'
|
||||||
|
import qs from 'qs'
|
||||||
|
|
||||||
|
export const customerAdd = query => axios.post('http://oa-dxtc.test/customer/add', qs.stringify(query));
|
|
@ -0,0 +1,4 @@
|
||||||
|
import axios from 'axios'
|
||||||
|
import qs from 'qs'
|
||||||
|
|
||||||
|
export const customerEdit = query => axios.post('http://oa-dxtc.test/customer/edit', qs.stringify(query));
|
|
@ -5,8 +5,8 @@
|
||||||
<el-breadcrumb-item>
|
<el-breadcrumb-item>
|
||||||
<i class="el-icon-lx-cascades"></i> 客户列表
|
<i class="el-icon-lx-cascades"></i> 客户列表
|
||||||
</el-breadcrumb-item>
|
</el-breadcrumb-item>
|
||||||
<el-button type="primary">
|
<el-button size="small" type="primary" @click="handleAdd()">
|
||||||
<el-icon :size="20"><plus /></el-icon>
|
<el-icon size="small"><plus /></el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-breadcrumb>
|
</el-breadcrumb>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,36 +22,22 @@
|
||||||
|
|
||||||
<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
|
<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
|
||||||
<el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
|
<el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
|
||||||
<el-table-column prop="name" label="用户名"></el-table-column>
|
<el-table-column prop="company" label="公司名"></el-table-column>
|
||||||
<el-table-column label="账户余额">
|
<el-table-column prop="name" label="联系人姓名"></el-table-column>
|
||||||
<template #default="scope">¥{{ scope.row.money }}</template>
|
<el-table-column prop="telephone" label="联系人电话"></el-table-column>
|
||||||
</el-table-column>
|
<el-table-column prop="wechat" label="微信"></el-table-column>
|
||||||
<el-table-column label="头像(查看大图)" align="center">
|
<el-table-column prop="create_time" label="添加时间"></el-table-column>
|
||||||
<template #default="scope">
|
<el-table-column prop="user_name" label="添加人"></el-table-column>
|
||||||
<el-image class="table-td-thumb" :src="scope.row.thumb" :preview-src-list="[scope.row.thumb]">
|
|
||||||
</el-image>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column prop="address" label="地址"></el-table-column>
|
|
||||||
<el-table-column label="状态" align="center">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-tag :type="
|
|
||||||
scope.row.state === '成功'
|
|
||||||
? 'success'
|
|
||||||
: scope.row.state === '失败'
|
|
||||||
? 'danger'
|
|
||||||
: ''
|
|
||||||
">{{ scope.row.state }}</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column prop="date" label="注册时间"></el-table-column>
|
|
||||||
<el-table-column label="操作" width="180" align="center">
|
<el-table-column label="操作" width="180" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">编辑
|
<el-button type="text" @click="handleEdit(scope.$index, scope.row)">
|
||||||
|
<el-icon><edit-pen /></el-icon>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
|
<el-button type="text" class="red" @click="handleDelete(scope.$index, scope.row)">
|
||||||
|
<el-icon><delete /></el-icon>
|
||||||
|
删除
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="text" icon="el-icon-delete" class="red"
|
|
||||||
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
@ -62,13 +48,19 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 编辑弹出框 -->
|
<!-- 编辑弹出框 -->
|
||||||
<el-dialog title="编辑" v-model="editVisible" width="30%">
|
<el-dialog title="编辑" v-model="editVisible" width="40%">
|
||||||
<el-form label-width="70px">
|
<el-form :model="editForm" ref="tableEditData" :rules="rules" label-width="120px">
|
||||||
<el-form-item label="用户名">
|
<el-form-item label="公司名/客户名" prop="company">
|
||||||
<el-input v-model="form.name"></el-input>
|
<el-input v-model="editForm.company"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="地址">
|
<el-form-item label="联系人姓名" prop="name">
|
||||||
<el-input v-model="form.address"></el-input>
|
<el-input v-model="editForm.name"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="联系人电话" prop="telephone">
|
||||||
|
<el-input v-model="editForm.telephone"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="微信">
|
||||||
|
<el-input v-model="editForm.wechat"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
@ -78,6 +70,30 @@
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<!-- 添加弹出框 -->
|
||||||
|
<el-dialog title="新增" v-model="addVisible" width="40%">
|
||||||
|
<el-form :model="addForm" ref="tableAddData" label-width="120px" :rules="rules">
|
||||||
|
<el-form-item label="公司名/客户名" prop="company">
|
||||||
|
<el-input v-model="addForm.company"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="联系人姓名" prop="name">
|
||||||
|
<el-input v-model="addForm.name"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="联系人电话" prop="telephone">
|
||||||
|
<el-input v-model="addForm.telephone"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="微信">
|
||||||
|
<el-input v-model="addForm.wechat"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="addVisible = false">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="saveAdd">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -85,6 +101,8 @@
|
||||||
import { ref, reactive } from "vue";
|
import { ref, reactive } from "vue";
|
||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { customerData } from "../api/customer";
|
import { customerData } from "../api/customer";
|
||||||
|
import { customerAdd } from "../api/customerAdd";
|
||||||
|
import { customerEdit } from '../api/customerEdit';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "basetable",
|
name: "basetable",
|
||||||
|
@ -100,9 +118,8 @@ export default {
|
||||||
// 获取表格数据
|
// 获取表格数据
|
||||||
const getData = () => {
|
const getData = () => {
|
||||||
customerData(query).then((res) => {
|
customerData(query).then((res) => {
|
||||||
console.log(res);
|
tableData.value = res.data.data;
|
||||||
//tableData.value = res.data;
|
pageTotal.value = res.data.pageTotal || 0;
|
||||||
//pageTotal.value = res.pageTotal || 0;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
getData();
|
getData();
|
||||||
|
@ -130,40 +147,104 @@ export default {
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
const user = JSON.parse(localStorage.getItem('user'));
|
||||||
// 表格编辑时弹窗和保存
|
// 表格编辑时弹窗和保存
|
||||||
const editVisible = ref(false);
|
const editVisible = ref(false);
|
||||||
let form = reactive({
|
const tableEditData = ref(null);
|
||||||
name: "",
|
const editForm = reactive({
|
||||||
address: "",
|
company:'',
|
||||||
|
name:'',
|
||||||
|
telephone:'',
|
||||||
|
wechat:'',
|
||||||
|
userid:user.id,
|
||||||
|
id:0
|
||||||
});
|
});
|
||||||
let idx = -1;
|
let idx = -1;
|
||||||
const handleEdit = (index, row) => {
|
const handleEdit = (index, row) => {
|
||||||
idx = index;
|
idx = index;
|
||||||
Object.keys(form).forEach((item) => {
|
Object.keys(editForm).forEach((item) => {
|
||||||
form[item] = row[item];
|
editForm[item] = row[item];
|
||||||
});
|
});
|
||||||
editVisible.value = true;
|
editVisible.value = true;
|
||||||
};
|
};
|
||||||
const saveEdit = () => {
|
const saveEdit = () => {
|
||||||
editVisible.value = false;
|
tableEditData.value.validate((valid) => {
|
||||||
ElMessage.success(`修改第 ${idx + 1} 行成功`);
|
if(!valid){
|
||||||
Object.keys(form).forEach((item) => {
|
ElMessage.error('验证失败');
|
||||||
tableData.value[idx][item] = form[item];
|
return false;
|
||||||
|
}
|
||||||
|
customerEdit(editForm).then((res) => {
|
||||||
|
if(res.data.code == 0){
|
||||||
|
ElMessage.success(`修改第 ${idx + 1} 行成功`);
|
||||||
|
editVisible.value = false;
|
||||||
|
}else{
|
||||||
|
ElMessage.error(res.data.msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//新增
|
||||||
|
const addVisible = ref(false);
|
||||||
|
const rules = reactive({
|
||||||
|
company: [
|
||||||
|
{ required: true, message: "请输入公司名", trigger: "blur"},
|
||||||
|
],
|
||||||
|
name: [
|
||||||
|
{ required: true, message: "联系人姓名", trigger: "blur" },
|
||||||
|
],
|
||||||
|
telephone:[
|
||||||
|
{ required: true, message: "联系人电话", trigger: "blur" },
|
||||||
|
]
|
||||||
|
});
|
||||||
|
const tableAddData = ref(null);
|
||||||
|
const addForm = reactive({
|
||||||
|
company:'',
|
||||||
|
name:'',
|
||||||
|
telephone:'',
|
||||||
|
wechat:'',
|
||||||
|
userid:user.id
|
||||||
|
});
|
||||||
|
const handleAdd = () => {
|
||||||
|
addVisible.value = true;
|
||||||
|
};
|
||||||
|
const saveAdd = () => {
|
||||||
|
tableAddData.value.validate((valid) => {
|
||||||
|
if(!valid){
|
||||||
|
ElMessage.error('验证失败');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
customerAdd(addForm).then((res) => {
|
||||||
|
if(res.data.code == 0){
|
||||||
|
ElMessage.success("添加成功");
|
||||||
|
addVisible.value = false;
|
||||||
|
}else{
|
||||||
|
ElMessage.error(res.data.msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
query,
|
query,
|
||||||
tableData,
|
tableData,
|
||||||
|
tableAddData,
|
||||||
|
tableEditData,
|
||||||
pageTotal,
|
pageTotal,
|
||||||
editVisible,
|
editVisible,
|
||||||
form,
|
addVisible,
|
||||||
|
editForm,
|
||||||
|
addForm,
|
||||||
handleSearch,
|
handleSearch,
|
||||||
handlePageChange,
|
handlePageChange,
|
||||||
handleDelete,
|
handleDelete,
|
||||||
handleEdit,
|
handleEdit,
|
||||||
|
handleAdd,
|
||||||
saveEdit,
|
saveEdit,
|
||||||
|
saveAdd,
|
||||||
|
rules,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue