wantLevel.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view>
  3. <z-text style="min-width: 300rpx;" arrow v-model="dicName" :placeholder="placeholder" @click="visible=true"></z-text>
  4. <z-select-popup :visible.sync="visible">
  5. <view v-for="(item,index) in list" :key="index" @click="changeData(item)">
  6. <view>{{item.dicName}}</view>
  7. <view class="line" v-if="index!=(list.length-1)"></view>
  8. </view>
  9. </z-select-popup>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. placeholder: String,
  16. value: String,
  17. },
  18. model: {
  19. prop: 'value',
  20. },
  21. data() {
  22. return {
  23. dicName: '',
  24. visible: false,
  25. list: []
  26. }
  27. },
  28. watch: {
  29. value(newval, oldval) {
  30. // var code = this.type == 'object' ? newval.dicCode : newval;
  31. var list = this.list.filter((item) => item.dicCode == newval);
  32. //数据不存在时
  33. if (list.length == 0) {
  34. this.$store.state.dicChange = true;
  35. this.getData();
  36. }else{
  37. this.changeData(list[0]);
  38. }
  39. }
  40. },
  41. mounted() {
  42. this.getData();
  43. },
  44. methods: {
  45. getData() {
  46. uni.getStorage({
  47. key:'dic',
  48. success: (res) => {
  49. this.list=res.data.wantlevel;
  50. var list = this.list.filter((item) => item.dicCode == this.value);
  51. if(list.length>0){
  52. this.changeData(list[0]);
  53. }
  54. },fail: (err) => {
  55. this.$store.state.dicChange = true;
  56. this.getData();
  57. }
  58. })
  59. // this.$axios.post('app/dic/wantLevelCode', {
  60. // "parentId": "1001",
  61. // "dicType": "want_level_code"
  62. // }).then(res => {
  63. // console.log(res)
  64. // this.list = res.data.list;
  65. // var list = this.list.filter((item) => item.dicCode == this.value);
  66. // if(list.length>0){
  67. // this.changeData(list[0]);
  68. // }
  69. // }).catch(err => {
  70. // console.log(err)
  71. // })
  72. },
  73. changeData(data) {
  74. this.dicName = data.dicName;
  75. this.$emit('input', data.dicCode);
  76. this.$emit('change',data);
  77. this.visible = false;
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. </style>