c-select.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div id="c-select">
  3. <van-cell :title="label" @click="show = true">
  4. <span v-if="mval" style="color: #000">{{ mval }}</span>
  5. <span v-else>{{ `请选择${label}` }}</span>
  6. </van-cell>
  7. <van-popup v-model="show" show-toolbar position="bottom">
  8. <van-picker v-if="type === 'select'" :value-key="valueKey" :title="label" show-toolbar :columns="list" @confirm="onConfirm" @cancel="show = false" />
  9. <van-checkbox-group v-model="multi" v-else>
  10. <van-picker :title="label" :show-toolbar="true" :columns="list" @confirm="onConfirm" @cancel="show = false">
  11. <template #option="item">
  12. <van-checkbox :name="item">{{ item }}</van-checkbox>
  13. </template>
  14. </van-picker>
  15. </van-checkbox-group>
  16. </van-popup>
  17. </div>
  18. </template>
  19. <script>
  20. const _ = require('lodash');
  21. export default {
  22. name: 'c-select',
  23. props: {
  24. label: { type: String },
  25. mval: { type: String },
  26. list: { type: Array, default: () => [] },
  27. type: { type: String },
  28. valueKey: { type: String },
  29. },
  30. model: {
  31. prop: 'mval',
  32. event: 'change',
  33. },
  34. components: {},
  35. data: function () {
  36. return {
  37. show: false,
  38. selectList: [],
  39. multi: [],
  40. };
  41. },
  42. created() {},
  43. methods: {
  44. onConfirm(value) {
  45. if (this.type === 'select') this.$emit('change', value);
  46. else {
  47. const str = this.multi.join(',');
  48. this.$emit('change', str);
  49. }
  50. this.show = false;
  51. },
  52. },
  53. computed: {
  54. pageTitle() {
  55. return `${this.$route.meta.title}`;
  56. },
  57. },
  58. metaInfo() {
  59. return { title: this.$route.meta.title };
  60. },
  61. };
  62. </script>
  63. <style lang="less" scoped>
  64. /deep/.van-cell__value {
  65. text-align: left;
  66. }
  67. </style>