From ae771d8df2405d955dabf79b349773694f34d05f Mon Sep 17 00:00:00 2001 From: "peggy.liu" Date: Fri, 4 Oct 2019 17:37:24 +0800 Subject: [PATCH 1/7] List, edit and delete project trip --- .../ProjectEdit/Trip/EditProjectTripBasic.vue | 52 ++- .../Trip/EditProjectTripCamera.vue | 28 +- .../ProjectEdit/Trip/ListProjectTrip.vue | 373 ++++++++++++++++++ src/main.js | 3 +- src/pages/Project/EditProject/Trip.vue | 73 +++- src/sass/globals/_page.sass | 39 ++ src/service/modules/trip.js | 17 +- src/store/modules/projects/trip.js | 39 +- 8 files changed, 574 insertions(+), 50 deletions(-) create mode 100644 src/components/ProjectEdit/Trip/ListProjectTrip.vue diff --git a/src/components/ProjectEdit/Trip/EditProjectTripBasic.vue b/src/components/ProjectEdit/Trip/EditProjectTripBasic.vue index 8b0aaa12..a61b0692 100644 --- a/src/components/ProjectEdit/Trip/EditProjectTripBasic.vue +++ b/src/components/ProjectEdit/Trip/EditProjectTripBasic.vue @@ -190,7 +190,7 @@ export default { openEditProjectTripCamera: { type: Function, }, - addProjectTripRequest: { + addEditProjectTripRequest: { type: Function, }, setEditProjectTrip: { @@ -301,9 +301,50 @@ export default { if (this.projectTripCameraLocations[value]) { cameraLocations = this.projectTripCameraLocations[value].map( cameraLocation => { + let cameraLocationEven = undefined; + let cameraLocationMark = undefined; + let projectCameras = undefined; + if ( + this.editProjectTripData.id && + this.editProjectTripData.studyAreas + ) { + this.editProjectTripData.studyAreas.some( + studyAreaData => { + if ( + studyAreaData.studyArea === value && + studyAreaData.cameraLocations + ) { + studyAreaData.cameraLocations.some( + cameraLocationData => { + if ( + cameraLocationData.cameraLocation === + cameraLocation.value && + cameraLocationData.projectCameras && + cameraLocationData.projectCameras.length > 0 + ) { + cameraLocationEven = + cameraLocationData.cameraLocationEven; + cameraLocationMark = + cameraLocationData.cameraLocationMark; + projectCameras = + cameraLocationData.projectCameras; + return true; + } + }, + ); + } + if (projectCameras) { + return true; + } + }, + ); + } return { cameraLocation: cameraLocation.value, title: cameraLocation.label, + cameraLocationEven: cameraLocationEven || '', + cameraLocationMark: cameraLocationMark || '', + projectCameras: projectCameras || [], }; }, ); @@ -320,13 +361,16 @@ export default { } const { sn, member, mark } = this.projectTrip; - const body = { + let body = { sn, member, mark, studyAreas, date: this.projectTripDate, }; + if (this.editProjectTripData.id) + body = { id: this.editProjectTripData.id, ...body }; + this.setEditProjectTrip(body); if (this.showNextStep) { @@ -355,13 +399,13 @@ export default { this.showCheckCameraLocationsModal = false; }, checkAddProjectTripRequest() { - this.addProjectTripRequest(true); + this.addEditProjectTripRequest(true); this.closeCheckStudyAreasModal(); this.closeEditProjectTripBasic(); }, checkGoEditProjectTripCamera() { if (this.showNextStep) this.openEditProjectTripCamera(); - else this.addProjectTripRequest(true); + else this.addEditProjectTripRequest(true); this.closeCheckCameraLocationsModal(); this.closeEditProjectTripBasic(); diff --git a/src/components/ProjectEdit/Trip/EditProjectTripCamera.vue b/src/components/ProjectEdit/Trip/EditProjectTripCamera.vue index 0cd3baeb..cad05758 100644 --- a/src/components/ProjectEdit/Trip/EditProjectTripCamera.vue +++ b/src/components/ProjectEdit/Trip/EditProjectTripCamera.vue @@ -117,7 +117,7 @@
0 - ) { - this.cmaeraLocationEvenOptions = ['設置', '替換']; - } else this.cmaeraLocationEvenOptions = ['設置']; - this.projectTrip.cameraLocationEven = this.cmaeraLocationEvenOptions[0]; await this.getProjectCameras({ projectId: this.projectId }); @@ -378,6 +371,7 @@ export default { const nextProjectTrip = this.editProjectTripBasic.studyAreas[ this.selectedStudyAreaIndex ].cameraLocations[this.selectedCameraLocationIndex]; + const projectCameras = nextProjectTrip.projectCameras ? { projectCameras: nextProjectTrip.projectCameras.map( @@ -391,8 +385,11 @@ export default { this.selectedStudyAreaIndex ].cameraLocations[this.selectedCameraLocationIndex].projectCameras; + this.cmaeraLocationEvenOptions = ['設置']; + if (nextTripCamerasDetail && nextTripCamerasDetail.length > 0) { this.tripCamerasDetail = nextTripCamerasDetail; + if ( this.projectTrip.projectCameras && this.projectTrip.projectCameras.length === 1 @@ -417,6 +414,9 @@ export default { }; } else this.endActiveTime = { HH: '00', mm: '00' }; } + + if (this.editProjectTripBasic.id) + this.cmaeraLocationEvenOptions = ['設置', '替換']; } else { this.tripCamerasDetail = [{}, {}]; this.startActiveTime = { HH: '00', mm: '00' }; @@ -466,6 +466,7 @@ export default { startActiveDate, endActiveDate, ); + return { cameraSn: value, ...currentTripCamera }; }, ); @@ -473,13 +474,12 @@ export default { } if (Object.keys(currentProjectTrip).length > 0) { - Object.assign( - this.editProjectTripBasic.studyAreas[this.selectedStudyAreaIndex] - .cameraLocations[this.selectedCameraLocationIndex], - currentProjectTrip, - ); + this.editProjectTripBasic.studyAreas[ + this.selectedStudyAreaIndex + ].cameraLocations[this.selectedCameraLocationIndex] = { + ...currentProjectTrip, + }; } - this.setEditProjectTrip(this.editProjectTripBasic); } }, diff --git a/src/components/ProjectEdit/Trip/ListProjectTrip.vue b/src/components/ProjectEdit/Trip/ListProjectTrip.vue new file mode 100644 index 00000000..7dce295c --- /dev/null +++ b/src/components/ProjectEdit/Trip/ListProjectTrip.vue @@ -0,0 +1,373 @@ + + + diff --git a/src/main.js b/src/main.js index b372280b..2cb8600b 100644 --- a/src/main.js +++ b/src/main.js @@ -7,6 +7,7 @@ import App from './App'; import router from './router'; import store from './store'; +import locale from 'element-ui/lib/locale/lang/zh-TW'; import './sass/app.sass'; import 'bootstrap'; import 'element-ui/lib/theme-chalk/index.css'; @@ -15,7 +16,7 @@ import 'vue2-dropzone/dist/vue2Dropzone.min.css'; Vue.use(VeeValidate); Vue.use(VTooltip); -Vue.use(ElementUI); +Vue.use(ElementUI, { locale }); Vue.config.productionTip = false; diff --git a/src/pages/Project/EditProject/Trip.vue b/src/pages/Project/EditProject/Trip.vue index c97bef8f..a2fb0374 100644 --- a/src/pages/Project/EditProject/Trip.vue +++ b/src/pages/Project/EditProject/Trip.vue @@ -8,13 +8,24 @@
+
+ +
@@ -59,7 +70,7 @@ :open="showCheckCameraDetailModal" title="您確定不填入相機資料嗎?" description="不填寫相機位置內的相機資料,往後將無法依據行程篩選資料." - @summit="addProjectTripRequest(true)" + @summit="addEditProjectTripRequest(true)" @close="closeCheckCameraDetailModal" /> @@ -70,6 +81,7 @@ import { createNamespacedHelpers } from 'vuex'; import DoubleCheckModalWithStyle from '@/components/Modal/DoubleCheckModalWithStyle.vue'; import EditProjectTripBasic from '@/components/ProjectEdit/Trip/EditProjectTripBasic.vue'; import EditProjectTripCamera from '@/components/ProjectEdit/Trip/EditProjectTripCamera.vue'; +import ListProjectTrip from '@/components/ProjectEdit/Trip/ListProjectTrip.vue'; const projectCamera = createNamespacedHelpers('projectCamera'); const studyAreas = createNamespacedHelpers('studyAreas'); @@ -80,6 +92,7 @@ export default { EditProjectTripBasic, EditProjectTripCamera, DoubleCheckModalWithStyle, + ListProjectTrip, }, data: function() { return { @@ -93,7 +106,7 @@ export default { computed: { ...projectCamera.mapState(['projectCameras']), ...studyAreas.mapGetters(['studyAreas', 'cameraLocations']), - ...trip.mapState(['editProjectTrip']), + ...trip.mapState(['projectTrips', 'editProjectTripData']), }, methods: { ...projectCamera.mapActions(['getProjectCameras']), @@ -101,9 +114,21 @@ export default { 'getProjectStudyAreas', 'getProjectCameraLocations', ]), - ...trip.mapActions(['addProjectTrip', 'setEditProjectTrip']), - openEditProjectTripBasic: function() { - this.setEditProjectTrip({}); + ...trip.mapActions([ + 'getProjectTrips', + 'addProjectTrip', + 'setEditProjectTripData', + 'editProjectTrip', + 'deleteProjectTrip', + ]), + openAddProjectTripBasic: async function() { + await this.getProjectStudyAreas(this.projectId); + this.setEditProjectTripData({}); + this.showEditProjectTripBasic = true; + }, + openEditProjectTripBasic: async function(currentTrip) { + await this.getProjectStudyAreas(this.projectId); + this.setEditProjectTripData(currentTrip); this.showEditProjectTripBasic = true; }, closeEditProjectTripBasic: function() { @@ -119,12 +144,20 @@ export default { this.showEditProjectTripBasic = true; this.closeEditProjectTripCamera(); }, - addProjectTripRequest: async function(reGetProjectTrip) { - await this.addProjectTrip({ - projectId: this.projectId, - body: this.editProjectTrip, - reGetProjectTrip, - }); + addEditProjectTripRequest: async function(reGetProjectTrip) { + if (this.editProjectTripData.id) { + await this.editProjectTrip({ + projectId: this.projectId, + tripId: this.editProjectTripData.id, + body: this.editProjectTripData, + }); + } else { + await this.addProjectTrip({ + projectId: this.projectId, + body: this.editProjectTripData, + reGetProjectTrip, + }); + } this.closeEditProjectTripCamera(); this.closeCheckCameraDetailModal(); }, @@ -136,7 +169,7 @@ export default { }, async checkAddProjectTripRequest() { await this.$emit('setEditProjectTripReduest'); - const emptyCameraDetail = this.editProjectTrip.studyAreas.reduce( + const emptyCameraDetail = this.editProjectTripData.studyAreas.reduce( (previous, current) => { let result = current.cameraLocations.reduce((pre, curr) => { if (curr.projectCameras && curr.projectCameras[0]) { @@ -154,7 +187,7 @@ export default { ); if (emptyCameraDetail) this.openCheckCameraDetailModal(); - else this.addProjectTripRequest(true); + else this.addEditProjectTripRequest(true); }, }, watch: { @@ -166,7 +199,7 @@ export default { }, }, mounted() { - this.getProjectStudyAreas(this.projectId); + this.getProjectTrips(this.projectId); }, }; diff --git a/src/sass/globals/_page.sass b/src/sass/globals/_page.sass index 28853a0d..8ea2ff52 100644 --- a/src/sass/globals/_page.sass +++ b/src/sass/globals/_page.sass @@ -493,6 +493,45 @@ .form-group line-height: 38px + .list-project-trip + .trip-detail + border: 2px solid #979797 + line-height: 40px + width: 100% + height: 200px + overflow: scroll + h5 + margin: 0px + line-height: 40px + padding-left: 20px + .el-table__row:hover > td + background: none + .trip-camera-detail + .camera-setting-title + color: $gray + .el-table__expanded-cell + padding: 10px 0 + div + line-height: 20px + span + font-size: 5px + .study-area-row, + .el-table .cell, + .el-table .cell div + white-space: nowrap + text-overflow: ellipsis + overflow: hidden + .el-table__expanded-cell + padding: 20px + .is-active + background: $bg-green + color: $green + .project-trip-sidebar-item + border-bottom: 1px solid #E6E7E8 + line-height: 38px + cursor: pointer + padding-left: 20px + .edit-project-trip-basic .edit-project-trip-basic-content min-height: 455px diff --git a/src/service/modules/trip.js b/src/service/modules/trip.js index 5eaf30e7..4c8610cd 100644 --- a/src/service/modules/trip.js +++ b/src/service/modules/trip.js @@ -13,4 +13,19 @@ const addProjectTrip = async (projectId, body) => body, }); -export { getProjectTrips, addProjectTrip }; +const editProjectTrip = async (projectId, tripId, body) => + await fetchWrap({ + url: `/api/v1/projects/${projectId}/trips/${tripId}`, + method: 'PUT', + body, + }); + +const deleteProjectTrip = async (projectId, tripId) => { + const data = await fetchWrap({ + url: `/api/v1/projects/${projectId}/trips/${tripId}`, + method: 'DELETE', + }); + return data; +}; + +export { getProjectTrips, addProjectTrip, editProjectTrip, deleteProjectTrip }; diff --git a/src/store/modules/projects/trip.js b/src/store/modules/projects/trip.js index 1b9d19cf..950f701d 100644 --- a/src/store/modules/projects/trip.js +++ b/src/store/modules/projects/trip.js @@ -1,24 +1,29 @@ -import { addProjectTrip, getProjectTrips } from '@/service'; +import { + addProjectTrip, + deleteProjectTrip, + editProjectTrip, + getProjectTrips, +} from '@/service'; import idx from 'idx'; const state = { - trips: [], - editProjectTrip: {}, + projectTrips: [], + editProjectTripData: {}, }; const mutations = { - setTrips(state, payload) { - state.trips = payload; + setProjectTrips(state, payload) { + state.projectTrips = payload; }, - setEditProjectTrip(state, payload) { - state.editProjectTrip = payload; + setEditProjectTripData(state, payload) { + state.editProjectTripData = payload; }, }; const actions = { async getProjectTrips({ commit }, projectId) { const data = await getProjectTrips(projectId); - commit('setTrips', idx(data, _ => _.items) || []); + commit('setProjectTrips', idx(data, _ => _.items) || []); }, async addProjectTrip({ dispatch }, { projectId, body, reGetProjectTrip }) { await addProjectTrip(projectId, body); @@ -26,8 +31,22 @@ const actions = { dispatch('getProjectTrips', projectId); } }, - async setEditProjectTrip({ commit }, payload) { - commit('setEditProjectTrip', payload); + async setEditProjectTripData({ commit }, payload) { + commit('setEditProjectTripData', payload); + }, + async editProjectTrip( + { dispatch }, + { projectId, tripId, body, reGetProjectTrip = true }, + ) { + await editProjectTrip(projectId, tripId, body); + if (reGetProjectTrip) dispatch('getProjectTrips', projectId); + }, + async deleteProjectTrip( + { dispatch }, + { projectId, tripId, reGetProjectTrip = true }, + ) { + await deleteProjectTrip(projectId, tripId); + if (reGetProjectTrip) dispatch('getProjectTrips', projectId); }, }; From 17a84b78aa8751f7d0f640f4d869c229405589df Mon Sep 17 00:00:00 2001 From: "peggy.liu" Date: Sat, 5 Oct 2019 10:17:48 +0800 Subject: [PATCH 2/7] Add search trip --- .../ProjectEdit/Trip/ListProjectTrip.vue | 39 ++++++++++++++++++- src/pages/Project/EditProject/Trip.vue | 24 ++++++++---- src/sass/globals/_page.sass | 14 +++++++ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/components/ProjectEdit/Trip/ListProjectTrip.vue b/src/components/ProjectEdit/Trip/ListProjectTrip.vue index 7dce295c..66b35a05 100644 --- a/src/components/ProjectEdit/Trip/ListProjectTrip.vue +++ b/src/components/ProjectEdit/Trip/ListProjectTrip.vue @@ -1,7 +1,7 @@