en-picker.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view v-show="showPicker">
  3. <uni-data-picker :popup-title="'选择'+label" :localdata="localData" ref="pickerObj"
  4. @change="pickerChange" :border="false" :clear-icon="false" @popupclosed="setPopupClosed">
  5. </uni-data-picker>
  6. </view>
  7. </template>
  8. <script>
  9. import EnPopup from "@/components/en-utils/en-popup/en-popup";
  10. export default {
  11. name: "en-picker",
  12. components: {EnPopup},
  13. props: {
  14. localData: {
  15. type: Array,
  16. default: []
  17. },
  18. label: {
  19. type: String,
  20. default: '标题'
  21. },
  22. placeholder: {
  23. type: String,
  24. default: '请选择'
  25. },
  26. disabled: {
  27. type: Boolean,
  28. default: false
  29. },
  30. name: {
  31. type: String,
  32. default: 'text'
  33. },
  34. valueType: {
  35. type: String,
  36. default: '1'
  37. },
  38. value: {
  39. default: ''
  40. }
  41. },
  42. data() {
  43. return {
  44. inputValue: [],
  45. optionName: '',
  46. labelWidth: 0,
  47. showPicker:false
  48. }
  49. },
  50. watch: {
  51. 'value': function () {
  52. this.setValue()
  53. },
  54. 'inputValue': function () {
  55. console.log(this.inputValue)
  56. if(this.valueType==='1'){
  57. this.$emit('change', this.inputValue.join(','))
  58. }else {
  59. this.$emit('change', this.inputValue)
  60. }
  61. }
  62. },
  63. mounted() {
  64. },
  65. methods: {
  66. setValue(){
  67. let value=this.value
  68. if(!value){
  69. value=[]
  70. }else if(typeof value==='string'){
  71. value=value.split(',')
  72. }
  73. if(this.inputValue!==value){
  74. this.inputValue=value
  75. this.optionName = "";
  76. this.localData.forEach((one)=>{
  77. if(one.value+''===this.inputValue[0]+''){
  78. this.optionName += one.text + " ";
  79. if(one.children){
  80. one.children.forEach((two)=>{
  81. if(two.value+''===this.inputValue[1]+''){
  82. this.optionName += two.text + " ";
  83. if(two.children){
  84. two.children.forEach((three)=>{
  85. if(three.value+''===this.inputValue[2]+''){
  86. this.optionName += three.text + " ";
  87. }
  88. })
  89. }
  90. }
  91. })
  92. }
  93. }
  94. })
  95. }
  96. },
  97. setPopupClosed() {
  98. this.showPicker = false;
  99. },
  100. showPickerObj() {
  101. this.showPicker = true;
  102. this.$refs.pickerObj.show();
  103. },
  104. pickerChange(data) {
  105. this.optionName = "";
  106. this.inputValue = [];
  107. data.detail.value.forEach((item) => {
  108. this.optionName += item.text + " ";
  109. this.inputValue.push(item.value)
  110. });
  111. this.showPicker = false;
  112. },
  113. }
  114. }
  115. </script>
  116. <style scoped lang="scss">
  117. </style>