zhangdan 3 years ago
parent
commit
3a5e01ad49
2 changed files with 125 additions and 0 deletions
  1. 8 0
      api/data.js
  2. 117 0
      components/select/v-select.vue

+ 8 - 0
api/data.js

@@ -6,6 +6,14 @@ export const getLookUpDatas = (params) => {
     method: 'get'
   })
 }
+
+export const listLookUp = (params) => {
+  let url = `lookup/findAll`
+  return axios.request({
+    url: url,
+    method: 'post'
+  }).then(res => res)
+}
 // 查询最新版本信息
 export const getSysVersion = (params) => {
   return axios.request({

+ 117 - 0
components/select/v-select.vue

@@ -0,0 +1,117 @@
+<template>
+	<picker @change="toChange" :value="index" :range="datalist" range-key="dispName">
+		<view style="display: flex;align-items: center;">
+			<input class="form-input" :disabled="disabled" v-model="selected" placeholder-class="form-input-placeholder" :placeholder="getPlaceholderText" />
+			<uni-font-icons size="12" type="icon-xiangyoujiantou" color="#9DA8B5"></uni-font-icons>
+		</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
+      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({
+        type: this.code
+      }).then(result => {
+		  console.log(result, 'result')
+        if (result && result.status + '' === '200') {
+          this.datalist = result.data
+          
+        }
+      })
+    } 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>