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,61 +44,61 @@ 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) {
// 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,
......@@ -116,7 +115,6 @@ export default defineComponent({
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,8 +107,8 @@ export default defineComponent({
i18n.global.t('customer.validateMessages.requireBusinessName'),
];
const taxCodeRules = [
(val?: number) =>
val !== undefined ||
(val?: string) =>
(val && val.trim().length) ||
i18n.global.t('customer.validateMessages.requireTaxCode'),
];
const phoneRules = [
......@@ -66,13 +132,13 @@ 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 = [
......@@ -89,31 +155,33 @@ export default defineComponent({
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>
......
import { defineComponent, onMounted, ref, Ref } from 'vue';
import { defineComponent, onMounted, ref, Ref, watch } from 'vue';
import { api, BaseResponseBody } from 'src/boot/axios';
import { API_PATHS, config } from 'src/assets/configurations';
import { useRoute } from 'vue-router';
import { AxiosResponse } from 'axios';
// import moment from 'moment';
import moment from 'moment';
import { i18n } from 'src/boot/i18n';
import { Dialog, Notify } from 'quasar';
import { Router } from 'src/router';
......@@ -21,7 +21,7 @@ import UpdateHotProduct from 'components/artist-information/UpdateHotProduct/ind
import AddStory from 'components/artist-information/VAB-account/add-story/index.vue';
import {
// ArtistInfoType,
ArtistInfoType,
FieldType,
NationalityType,
ArtistLevelType,
......@@ -36,14 +36,13 @@ import {
TypeCardType,
FileUploadType,
} from 'src/assets/type';
import { isEmail } from '../../boot/functions';
import { isMobilePhone } from '../../boot/functions';
export type AvatarType = {
file?: File;
url?: string | null;
};
// export type Story = {
// story?:object |
// };
export default defineComponent({
components: {
PersonalInformation,
......@@ -91,19 +90,19 @@ export default defineComponent({
const avatarUploaded: Ref<string | null> = ref(null);
const artistCode: Ref<string> = ref('');
const fullName: Ref<string> = ref('');
const artistName: Ref<string | null | undefined> = ref();
const artistName: Ref<string | null> = ref(null);
const birthday: Ref<string | null> = ref(null);
const sex: Ref<number | undefined> = ref();
const sex: Ref<number | null> = ref(null);
const nationality: Ref<NationalityType | null> = ref(null);
const qualification: Ref<QualificationType | null> = ref(null);
const artistLevel: Ref<ArtistLevelType | null> = ref(null);
const address: Ref<string | null | undefined> = ref();
const address: Ref<string | null> = ref(null);
const status: Ref<number> = ref(1);
const fields: Ref<FieldType[]> = ref([]);
const works: Ref<WorkType[]> = ref([]);
const phoneNumber: Ref<string | null | undefined> = ref();
const email: Ref<string | null | undefined> = ref();
const facebook: Ref<string | null | undefined> = ref();
const phoneNumber: Ref<string | null> = ref(null);
const email: Ref<string | null> = ref(null);
const facebook: Ref<string | null> = ref(null);
const facebookMessage: Ref<string | null | undefined> = ref();
const instagram: Ref<string | null | undefined> = ref();
const whatsapp: Ref<string | null | undefined> = ref();
......@@ -121,12 +120,139 @@ export default defineComponent({
const rowBankAccIdx: Ref<number> = ref(0);
const rowDataAccBank: Ref<BankAccountType | null> = ref(null);
//satate hot product
//state hot product
const products: Ref<ProductType[]> = ref([]);
const statusHotProduct: Ref<number> = ref(2);
const DataInsertHotProduct: Ref<ProductType | null> = ref(null);
const DataUpdateHotProduct: Ref<ProductType | null> = ref(null);
//sate error input thong-tin-ca-nhan
const artistCodeRules = ref(false);
const fullNameRules = ref(false);
const artistNameRules = ref(false);
const birthdayRules = ref(false);
const emailRules = ref(false);
const addressRules = ref(false);
const phoneNumberRules = ref(false);
const sexRules = ref(false);
const nationalityRules = ref(false);
const fieldRules = ref(false);
const workRules = ref(false);
const qualificationRules = ref(false);
const artistLevelRules = ref(false);
const errorMessEmail = ref(
i18n.global.t('artist.artistInformation.validateMessages.requireEmail')
);
const errorMessPhoneNumber = ref(
i18n.global.t(
'artist.artistInformation.validateMessages.requirePhoneNumber'
)
);
watch(
() => artistCode.value,
(value) => {
if (value) {
artistCodeRules.value = false;
}
}
);
watch(
() => fullName.value,
(value) => {
if (value) {
fullNameRules.value = false;
}
}
);
watch(
() => artistName.value,
(value) => {
if (value) {
artistNameRules.value = false;
}
}
);
watch(
() => birthday.value,
(value) => {
if (value) {
birthdayRules.value = false;
}
}
);
watch(
() => email.value,
(value) => {
if (value) {
emailRules.value = false;
}
}
);
watch(
() => address.value,
(value) => {
if (value) {
addressRules.value = false;
}
}
);
watch(
() => phoneNumber.value,
(value) => {
if (value) {
phoneNumberRules.value = false;
}
}
);
watch(
() => sex.value,
(value) => {
if (value) {
sexRules.value = false;
}
}
);
watch(
() => nationality.value,
(value) => {
if (value) {
nationalityRules.value = false;
}
}
);
watch(
() => fields.value,
(value) => {
if (value) {
fieldRules.value = false;
}
}
);
watch(
() => works.value,
(value) => {
if (value) {
workRules.value = false;
}
}
);
watch(
() => qualification.value,
(value) => {
if (value) {
qualificationRules.value = false;
}
}
);
watch(
() => artistLevel.value,
(value) => {
if (value) {
artistLevelRules.value = false;
}
}
);
const getFieldOptions = async () => {
const response = (await api({
url: API_PATHS.getFieldOptions,
......@@ -261,6 +387,8 @@ export default defineComponent({
};
const selectedFile = (value: BannerType) => {
console.log(value, 'banners');
banners.value.push(value);
console.log(banners.value);
};
......@@ -295,7 +423,7 @@ export default defineComponent({
DataUpdateHotProduct.value = value;
};
const setAvatar = (value: BannerType) => {
console.log(value);
console.log(value, 'avatarFile');
avatarFile.value = value.file as File;
avatar.value = value.url as string;
};
......@@ -326,10 +454,7 @@ export default defineComponent({
const addStory = (value: StoriesType) => {
stories.value.push(value);
};
const UpdateBirtday = (value: string) => {
// console.log(value);
birthday.value = value;
console.log(stories, 'storiesstoriesstories');
};
const deleteStory = (idx: number) => {
......@@ -354,7 +479,12 @@ export default defineComponent({
stories.value.splice(idx, 1);
});
};
const UpdateBirtday = (value: string) => {
// console.log(value);
console.log(value, 'birthdayyyy');
birthday.value = value;
};
const callApiUploadAvatar = async (file: File) => {
try {
const bodyFormData = new FormData();
......@@ -366,9 +496,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) {}
};
......@@ -383,9 +511,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,
};
......@@ -403,19 +529,96 @@ 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) {}
};
const checkValidate = () => {
let hasError = false;
if (!artistCode.value || !artistCode.value?.trim().length) {
hasError = true;
artistCodeRules.value = true;
}
if (!fullName.value || !fullName.value?.trim().length) {
hasError = true;
fullNameRules.value = true;
}
if (!artistName.value || !artistName.value?.trim().length) {
hasError = true;
artistNameRules.value = true;
}
if (!address.value || !address.value.trim().length) {
hasError = true;
addressRules.value = true;
}
if (!birthday.value || !birthday.value?.trim().length) {
hasError = true;
birthdayRules.value = true;
}
if (sex.value === null) {
hasError = true;
sexRules.value = true;
}
if (!phoneNumber.value || !phoneNumber.value?.trim().length) {
hasError = true;
phoneNumberRules.value = true;
errorMessPhoneNumber.value = i18n.global.t(
'artist.artistInformation.validateMessages.requirePhoneNumber'
);
}
if (!isMobilePhone(phoneNumber.value as string)) {
hasError = true;
phoneNumberRules.value = true;
errorMessPhoneNumber.value = i18n.global.t(
'artist.artistInformation.validateMessages.isPhone'
);
}
if (!email.value || !email.value?.trim().length) {
hasError = true;
emailRules.value = true;
errorMessEmail.value = i18n.global.t(
'artist.artistInformation.validateMessages.requireEmail'
);
}
if (!isEmail(email.value as string)) {
hasError = true;
emailRules.value = true;
errorMessEmail.value = i18n.global.t(
'artist.artistInformation.validateMessages.isEmail'
);
}
if (artistLevel.value === null) {
hasError = true;
artistLevelRules.value = true;
}
if (!fields.value.length) {
hasError = true;
fieldRules.value = true;
}
if (nationality.value === null) {
hasError = true;
nationalityRules.value = true;
}
if (qualification.value === null) {
hasError = true;
qualificationRules.value = true;
}
if (!works.value.length) {
hasError = true;
workRules.value = true;
}
if (hasError === false) {
void addArtist();
}
};
const addArtist = async () => {
try {
if (avatarFile.value !== null) {
await callApiUploadAvatar(avatarFile.value);
}
} else avatarUploaded.value = avatar.value;
for (let index = 0; index < banners.value.length; index++) {
const element = banners.value[index];
if (element.file !== undefined) {
......@@ -428,6 +631,7 @@ export default defineComponent({
await callApiUploadStories(item.file, idx);
}
}
const response = (await api({
url: API_PATHS.addArtist,
method: 'POST',
......@@ -472,10 +676,6 @@ export default defineComponent({
}
} catch (error) {}
};
const deleteImagesStories = (value: number) => {
console.log(value, 'deleteImagesStories');
console.log(stories.value);
};
const DeleteItemStories = (value: StoriesType) => {
for (let i = 0; i < stories.value.length; i++) {
if (stories.value[i].id == value.id) {
......@@ -569,7 +769,6 @@ export default defineComponent({
avatar,
setAvatar,
deleteAvatar,
deleteImagesStories,
DeleteItemStories,
confirmDeleteSocialEmbedded,
changeEmbed,
......@@ -577,6 +776,22 @@ export default defineComponent({
addStory,
deleteStory,
UpdateBirtday,
checkValidate,
artistCodeRules,
fullNameRules,
artistNameRules,
birthdayRules,
emailRules,
addressRules,
phoneNumberRules,
sexRules,
nationalityRules,
fieldRules,
workRules,
qualificationRules,
artistLevelRules,
errorMessEmail,
errorMessPhoneNumber,
};
},
});
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