123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <template>
- <picker @change="toChange" :value="index" :range="datalist" range-key="dispName">
- <view style="display: flex;align-items: center;">
- <input class="form-input" :disabled="disabled" style="width: 100%;" v-model="selected" placeholder-style="color:#C0C4CC" :placeholder="getPlaceholderText" />
- <u-icon name="arrow-right" color="#C0C4CC" ></u-icon>
- </view>
- </picker>
- </template>
- <script>
- import { getLookUpDatas, listLookUp } from '@/api/data'
- export default {
- name: 'v-select',
- data () {
- return {
- selected: '',
- datalist: [],
- placeholderText: '请选择',
- lookUp: [],
- index: 0
- }
- },
- props: {
- disabled: {
- type: [Boolean, String],
- default: false
- },
- multiple: {
- type: [Boolean, String],
- default: false
- },
- value: [String, Number, Array],
- code: {
- type: String,
- required: true
- },
- placeholder: {
- type: String,
- default: ''
- },
- size: [String]
- },
- computed: {
- getVal () {
- return this.value
- },
- getPlaceholderText () {
- let _this = this
- console.log(_this.lookUp,'_this.lookUp')
- for (let i = 0; i < _this.lookUp.length; i++) {
- if (_this.lookUp[i].code == _this.code) {
- if (this.placeholder === '') _this.placeholderText = _this.lookUp[i].name
- break
- }
- }
- return _this.placeholderText
- }
- },
- created () {
- if (this.code) {
- if (this.placeholder) {
- this.placeholderText = this.placeholder
- }
- getLookUpDatas({
- lookupCode: this.code,pageNo:1,pageSize:1000
- }).then(result => {
- console.log(result, 'result')
- if (result && result.status + '' === '200') {
- this.datalist = result.data.list
-
- }
- })
- } else {
- // console.log('请确认传递类型')
- }
- // 获取所有数据字典
- this.lookUp = this.$store.state.vuex_allLookUp
- },
- methods: {
- getDataList (){
- return this.datalist
- },
- getOptionName (val) {
- return this.datalist.find((item) => {
- return item.code == val
- })
- },
- getCodeByName (dispName) {
- return this.datalist.find((item) => {
- return item.dispName == dispName
- })
- },
- resetVal(){
- this.selected = ''
- this.index = 0
- },
- // 赋值
- setVal(code){
- let index = this.datalist.findIndex(item=>{
- return item.code == code
- })
- console.log(this.datalist,code,index)
- this.index = index
- this.selected = this.datalist[index].dispName
- },
- toChange (e) {
- this.index = e.target.value
- this.selected = this.datalist[this.index].dispName
- this.$emit('itemChange', this.datalist[this.index].code)
- }
- }
- }
- </script>
- <style scoped>
- </style>
|