176 lines
5.5 KiB
Vue
176 lines
5.5 KiB
Vue
<template>
|
|
<div>
|
|
<CustomSubHeader>
|
|
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
|
<el-tag v-if="warranty._creator && warranty._creator.first_name" type="primary">
|
|
<span>ایجاد یا اصلاح کننده: </span>
|
|
<span> {{ warranty._creator.first_name + ' ' + warranty._creator.last_name }} </span>
|
|
</el-tag>
|
|
<CButton
|
|
size="sm"
|
|
color="primary"
|
|
class="mr-auto"
|
|
:to="{ name: 'admin-warranty-terms-page', params: { page: $route.params.page } }"
|
|
>برگشت به صفحه قبل</CButton
|
|
>
|
|
<CButton size="sm" color="success" style="margin-right: 10px" @click="upload">بروزرسانی</CButton>
|
|
</CustomSubHeader>
|
|
<CRow>
|
|
<CCol xl="6">
|
|
<CCard>
|
|
<CCardBody>
|
|
<CForm>
|
|
<CInput
|
|
v-model="warranty.title"
|
|
label="عنوان"
|
|
horizontal
|
|
:description="validation.title ? validation.title.msg : null"
|
|
:class="validation.title ? 'err' : null"
|
|
/>
|
|
|
|
<CTextarea
|
|
v-model="warranty.short_description"
|
|
label="توضیح کوتاه"
|
|
horizontal
|
|
rows="3"
|
|
:description="validation.short_description ? validation.short_description.msg : null"
|
|
:class="validation.short_description ? 'err' : null"
|
|
/>
|
|
|
|
<CRow form class="form-group" :class="validation.description ? 'err' : null">
|
|
<CCol tag="label" sm="3" class="col-form-label">توضیحات</CCol>
|
|
<CCol sm="9">
|
|
<client-only>
|
|
<ckeditor v-model="warranty.description" :config="editorConfig"></ckeditor>
|
|
</client-only>
|
|
<small v-if="validation.description" class="form-text text-muted w-100">
|
|
{{ validation.description.msg }}
|
|
</small>
|
|
</CCol>
|
|
</CRow>
|
|
</CForm>
|
|
</CCardBody>
|
|
</CCard>
|
|
</CCol>
|
|
<CCol xl="6">
|
|
<CCard>
|
|
<CCardBody>
|
|
<h1>تصویر:</h1>
|
|
<el-divider />
|
|
<CRow>
|
|
<CCol col="12" class="mb-3">
|
|
<img :src="warranty.image" alt="" style="width: 100%; max-width: 500px" />
|
|
</CCol>
|
|
<CCol col="1">
|
|
<span>کاور</span>
|
|
</CCol>
|
|
<CCol col="11">
|
|
<input ref="image" type="file" @change="preview" />
|
|
</CCol>
|
|
<CCol col="11" class="mr-auto mt-3">
|
|
<small v-if="validation.image" class="form-text alert-danger w-100">
|
|
{{ validation.image.msg }}
|
|
</small>
|
|
<small v-else class="form-text text-muted w-100"> عکس باید با نسبت 1:1 باشد. </small>
|
|
</CCol>
|
|
</CRow>
|
|
</CCardBody>
|
|
</CCard>
|
|
</CCol>
|
|
</CRow>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: 'AddminWarrantyTermDetails',
|
|
layout: 'admin',
|
|
async asyncData({ $axios, params, error }) {
|
|
try {
|
|
const warranty = await $axios.get(`/api/public/warranty/${params.item}`)
|
|
return {
|
|
warranty: warranty.data
|
|
}
|
|
} catch (e) {
|
|
error({ status: 404, message: 'Page not found' })
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
warranty: null,
|
|
editorConfig: {
|
|
language: 'fa',
|
|
extraPlugins: ['bidi', 'justify']
|
|
},
|
|
validation: {},
|
|
uploading: false,
|
|
uploadProgress: null
|
|
}
|
|
},
|
|
head() {
|
|
return {
|
|
title: this.title
|
|
}
|
|
},
|
|
computed: {
|
|
title() {
|
|
if (!this.uploading) {
|
|
return 'ویرایش شرایط گارانتی'
|
|
} else {
|
|
return this.uploadProgress
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
upload() {
|
|
this.validation = {}
|
|
const data = new FormData()
|
|
data.append('title', this.warranty.title)
|
|
data.append('short_description', this.warranty.short_description)
|
|
data.append('description', this.warranty.description)
|
|
if (this.$refs.image.files[0]) data.append('image', this.$refs.image.files[0])
|
|
|
|
const axiosConfig = {
|
|
onUploadProgress: progressEvent => {
|
|
this.uploading = true
|
|
this.uploadProgress = 'درحال آپلود ' + Math.floor((progressEvent.loaded / progressEvent.total) * 100) + '%'
|
|
|
|
if ((progressEvent.loaded / progressEvent.total) * 100 === 100) {
|
|
this.uploading = false
|
|
}
|
|
}
|
|
}
|
|
|
|
this.$axios
|
|
.put(`/api/admin/warranty/${this.warranty._id}`, data, axiosConfig)
|
|
.then(response => {
|
|
if (response.data) {
|
|
this.$message({
|
|
message: 'آیتم با موفقیت بروزرسانی شد.',
|
|
type: 'success'
|
|
})
|
|
this.$refs.image.value = null
|
|
this.warranty = response.data
|
|
}
|
|
})
|
|
.catch(error => {
|
|
if (error.response.status === 422) {
|
|
this.validation = error.response.data.validation
|
|
this.$message({
|
|
type: 'error',
|
|
message: 'اطلاعات رو بررسی و دوباره تلاش کنید'
|
|
})
|
|
} else {
|
|
this.$alert(error.response.data.message, 'خطا', {
|
|
confirmButtonText: 'باشه'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
preview(event) {
|
|
this.warranty.image = URL.createObjectURL(event.target.files[0])
|
|
}
|
|
}
|
|
}
|
|
</script>
|