Vue.component("values-box", { props: ["values", "v-values", "size", "maxlength", "name", "placeholder", "v-allow-empty", "validator"], data: function () { let values = this.values; if (values == null) { values = []; } if (this.vValues != null && typeof this.vValues == "object") { values = this.vValues } return { "realValues": values, "isUpdating": false, "isAdding": false, "index": 0, "value": "", isEditing: false } }, methods: { create: function () { this.isAdding = true; var that = this; setTimeout(function () { that.$refs.value.focus(); }, 200); }, update: function (index) { this.cancel() this.isUpdating = true; this.index = index; this.value = this.realValues[index]; var that = this; setTimeout(function () { that.$refs.value.focus(); }, 200); }, confirm: function () { if (this.value.length == 0) { if (typeof(this.vAllowEmpty) != "boolean" || !this.vAllowEmpty) { return } } // validate if (typeof(this.validator) == "function") { let resp = this.validator.call(this, this.value) if (typeof resp == "object") { if (typeof resp.isOk == "boolean" && !resp.isOk) { if (typeof resp.message == "string") { let that = this teaweb.warn(resp.message, function () { that.$refs.value.focus(); }) } return } } } if (this.isUpdating) { Vue.set(this.realValues, this.index, this.value); } else { this.realValues.push(this.value); } this.cancel() this.$emit("change", this.realValues) }, remove: function (index) { this.realValues.$remove(index) this.$emit("change", this.realValues) }, cancel: function () { this.isUpdating = false; this.isAdding = false; this.value = ""; }, updateAll: function (values) { this.realValues = values }, addValue: function (v) { this.realValues.push(v) }, startEditing: function () { this.isEditing = !this.isEditing }, allValues: function () { return this.realValues } }, template: `
{{value}} [空]
[修改]
{{value}} [空]  
` });