followState.vue 2.0 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)" v-if="item.dicCode!='01'">
  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. console.log('yx',newval)
  32. var list = this.list.filter((item) => item.dicCode == newval);
  33. //数据不存在时
  34. if (list.length == 0) {
  35. this.$store.state.dicChange = true;
  36. this.getData();
  37. }else{
  38. this.changeData(list[0]);
  39. }
  40. }
  41. },
  42. mounted() {
  43. this.getData();
  44. },
  45. methods:{
  46. getData(){
  47. uni.getStorage({
  48. key:'dic',
  49. success: (res) => {
  50. this.list=res.data.followState;
  51. var list = this.list.filter((item) => item.dicCode == this.value);
  52. if(list.length>0){
  53. this.changeData(list[0]);
  54. }
  55. },fail: (err) => {
  56. this.$store.state.dicChange = true;
  57. this.getData();
  58. }
  59. })
  60. // this.$axios.post('app/dic/followStateCode', {
  61. // "parentId": "1001",
  62. // "dicType": " follow_state"
  63. // }).then(res => {
  64. // console.log(res)
  65. // this.list = res.data.list;
  66. // var list = this.list.filter((item) => item.dicCode == this.value);
  67. // if(list.length>0){
  68. // this.changeData(list[0]);
  69. // }
  70. // }).catch(err => {
  71. // console.log(res)
  72. // })
  73. },
  74. changeData(data){
  75. this.dicName=data.dicName;
  76. this.$emit('input',data.dicCode);
  77. this.$emit('change',data);
  78. this.visible=false;
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. </style>