done update customer

parent 562a4487
......@@ -67,4 +67,6 @@ export enum API_PATHS {
getDetailField = 'field/detail',
getListPost = 'post',
deletePost = 'post/delete',
detailCustomer = 'customer/detail',
updateCustomer = 'customer/update',
}
......@@ -242,7 +242,7 @@ export type CustomerType = {
type: string;
representative: string;
position: string;
level: string;
level: CustomerLevelType;
};
export type CustomerLevelType = {
id: number;
......
......@@ -3,7 +3,6 @@ import { i18n } from 'src/boot/i18n';
import { isEmail } from '../../../boot/functions';
import { isMobilePhone } from '../../../boot/functions';
import { CustomerLevelType, CustomerType } from 'src/assets/type';
import { Notify } from 'quasar';
export default defineComponent({
props: {
......@@ -45,78 +44,77 @@ export default defineComponent({
const level: Ref<CustomerLevelType | null> = ref(null);
const confirmAddCustomer = () => {
let hasError = false;
// let hasError = false;
if (
props.listCustomers.filter((customer) => customer.code === code.value)
.length
) {
hasError = true;
Notify.create({
type: 'negative',
message: i18n.global.t('customer.validateMessages.codeExists'),
});
}
if (
props.listCustomers.filter(
(customer) => customer.userName === userName.value
).length
) {
hasError = true;
Notify.create({
type: 'negative',
message: i18n.global.t('customer.validateMessages.userNameExists'),
});
}
if (
props.listCustomers.filter(
(customer) => customer.taxCode === taxCode.value
).length
) {
hasError = true;
Notify.create({
type: 'negative',
message: i18n.global.t('customer.validateMessages.taxCodeExists'),
});
}
if (
props.listCustomers.filter((customer) => customer.email === email.value)
.length
) {
hasError = true;
Notify.create({
type: 'negative',
message: i18n.global.t('customer.validateMessages.emailExists'),
});
}
if (
props.listCustomers.filter((customer) => customer.phone === phone.value)
.length
) {
hasError = true;
Notify.create({
type: 'negative',
message: i18n.global.t('customer.validateMessages.phoneExists'),
});
}
if (!hasError) {
context.emit('addNewCustomer', {
code: code.value,
userName: userName.value,
fullName: fullName.value,
companyName: companyName.value,
taxCode: taxCode.value,
email: email.value,
status: status.value,
phone: phone.value,
password: password.value,
address: address.value,
type: type.value,
representative: representative.value,
position: position.value,
level: level.value,
});
}
// if (
// props.listCustomers.filter((customer) => customer.code === code.value)
// .length
// ) {
// hasError = true;
// Notify.create({
// type: 'negative',
// message: i18n.global.t('customer.validateMessages.codeExists'),
// });
// }
// if (
// props.listCustomers.filter(
// (customer) => customer.userName === userName.value
// ).length
// ) {
// hasError = true;
// Notify.create({
// type: 'negative',
// message: i18n.global.t('customer.validateMessages.userNameExists'),
// });
// }
// if (
// props.listCustomers.filter(
// (customer) => customer.taxCode === taxCode.value
// ).length
// ) {
// hasError = true;
// Notify.create({
// type: 'negative',
// message: i18n.global.t('customer.validateMessages.taxCodeExists'),
// });
// }
// if (
// props.listCustomers.filter((customer) => customer.email === email.value)
// .length
// ) {
// hasError = true;
// Notify.create({
// type: 'negative',
// message: i18n.global.t('customer.validateMessages.emailExists'),
// });
// }
// if (
// props.listCustomers.filter((customer) => customer.phone === phone.value)
// .length
// ) {
// hasError = true;
// Notify.create({
// type: 'negative',
// message: i18n.global.t('customer.validateMessages.phoneExists'),
// });
// }
// if (!hasError) {
context.emit('addNewCustomer', {
code: code.value,
userName: userName.value,
fullName: fullName.value,
companyName: companyName.value,
taxCode: taxCode.value,
email: email.value,
status: status.value,
phone: phone.value,
password: password.value,
address: address.value,
type: type.value,
representative: representative.value,
position: position.value,
level: level.value,
});
};
const resetData = () => {
code.value = null;
......
import { defineComponent } from 'vue';
import { defineComponent, PropType, Ref, ref, watch } from 'vue';
import { i18n } from 'src/boot/i18n';
import { isEmail } from '../../../boot/functions';
import { isMobilePhone } from '../../../boot/functions';
import { CustomerLevelType, CustomerType } from 'src/assets/type';
export default defineComponent({
props: {
......@@ -9,27 +10,92 @@ export default defineComponent({
type: Boolean,
required: true,
},
ratingsOptions: {type: Array, required: true},
businessTypeOptions: {type: Array, required: true},
userName: { type: String, required: true },
customerName: { type: String, required: true },
businessName: { type: String, required: true },
taxCode: { type: Number, required: true },
email: { type: String, required: true },
ratings: { type: String, required: true },
address: { type: String, required: true },
businessType: { type: String, required: true },
representative: { type: String, required: true },
position: { type: String, required: true },
phone: { type: String, required: true },
status: { type: Boolean, required: true },
levelOptions: {
type: Array as PropType<CustomerLevelType[]>,
required: true,
},
customerInfo: { type: Object as PropType<CustomerType>, required: true },
},
setup() {
setup(props, context) {
watch(
() => props.showDialogUpdate,
(value) => {
if (value) {
console.log(
props.customerInfo,
'customerInfocustomerInfocustomerInfo'
);
void getData();
}
}
);
const id: Ref<number | null> = ref(null);
const code: Ref<string | null> = ref(null);
const userName: Ref<string | null> = ref(null);
const fullName: Ref<string | null> = ref(null);
const companyName: Ref<string | null> = ref(null);
const taxCode: Ref<string | null> = ref(null);
const email: Ref<string | null> = ref(null);
const status: Ref<number | null> = ref(1);
const phone: Ref<string | null> = ref(null);
const password: Ref<string | null> = ref(null);
const address: Ref<string | null> = ref(null);
const type: Ref<string | null> = ref(null);
const representative: Ref<string | null> = ref(null);
const position: Ref<string | null> = ref(null);
const level: Ref<CustomerLevelType | null> = ref(null);
const confirmEditCustomer = () => {
context.emit('editCustomer', {
id: id.value,
code: code.value,
userName: userName.value,
fullName: fullName.value,
companyName: companyName.value,
taxCode: taxCode.value,
email: email.value,
status: status.value,
phone: phone.value,
password: password.value,
address: address.value,
type: type.value,
representative: representative.value,
position: position.value,
level: level.value,
});
};
const getData = () => {
id.value = props.customerInfo.id;
code.value = props.customerInfo.code;
userName.value = props.customerInfo.userName;
fullName.value = props.customerInfo.fullName;
companyName.value = props.customerInfo.companyName;
taxCode.value = props.customerInfo.taxCode;
email.value = props.customerInfo.email;
status.value = props.customerInfo.status;
phone.value = props.customerInfo.phone;
password.value = props.customerInfo.password;
address.value = props.customerInfo.address;
type.value = props.customerInfo.type;
representative.value = props.customerInfo.representative;
position.value = props.customerInfo.position;
level.value = props.customerInfo.level;
};
const userNameRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireUserName'),
];
const passwordRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requirePassword'),
];
const codeRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireCode'),
];
const customerNameRules = [
(val?: string) =>
(val && val.trim().length) ||
......@@ -41,18 +107,18 @@ export default defineComponent({
i18n.global.t('customer.validateMessages.requireBusinessName'),
];
const taxCodeRules = [
(val?: number) =>
val !== undefined ||
i18n.global.t('customer.validateMessages.requireTaxCode'),
];
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireTaxCode'),
];
const phoneRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requirePhone'),
(val: string) =>
isMobilePhone(val) ||
i18n.global.t('customer.validateMessages.isPhone'),
];
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requirePhone'),
(val: string) =>
isMobilePhone(val) ||
i18n.global.t('customer.validateMessages.isPhone'),
];
const emailRules = [
(val?: string) =>
(val && val.trim().length) ||
......@@ -66,54 +132,56 @@ export default defineComponent({
i18n.global.t('customer.validateMessages.requireAddress'),
];
const businessTypeRules = [
(val?: number) =>
val !== undefined ||
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireBusinessType'),
];
const ratingsRules = [
(val?: number) =>
val !== undefined ||
const levelRules = [
(val?: CustomerLevelType) =>
val !== null ||
i18n.global.t('customer.validateMessages.requireRatings'),
];
const representativeRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireRepresentative'),
];
const positionRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requiredPosition'),
];
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireRepresentative'),
];
const positionRules = [
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requiredPosition'),
];
return {
userNameRules,
customerNameRules,
businessNameRules,
passwordRules,
codeRules,
taxCodeRules,
emailRules,
ratingsRules,
levelRules,
addressRules,
businessTypeRules,
representativeRules,
positionRules,
phoneRules,
userName,
fullName,
companyName,
taxCode,
email,
status,
phone,
password,
address,
type,
representative,
position,
level,
code,
confirmEditCustomer,
id,
};
},
emits: [
'update:showDialogUpdate',
'click:CloseBtn',
'update:userName',
'update:customerName',
'update:businessName',
'update:taxCode',
'update:email',
'update:ratings',
'update:address',
'update:businessType',
'update:representative',
'update:position',
'update:phone',
'update:status',
'updateNewCustomer',
],
emits: ['update:showDialogUpdate', 'click:CloseBtn', 'editCustomer'],
});
......@@ -5,12 +5,12 @@
@update:model-value="$emit('update:showDialogUpdate', $event)"
>
<q-card style="min-width: 900px" bordered>
<q-form greedy @submit.prevent="$emit('updateNewCustomer')">
<q-form greedy @submit.prevent="confirmEditCustomer">
<q-card-section>
<q-item>
<q-item-section>
<q-item-label class="text-h6 text-weight-regular">{{
$t('customer.dialogLabel.title.updateCustomer')
$t('customer.dialogLabel.title.editCustomer')
}}</q-item-label>
</q-item-section>
</q-item>
......@@ -21,149 +21,138 @@
<div class="row q-col-gutter-sm">
<div class="col-6">
<q-input
:model-value="userName"
@update:model-value="$emit('update:userName', $event)"
v-model="userName"
:label="$t('customer.dialogLabel.fieldLabels.userName')"
:rules="userNameRules"
hide-bottom-space
type="text"
class="q-my-sm"
outlined
clearable
></q-input>
<q-input
:model-value="customerName"
@update:model-value="$emit('update:customerName', $event)"
v-model="password"
:label="$t('customer.dialogLabel.fieldLabels.password')"
:rules="passwordRules"
hide-bottom-space
type="password"
class="q-my-sm"
outlined
></q-input>
<q-input
v-model="code"
:label="$t('customer.dialogLabel.fieldLabels.code')"
:rules="codeRules"
hide-bottom-space
type="text"
class="q-my-sm"
outlined
></q-input>
<q-input
v-model="fullName"
:label="$t('customer.dialogLabel.fieldLabels.customerName')"
type="text"
class="q-my-sm"
outlined
:rules="customerNameRules"
hide-bottom-space
clearable
></q-input>
<q-input
:model-value="businessName"
@update:model-value="$emit('update:businessName', $event)"
v-model="companyName"
:label="$t('customer.dialogLabel.fieldLabels.businessName')"
type="text"
class="q-my-sm"
outlined
:rules="businessNameRules"
hide-bottom-space
clearable
></q-input>
<q-input
:model-value="taxCode"
@update:model-value="$emit('update:taxCode', $event)"
v-model="taxCode"
:label="$t('customer.dialogLabel.fieldLabels.taxCode')"
type="number"
type="text"
class="q-my-sm"
outlined
:rules="taxCodeRules"
hide-bottom-space
clearable
></q-input>
<q-input
:model-value="email"
@update:model-value="$emit('update:email', $event)"
:label="$t('customer.dialogLabel.fieldLabels.email')"
v-model="address"
:label="$t('customer.dialogLabel.fieldLabels.address')"
type="text"
class="q-my-sm"
:rules="addressRules"
outlined
:rules="emailRules"
hide-bottom-space
clearable
></q-input>
<q-select
:model-value="ratings"
@update:model-value="$emit('update:ratings', $event)"
:label="$t('customer.dialogLabel.fieldLabels.ratings')"
:options="ratingsOptions"
:rules="ratingsRules"
emit-value
map-options
option-value="id"
option-label="text"
type="text"
class="q-my-sm"
outlined
hide-bottom-space
clearable
></q-select>
</div>
<div class="col-6">
<q-input
:model-value="address"
@update:model-value="$emit('update:address', $event)"
:label="$t('customer.dialogLabel.fieldLabels.address')"
v-model="email"
:label="$t('customer.dialogLabel.fieldLabels.email')"
type="text"
class="q-my-sm"
:rules="addressRules"
outlined
:rules="emailRules"
hide-bottom-space
clearable
></q-input>
<q-select
:model-value="businessType"
@update:model-value="$emit('update:businessType', $event)"
<q-input
v-model="type"
:label="$t('customer.dialogLabel.fieldLabels.businessType')"
:options="businessTypeOptions"
:rules="businessTypeRules"
emit-value
map-options
option-value="id"
option-label="text"
type="text"
class="q-my-sm"
outlined
hide-bottom-space
></q-input>
<q-select
v-model="level"
:label="$t('customer.dialogLabel.fieldLabels.ratings')"
:options="levelOptions"
:rules="levelRules"
map-options
option-value="id"
option-label="name"
type="text"
class="q-my-sm"
outlined
clearable
hide-bottom-space
></q-select>
<q-input
:model-value="representative"
emit-value
@update:model-value="$emit('update:representative', $event)"
v-model="representative"
:label="$t('customer.dialogLabel.fieldLabels.representative')"
class="q-my-sm"
type="text"
outlined
:rules="representativeRules"
hide-bottom-space
clearable
></q-input>
<q-input
:model-value="position"
emit-value
@update:model-value="$emit('update:position', $event)"
v-model="position"
:label="$t('customer.dialogLabel.fieldLabels.position')"
class="q-my-sm"
type="text"
outlined
:rules="positionRules"
hide-bottom-space
clearable
></q-input>
<q-input
:model-value="phone"
emit-value
@update:model-value="$emit('update:phone', $event)"
v-model="phone"
:label="$t('customer.dialogLabel.fieldLabels.phone')"
class="q-my-sm"
type="number"
:rules="phoneRules"
outlined
hide-bottom-space
clearable
></q-input>
<div style="padding-top: 13px; padding-left: 12px">
<span class="text-body1">{{
$t('customer.dialogLabel.fieldLabels.status')
}}</span
><q-toggle
:model-value="status"
@update:model-value="$emit('update:status', $event)"
/>
><q-toggle :true-value="1" :false-value="2" v-model="status" />
</div>
</div>
</div>
......
......@@ -316,6 +316,7 @@ export default {
title: {
addCustomer: 'Thêm khách hàng',
updateCustomer: 'Cập nhật khách hàng',
editCustomer: 'Cập nhật thông tin khách hàng',
},
fieldLabels: {
userName: 'Tên đăng nhập *',
......
......@@ -544,9 +544,7 @@ export default defineComponent({
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
avatarUploaded.value =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
avatarUploaded.value = response.data.data.fileName;
}
} catch (error) {}
};
......@@ -561,9 +559,7 @@ export default defineComponent({
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const bannerUpload =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
const bannerUpload = response.data.data.fileName;
banners.value[index] = {
bannerUrl: bannerUpload,
};
......@@ -581,9 +577,7 @@ export default defineComponent({
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const urlStoryUpload =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
const urlStoryUpload = response.data.data.fileName;
stories.value[idxStory].imageUrl = urlStoryUpload;
}
} catch (error) {}
......
......@@ -110,6 +110,7 @@ export default defineComponent({
},
];
const userTableRowsCustomer: Ref<CustomerType[]> = ref([]);
const customerInfo: Ref<CustomerType | null> = ref(null);
const showDialog = ref(false);
const showDialogUpdate = ref(false);
const pageIndex = ref(1);
......@@ -254,32 +255,57 @@ export default defineComponent({
status.value = 2;
};
const getDetailCustomer = () => {
// gọi api chi tiết cần có id để lấy value cho từng customer
// const response = (await api({
// url: ...,
// method: 'GET',
// params: {
// id: id
// }
// }))
// gọi api lấy chi tiết sau đấy gán giá trị api trả về gán cho các biến userName customerName businessName taxCode...
const fakeDataDetail = {
userName: 'Sơn Tùng',
};
userName.value = fakeDataDetail.userName;
// Tương tự các biến còn lại
const getDetailCustomer = async (id: number) => {
try {
const response = (await api({
url: API_PATHS.detailCustomer,
method: 'GET',
params: {
id: id,
},
})) as AxiosResponse<BaseResponseBody<CustomerType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
customerInfo.value = response.data.data;
showDialogUpdate.value = true;
}
} catch (error) {}
};
const openUpdateCustomerDialog = (id: number) => {
showDialogUpdate.value = true;
console.log(id, 'iddd');
void getDetailCustomer();
void getDetailCustomer(id);
};
//Bấm nút lưu ở dialog update thì gọi api cập nhật trong hàm updateCustomer
const updateCustomer = () => {
//gọi api update
const updateCustomer = async (item: CustomerType) => {
try {
const response = (await api({
url: API_PATHS.updateCustomer,
method: 'POST',
data: {
id: item.id,
code: item.code,
userName: item.userName,
fullName: item.fullName,
companyName: item.companyName,
taxCode: item.taxCode,
email: item.email,
status: item.status,
phone: item.phone,
password: item.password,
address: item.address,
type: item.type,
representative: item.representative,
position: item.position,
level: item.level,
},
})) as AxiosResponse<BaseResponseBody<unknown>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
Notify.create({
type: 'positive',
message: i18n.global.t('artist.actionMessages.editArtistAccess'),
});
void getListCustomers();
showDialogUpdate.value = false;
}
} catch (error) {}
};
......@@ -323,6 +349,7 @@ export default defineComponent({
changePageSize,
getCustomerLevelOptions,
confirmDeleteCustomer,
customerInfo,
};
},
});
......@@ -134,25 +134,13 @@
@addNewCustomer="addCustomer"
></AddNewCustomerDialogComponent>
<!-- <UpdateNewCustomerDialogComponent
<UpdateNewCustomerDialogComponent
v-model:show-dialog-update="showDialogUpdate"
v-model:user-name="userName"
v-model:customer-name="customerName"
v-model:business-name="businessName"
v-model:tax-code="taxCode"
v-model:email="email"
v-model:ratings="ratings"
v-model:address="address"
v-model:business-type="businessType"
v-model:representative="representative"
v-model:position="position"
v-model:phone="phone"
v-model:status="status"
:ratings-options="ratingsOptions"
:business-type-options="businessTypeOptions"
:level-options="levelOptions"
:customer-info="customerInfo"
@click:CloseBtn="showDialogUpdate = false"
@updateNewCustomer="updateCustomer"
></UpdateNewCustomerDialogComponent> -->
@editCustomer="updateCustomer"
></UpdateNewCustomerDialogComponent>
</div>
</div>
</div>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment