123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <template>
- <view>
- <u-input v-model="v" readonly placeholder="请选择">
- <template v-if="!readonly" slot="suffix">
- <u-button @tap="openSelect" text="点击选择" type="primary" size="small"></u-button>
- </template>
- </u-input>
- <action-sheet :actions="options" title="请选择" :show="showSelector" @closeOnClickOverlay="showSelector = false"
- @close="showSelector = false" @select="onSelect" />
- </view>
- </template>
- <script>
- import {
- str,
- clone
- } from '@/utils/tools';
- import * as allStatic from './options.js'
- import actionSheet from './u-action-sheet/my-action-sheet.vue'
- export default {
- name: "commonSelect",
- props: {
- value: {
- type: [String, Number],
- required: false,
- default: null,
- },
- data: {
- type: [String, Array],
- required: true
- },
- remote: {
- type: Boolean,
- required: false,
- default: false,
- },
- readonly: {
- type: Boolean,
- required: false,
- default: false,
- }
- },
- components: {
- // uInput
- actionSheet
- },
- data() {
- return {
- v: str(this.value, null),
- _name: this.getName(),
- options: [],
- showSelector: false,
- };
- },
- watch: {
- value(n, o) {
- this._vlaue = str(n, null)
- },
- data: {
- handler: function(n, o) {
- this.initOptions()
- },
- immediate: true,
- }
- },
- methods: {
- getName() {
- if (!this.v) {
- return ''
- }
- },
- openSelect() {
- uni.hideKeyboard()
- if (!this.readonly) {
- this.showSelector = true
- }
- },
- onSelect(n) {
- this.v = n.name
- console.log('select', arguments);
- },
- parseData(d) {
- return {
- name: d.text,
- value: d.value,
- raw: d,
- }
- },
- initOptions() {
- if (Array.isArray(this.data)) { // 本地数据
- this.options = clone(this.data).map(this.parseData)
- console.log(this.options);
- } else if(this.remote){ // 字典数据
- } else { // 静态数据
- this.options = allStatic[this.data].map(this.parseData)
- }
- }
- }
- }
- </script>
- <style>
- </style>
|