diff --git a/src/components/Options/index.vue b/src/components/Options/index.vue
index eeb187b..98691e1 100644
--- a/src/components/Options/index.vue
+++ b/src/components/Options/index.vue
@@ -1,15 +1,11 @@
-
-
-
+ :prop="`gearValue[${index}]`" :rules="ruleValidate" align="center" prop="options">
+
+
+
@@ -18,114 +14,112 @@
import addImg from '@/assets/images/add-icon.png'
import delImg from '@/assets/images/del-icon.png'
export default {
- props: {
- enumData: {
- type: Object,
- default: null
- },
- isSee: {
- type: Boolean,
- default: false
- },
- // label宽度
- configWidth: {
- type: Number,
- default: 120
- }
+ props: {
+ enumData: {
+ type: Object,
+ default: null
},
- data() {
- return {
- addImg: addImg,
- delImg: delImg,
- maxPosLen: 20, // 最多20档
- posNum: 1, // 当前档位数量
- formData: {
- gearValue: [null] // null:为了不让显示默认1
- },
- ruleValidate: {
- gearValue: [
- { required: true, message: '请填写档位值' }
- ]
- }
- }
+ isSee: {
+ type: Boolean,
+ default: false
},
-
- methods: {
- // 提交的校验
- handleValidate() {
- return new Promise((resolve, reject) => {
- this.$refs.formPosition.validate((valid) => {
- if (valid) {
- // 数据转换为接口所需要的形式
- let obj = {};
- if (this.formData.gearValue) {
- if (this.formData.gearValue.length[0] === null) {
- obj.gearValue = null;
- } else {
- obj.gearValue = this.formData.gearValue.join();
- }
- } else {
- obj.gearValue = null;
- }
- resolve(obj)
- }
- })
- })
- },
-
- // 增删档位
- changePos(idx, actType) {
- if (actType === 'add') {
- if (this.formData.gearValue.length < 20) {
- this.posNum++;
- this.formData.gearValue.splice(idx + 1, 0, null);
- }
- } else {
- this.formData.gearValue.splice(idx, 1);
- this.posNum--;
- }
- },
-
- // 初始化(在父组件中调用)
- initData(obj) {
- if (obj.gearValue) {
- if (obj.gearValue instanceof Array) {
- this.formData.gearValue = obj.gearValue;
- } else if (typeof obj.gearValue === 'string') {
- let arr = [];
- if (obj.gearValue.indexOf(';') !== -1) {
- // 多个-接口传回来的(接口返回的是;分割)
- arr = obj.gearValue.split(';');
- } else {
- // 多个-正在编辑中 / 只有一个
- arr = obj.gearValue.split(',');
- }
- this.formData.gearValue = arr.map(item => {
- return Number(item);
- })
- }
- } else {
- this.formData.gearValue = [null];
- }
- this.posNum = this.formData.gearValue.length;
- },
-
- // 重置表单(在父组件中调用)
- resetForm() {
- this.$refs.formPosition.resetFields();
- this.formData.gearValue = [null];
- }
+ // label宽度
+ configWidth: {
+ type: Number,
+ default: 120
}
+ },
+ data() {
+ return {
+ addImg: addImg,
+ delImg: delImg,
+ maxPosLen: 20, // 最多20档
+ posNum: 1, // 当前档位数量
+ formData: {
+ gearValue: [null] // null:为了不让显示默认1
+ },
+ ruleValidate: {
+ required: true, message: '请填写选项'
+ }
+ }
+ },
+
+ methods: {
+ // 提交的校验
+ handleValidate() {
+ return new Promise((resolve, reject) => {
+ this.$refs.formPosition.validate((valid) => {
+ if (valid) {
+ // 数据转换为接口所需要的形式
+ let obj = {};
+ if (this.formData.gearValue) {
+ if (this.formData.gearValue.length[0] === null) {
+ obj.gearValue = null;
+ } else {
+ obj.gearValue = this.formData.gearValue.join();
+ }
+ } else {
+ obj.gearValue = null;
+ }
+ resolve(obj)
+ }
+ })
+ })
+ },
+
+ // 增删档位
+ changePos(idx, actType) {
+ if (actType === 'add') {
+ if (this.formData.gearValue.length < 20) {
+ this.posNum++;
+ this.formData.gearValue.splice(idx + 1, 0, null);
+ }
+ } else {
+ this.formData.gearValue.splice(idx, 1);
+ this.posNum--;
+ }
+ },
+
+ // 初始化(在父组件中调用)
+ initData(obj) {
+ if (obj.gearValue) {
+ if (obj.gearValue instanceof Array) {
+ this.formData.gearValue = obj.gearValue;
+ } else if (typeof obj.gearValue === 'string') {
+ let arr = [];
+ if (obj.gearValue.indexOf(';') !== -1) {
+ // 多个-接口传回来的(接口返回的是;分割)
+ arr = obj.gearValue.split(';');
+ } else {
+ // 多个-正在编辑中 / 只有一个
+ arr = obj.gearValue.split(',');
+ }
+ this.formData.gearValue = arr.map(item => {
+ return Number(item);
+ })
+ }
+ } else {
+ this.formData.gearValue = [null];
+ }
+ this.posNum = this.formData.gearValue.length;
+ },
+
+ // 重置表单(在父组件中调用)
+ resetForm() {
+ this.$refs.formPosition.resetFields();
+ this.formData.gearValue = [null];
+ }
+ }
}