diff --git a/src/store/index.js b/src/store/index.js
index fce212f..429dc06 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -15,6 +15,7 @@ const store = new Vuex.Store({
shopList: [], // 商铺列表
adminList: [], // 管理员列表
airList: [], // 所有飞机列表
+ planeClassList: [], // 机型列表
siteList: [], // 站点列表
routeList: [], // 航线列表
noflyData: [[], [], []], // [0]禁飞区数据 [1]限制飞区 [2]限飞区高度
@@ -66,6 +67,12 @@ const store = new Vuex.Store({
setRouteList (state, list) {
state.routeList = list
},
+ /**
+ * @description: 设置机型列表
+ */
+ setPlaneClassList (state, list) {
+ state.planeClassList = list
+ },
/**
* @description: 设置禁飞区列表
*/
@@ -431,6 +438,64 @@ const store = new Vuex.Store({
})
}
},
+ /**
+ * @description: 获取机型列表
+ */
+ async fetchPlaneClassList ({ commit }) {
+ const res = await api.get('getPlaneClassList')
+ if (res.data.status === 1) {
+ commit('setPlaneClassList', res.data.planeClassList)
+ } else {
+ commit('setPlaneClassList', [])
+ Message.warning(res.data.msg)
+ }
+ return res.data.planeClassList
+ },
+ /**
+ * @description: 创建新机型
+ * @param {*} form 表单.机型信息
+ * @return {*} 服务器返回信息
+ */
+ async fetchAddPlaneClass ({ dispatch }, form) {
+ const params = new URLSearchParams()
+ params.append('shop_id', form.shop_id)
+ params.append('class_name', form.class_name)
+ params.append('wheelbase', form.wheelbase)
+ params.append('category', form.category)
+ params.append('weight_max', form.weight_max)
+ params.append('describe', form.describe)
+ const res = await api.post('addPlaneClass', params)
+ if (res.data.status === 1) {
+ await dispatch('fetchPlaneClassList')// 刷新 机型列表
+ Message.success(res.data.msg)
+ } else {
+ Message.error(res.data.msg)
+ }
+ return res
+ },
+ /**
+ * @description: 创建新机型
+ * @param {*} form 表单.机型信息
+ * @return {*} 服务器返回信息
+ */
+ async fetchSavePlaneClass ({ dispatch }, form) {
+ const params = new URLSearchParams()
+ params.append('id', form.id)
+ params.append('shop_id', form.shop_id)
+ params.append('class_name', form.class_name)
+ params.append('wheelbase', form.wheelbase)
+ params.append('category', form.category)
+ params.append('weight_max', form.weight_max)
+ params.append('describe', form.describe)
+ const res = await api.post('savePlaneClass', params)
+ if (res.data.status === 1) {
+ await dispatch('fetchPlaneClassList')// 刷新 机型列表
+ Message.success(res.data.msg)
+ } else {
+ Message.error(res.data.msg)
+ }
+ return res
+ },
/**
* @description: 获取站点列表
*/
diff --git a/src/views/layout/components/headbar.vue b/src/views/layout/components/headbar.vue
index dc84547..ef8a760 100644
--- a/src/views/layout/components/headbar.vue
+++ b/src/views/layout/components/headbar.vue
@@ -266,6 +266,7 @@ export default {
refreshPage () {
/* init 数据接口 */
this.$store.commit('app/setIsMobile') // 获取客户端平台类型
+ this.$store.dispatch('fetchPlaneClassList')// 获取机型列表
this.$store.dispatch('fetchAirList') // 获取飞机列表
this.$store.dispatch('fetchShopList') // 获取商铺列表
this.$store.dispatch('fetchAdminList') // 获取管理员列表
diff --git a/src/views/layout/components/main/model/add.vue b/src/views/layout/components/main/model/add.vue
index 69dd451..7ff17ef 100644
--- a/src/views/layout/components/main/model/add.vue
+++ b/src/views/layout/components/main/model/add.vue
@@ -35,14 +35,14 @@
- cm
+ cm
- 克
+ 克
@@ -52,15 +52,19 @@
-
- 创建
-
+
+
+ {{ pageState === 'add' ? '创建' : '更新' }}
+
+
重填
-
- 更新
-
+
@@ -73,7 +77,10 @@
import SelectionShopId from '@/components/SelectionShopId'
export default {
- name: 'RegisterAdd',
+ name: 'PlaneClassAdd',
+ components: {
+ SelectionShopId
+ },
data () {
return {
form: {
@@ -82,79 +89,67 @@ export default {
category: '四旋翼',
wheelbase: '',
weight_max: '',
- module: '',
- describe: '',
- onoff: true
+ describe: ''
},
- airId: this.$route.params.id,
+ planeClassId: this.$route.params.id,
pageState: 'add',
- plane: null
+ planeClass: null
}
},
- components: {
- SelectionShopId
- },
computed: {
- airList () {
- return this.$store.state.airList
+ planeClassList () {
+ return this.$store.state.planeClassList || []
}
},
methods: {
- setForm (data) {
- this.form.shop_id = data.shop_id
- this.form.class_name = data.class_name
- this.form.category = data.category
- this.form.wheelbase = data.wheelbase
- this.form.weight_max = data.weight_max
- this.form.module = data.module
+ setForm (data = {}) {
+ this.form.shop_id = data.shop_id || ''
+ this.form.class_name = data.class_name || ''
+ this.form.category = data.category || '四旋翼'
+ this.form.wheelbase = data.wheelbase || ''
+ this.form.weight_max = data.weight_max || ''
this.form.describe = data.describe || ''
- this.form.onoff = data.onoff === '1' || data.onoff === true
if (Object.keys(data).length === 0) {
this.$message.warning('清空表单')
}
},
initPage () {
- if (this.airId === undefined) {
+ if (!this.planeClassId) {
this.pageState = 'add'
} else {
this.pageState = 'edit'
- this.plane = this.airList.find((item) => item.id === this.airId)
- if (this.plane) {
- const data = {
- shop_id: this.plane.shop_id,
- class_name: this.plane.class_name,
- category: this.plane.category,
- wheelbase: this.plane.wheelbase,
- weight_max: this.plane.weight_max,
- module: this.plane.module,
- describe: this.plane.describe,
- onoff: this.plane.onoff
- }
- this.setForm(data)
+ this.planeClass = this.planeClassList.find(item => item.id === this.planeClassId)
+ if (this.planeClass) {
+ this.setForm({ ...this.planeClass })
+ } else {
+ this.$message.error('找不到对应机型信息')
}
}
},
- async addAir () {
- const res = await this.$store.dispatch('fetchAddAir', this.form)
- if (res.data.status === 1) {
- this.$router.push('/register/index')
+ async addPlaneClass () {
+ const res = await this.$store.dispatch('fetchAddPlaneClass', this.form)
+ if (res?.data?.status === 1) {
+ this.$router.push('/model/index')
}
},
- async saveAir () {
- this.form.id = this.airId
- const res = await this.$store.dispatch('fetchSaveAir', this.form)
- if (res.data.status === 1) {
- this.$router.push('/register/index')
+ async savePlaneClass () {
+ this.form.id = this.planeClassId
+ const res = await this.$store.dispatch('fetchSavePlaneClass', this.form)
+ if (res?.data?.status === 1) {
+ this.$router.push('/model/index')
}
}
},
watch: {
- airList () {
- this.initPage()
+ planeClassList: {
+ handler () {
+ this.initPage()
+ },
+ immediate: true
}
},
created () {
- if (this.airList.length > 0) {
+ if (this.planeClassList.length > 0) {
this.initPage()
}
}
diff --git a/src/views/layout/index.vue b/src/views/layout/index.vue
index c4162d4..2edbd37 100644
--- a/src/views/layout/index.vue
+++ b/src/views/layout/index.vue
@@ -107,6 +107,7 @@ export default {
created () {
/* init */
this.$store.commit('app/setIsMobile')// 获取客户端平台类型
+ this.$store.dispatch('fetchPlaneClassList')// 获取机型列表
this.$store.dispatch('fetchAirList')// 获取飞机列表
this.$store.dispatch('fetchShopList')// 获取商铺列表
this.$store.dispatch('fetchAdminList')// 获取管理员列表