Commit 3ee5840a authored by Kittisak Maneewong's avatar Kittisak Maneewong

update

parent eed7fd8e
...@@ -102,8 +102,12 @@ class CompanyController extends Controller ...@@ -102,8 +102,12 @@ class CompanyController extends Controller
*/ */
public function edit($id) public function edit($id)
{ {
$company = Company::where('user_id', $id)->first(); $exists = Company::where('user_id', $id)->exists();
return response()->json(['company' => $company]); if ($exists) {
return response()->json(['exists' => true, 'company' => Company::where('user_id', $id)->first()]);
} else {
return response()->json(['exists' => false, 'company' => User::where('id', $id)->first()]);
}
} }
/** /**
......
This diff is collapsed.
...@@ -124,30 +124,6 @@ router.beforeEach((to, from, next) => { ...@@ -124,30 +124,6 @@ router.beforeEach((to, from, next) => {
} else { } else {
next() next()
} }
} else if (to.matched.some(record => record.meta.loginEmployer)) {
if(!localStorage.getItem('access_token_employer')) {
next('/employer/login')
} else if (to.matched.some(record => record.meta.configProfile)) {
axios.get('/api/auth/current', {
headers: {
Authorization: `Bearer ${localStorage.getItem('access_token_employer')}`
}
})
.then(res => {
axios.get(`/api/companys/${res.data.user.id}/check`)
.then(res => {
if (res.data.exists) {
next()
} else {
next('/employer/configcompany')
}
})
.catch(err => {next()})
})
.catch(err => {next()})
} else {
next()
}
} else { } else {
next() next()
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<v-icon color="black">business</v-icon> ข้อมูลบริษัท <v-icon color="black">business</v-icon> ข้อมูลบริษัท
<v-divider></v-divider> <v-divider></v-divider>
</v-flex> </v-flex>
<v-form enctype="multipart/form-data" @submit.prevent="createJob()" ref="create"> <v-form enctype="multipart/form-data" @submit.prevent="configCompany()" ref="create">
<v-flex sm12 xs12> <v-flex sm12 xs12>
<v-layout row wrap class="ป pa-3"> <v-layout row wrap class="ป pa-3">
<v-flex sm4 xs12 class="px-3"> <v-flex sm4 xs12 class="px-3">
...@@ -246,6 +246,9 @@ export default { ...@@ -246,6 +246,9 @@ export default {
status: 'ยังไม่ได้เลือกไฟล์', status: 'ยังไม่ได้เลือกไฟล์',
nameImage: null, nameImage: null,
company_data: { company_data: {
currentImageCompany: null,
currentImageMap: null,
exists: false,
user_id: null, user_id: null,
imageCompany: 'https://asianinteriorservices.com/wp-content/uploads/2018/04/noImg.png', imageCompany: 'https://asianinteriorservices.com/wp-content/uploads/2018/04/noImg.png',
company_name: '', company_name: '',
...@@ -405,7 +408,7 @@ export default { ...@@ -405,7 +408,7 @@ export default {
this.company_data.imageMap = e.target.result this.company_data.imageMap = e.target.result
} }
}, },
createJob () { configCompany () {
this.loading = true this.loading = true
if (this.amphoes.findIndex(x => x.amphoe_code === this.amphoe.amphoe_code) === -1) {this.amphoe = ''} if (this.amphoes.findIndex(x => x.amphoe_code === this.amphoe.amphoe_code) === -1) {this.amphoe = ''}
if (this.tumbons.findIndex(x => x.tumbon_code === this.tumbon.tumbon_code) === -1) {this.tumbon = ''} if (this.tumbons.findIndex(x => x.tumbon_code === this.tumbon.tumbon_code) === -1) {this.tumbon = ''}
...@@ -414,16 +417,21 @@ export default { ...@@ -414,16 +417,21 @@ export default {
this.company_data.province = this.province.province this.company_data.province = this.province.province
this.company_data.amphoe = this.amphoe.amphoe this.company_data.amphoe = this.amphoe.amphoe
this.company_data.tumbon = this.tumbon.tumbon this.company_data.tumbon = this.tumbon.tumbon
axios.post('/api/companys', this.company_data) if (this.company_data.exists) {
.then(res => { console.log('true')
this.$router.push('/employer') } else {
this.loading = false console.log(false)
console.log(res) axios.post('/api/companys', this.company_data)
}) .then(res => {
.catch(err => { this.$router.push('/employer')
console.log(err.response) this.loading = false
this.loading = false console.log(res)
}) })
.catch(err => {
console.log(err.response)
this.loading = false
})
}
} else { } else {
this.$Loading.error() this.$Loading.error()
this.loading = false this.loading = false
...@@ -497,10 +505,63 @@ export default { ...@@ -497,10 +505,63 @@ export default {
beforeMount() { beforeMount() {
this.$store.dispatch('checkEmployer') this.$store.dispatch('checkEmployer')
.then(res => { .then(res => {
this.company_data.company_name = res.company_name axios.get(`/api/companys/${res.id}/edit`)
this.company_data.email = res.email_employers .then(res => {
this.company_data.phone_no = res.tel console.log(res)
this.company_data.user_id = res.id const data = res.data.company
if (res.data.exists) {
this.company_data.currentImageCompany = res.data.imageCompany
this.company_data.currentImageMap = res.data.imageMap
this.company_data.exists = res.data.exists
this.company_data.about = data.about
this.company_data.addr = data.addr
this.company_data.another = data.another
this.company_data.arl = data.arl
this.company_data.bts = data.bts
this.company_data.bus = data.bus
this.company_data.company_name = data.company_name
this.company_data.company_owner = data.company_owner
this.company_data.email = data.email
this.company_data.fax = data.fax
this.company_data.imageCompany = data.imageCompany
this.company_data.imageMap = data.imageMap
this.company_data.lat = data.lat*1
this.company_data.lng = data.long*1
this.company_data.mrt = data.mrt
this.company_data.phone_no = data.phone_no
this.company_data.website = data.website
this.company_data.user_id = data.user_id
if (this.company_data.lat) {
this.place = '_';
}
axios.get(`/api/${data.province}/${data.amphoe}/${data.tambon}/${data.zipcode}`)
.then(res => {
this.province = {
province: res.data.addr.province,
province_code: res.data.addr.province_code
}
this.amphoe = {
amphoe: res.data.addr.amphoe,
amphoe_code: res.data.addr.amphoe_code
}
this.tumbon = {
tumbon: res.data.addr.district,
tumbon_code: res.data.addr.district_code
}
this.showAmphoes()
this.showTumbons()
this.company_data.zip_code = data.zipcode
})
.catch(err => {console.log(err.response)})
} else {
this.company_data.company_name = data.company_name
this.company_data.email = data.email_employers
this.company_data.phone_no = data.tel
this.company_data.user_id = data.id
this.company_data.exists = res.data.exists
}
})
.catch(err => {console.log(err)})
}) })
} }
} }
......
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