Commit 549aed67 authored by renjintao's avatar renjintao

state

parent de465fe8
<template> <template>
<div class="ib"> <div class="ib">
<div class="ib" v-if="!isMore">
<div class="ib" v-if="!isMore"> <span v-if="type=='text'" :style="style">{{name}}</span>
<span v-if="type=='text'" :style="style">{{name}}</span> <Tag v-if="type=='tag'" :color="tagcolor">{{name}}</Tag>
<Tag v-if="type=='tag'" :color="tagcolor">{{name}}</Tag> <Badge v-if="type=='dot'" :color="tagcolor" :text="name" />
<Badge v-if="type=='dot'" :color="tagcolor" :text="name" /> <Icon v-if="type=='icon'" :type="item.icon" :color="tagcolor" :title="name" size="24" />
<Icon v-if="type=='icon'" :type="item.icon" :color="tagcolor" :title="name" size="24" /> </div>
<div class="ib" v-else v-for="(li,i) in items" :key="i">
<span v-if="type=='text'" :style="li.style">{{li.name}}</span>
<Tag v-if="type=='tag'" :color="li.tagcolor">{{li.name}}</Tag>
<Badge v-if="type=='dot'" :color="li.tagcolor" :text="li.name" />&nbsp;
</div>
</div> </div>
<div class="ib" v-else v-for="(li,i) in items" :key="i">
<span v-if="type=='text'" :style="li.style">{{li.name}}</span>
<Tag v-if="type=='tag'" :color="li.tagcolor">{{li.name}}</Tag>
<Badge v-if="type=='dot'" :color="li.tagcolor" :text="li.name" />
&nbsp;
</div>
</div>
</template> </template>
<script> <script>
export default { export default {
name: 'state', name: "state",
data() { data() {
return { return {
name: '', name: "",
isMore:false, isMore: false,
item: {}, item: {},
items: [], items: [],
data: [] data: []
} };
}, },
props: { props: {
default: { default: {
type: String, type: String,
default: '' default: ""
}, },
type: { type: {
type: String, type: String,
default: 'text', default: "text",
validator: function(value) { validator: function(value) {
return ['text', 'tag', 'dot','icon'].indexOf(value) != -1 return ["text", "tag", "dot", "icon"].indexOf(value) != -1;
} }
}, },
code: { code: {
...@@ -62,35 +59,39 @@ export default { ...@@ -62,35 +59,39 @@ export default {
} }
}, },
created() { created() {
this.data = this.$store.getters.dictionaryByKey(this.code) || [] this.data = this.$store.getters.dictionaryByKey(this.code) || [];
}, },
methods: { methods: {
setName(v) { setName(v) {
if ((v+"").indexOf(',')==-1) { if ((v + "").indexOf(",") == -1) {
var item var item;
this.data.map((u) => { this.data.map(u => {
if (u.code == v) { if (u.code == v) {
item = u item = u;
} }
}) });
if (item) { if (item) {
this.name = item.name this.name = item.name;
this.item = item this.item = item;
} else { } else {
this.name = this.value if (this.value == "undefined") {
this.name = ' '
} else {
this.name = this.value;
}
} }
} else { } else {
this.isMore=true; this.isMore = true;
var items=[]; var items = [];
var ul=(v+"").split(',') var ul = (v + "").split(",");
this.data.map((u) => { this.data.map(u => {
if (ul.indexOf(u.code)>-1) { if (ul.indexOf(u.code) > -1) {
u.tagcolor=u.color|'default' u.tagcolor = u.color | "default";
u.style={color: u.color|'inherit'} u.style = { color: u.color | "inherit" };
items.push(u) items.push(u);
} }
}) });
this.items=items; this.items = items;
} }
} }
}, },
...@@ -99,36 +100,36 @@ export default { ...@@ -99,36 +100,36 @@ export default {
if ( if (
this.color && this.color &&
this.item && this.item &&
this.item.color != '' && this.item.color != "" &&
this.item.color != null this.item.color != null
) { ) {
return this.item.color return this.item.color;
} }
return 'default' return "default";
}, },
style() { style() {
if (!this.color) { if (!this.color) {
return {} return {};
} }
return { return {
color: color:
this.item && this.item.color != '' && this.item.color != null this.item && this.item.color != "" && this.item.color != null
? this.item.color ? this.item.color
: 'inherit' : "inherit"
} };
} }
}, },
watch: { watch: {
value(v) { value(v) {
this.setName(v) this.setName(v);
// this.$forceUpdate() // this.$forceUpdate()
}, },
data(v){ data(v) {
if(v.length>0){ if (v.length > 0) {
this.setName(this.value) this.setName(this.value);
this.$forceUpdate() this.$forceUpdate();
} }
} }
} }
} };
</script> </script>
\ No newline at end of file
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