123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <template>
- <view v-show="showPicker">
- <uni-data-picker :popup-title="'选择'+label" :localdata="localData" ref="pickerObj"
- @change="pickerChange" :border="false" :clear-icon="false" @popupclosed="setPopupClosed">
- </uni-data-picker>
- </view>
- </template>
- <script>
- import EnPopup from "@/components/en-utils/en-popup/en-popup";
- export default {
- name: "en-picker",
- components: {EnPopup},
- props: {
- localData: {
- type: Array,
- default: []
- },
- label: {
- type: String,
- default: '标题'
- },
- placeholder: {
- type: String,
- default: '请选择'
- },
- disabled: {
- type: Boolean,
- default: false
- },
- name: {
- type: String,
- default: 'text'
- },
- valueType: {
- type: String,
- default: '1'
- },
- value: {
- default: ''
- }
- },
- data() {
- return {
- inputValue: [],
- optionName: '',
- labelWidth: 0,
- showPicker:false
- }
- },
- watch: {
- 'value': function () {
- this.setValue()
- },
- 'inputValue': function () {
- console.log(this.inputValue)
- if(this.valueType==='1'){
- this.$emit('change', this.inputValue.join(','))
- }else {
- this.$emit('change', this.inputValue)
- }
- }
- },
- mounted() {
- },
- methods: {
- setValue(){
- let value=this.value
- if(!value){
- value=[]
- }else if(typeof value==='string'){
- value=value.split(',')
- }
- if(this.inputValue!==value){
- this.inputValue=value
- this.optionName = "";
- this.localData.forEach((one)=>{
- if(one.value+''===this.inputValue[0]+''){
- this.optionName += one.text + " ";
- if(one.children){
- one.children.forEach((two)=>{
- if(two.value+''===this.inputValue[1]+''){
- this.optionName += two.text + " ";
- if(two.children){
- two.children.forEach((three)=>{
- if(three.value+''===this.inputValue[2]+''){
- this.optionName += three.text + " ";
- }
- })
- }
- }
- })
- }
- }
- })
- }
- },
- setPopupClosed() {
- this.showPicker = false;
- },
- showPickerObj() {
- this.showPicker = true;
- this.$refs.pickerObj.show();
- },
- pickerChange(data) {
- this.optionName = "";
- this.inputValue = [];
- data.detail.value.forEach((item) => {
- this.optionName += item.text + " ";
- this.inputValue.push(item.value)
- });
- this.showPicker = false;
- },
- }
- }
- </script>
- <style scoped lang="scss">
- </style>
|