orderState.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. onBackPress() {
  29. if(this.visible) {
  30. this.visible = false;
  31. return true;
  32. }
  33. },
  34. watch: {
  35. value(newval, oldval) {
  36. // var code = this.type == 'object' ? newval.dicCode : newval;
  37. var list = this.list.filter((item) => item.dicCode == newval);
  38. //数据不存在时
  39. if (list.length == 0) {
  40. this.$store.state.dicChange = true;
  41. this.getData();
  42. }
  43. }
  44. },
  45. mounted() {
  46. this.getData();
  47. },
  48. methods:{
  49. getData() {
  50. uni.getStorage({
  51. key:'dic',
  52. success: (res) => {
  53. this.list=res.data.orderState;
  54. var list = this.list.filter((item) => item.dicCode == this.value);
  55. if(list.length>0){
  56. this.changeData(list[0]);
  57. }
  58. },fail: (err) => {
  59. this.$store.state.dicChange = true;
  60. this.getData();
  61. }
  62. })
  63. // if(this.$root.getStorage('dic')){
  64. // this.list=this.$root.getStorage('dic').filter((item)=>item.dicType=='want_level');
  65. // }else{
  66. // this.$store.state.dicChange=true;
  67. // }
  68. // this.$axios.post('app/dic/orderStateCode', {
  69. // "parentId": "1001",
  70. // "dicType": "order_state"
  71. // }).then(res => {
  72. // console.log(res)
  73. // this.list = res.data.list;
  74. // var list = this.list.filter((item) => item.dicCode == this.value);
  75. // if(list.length>0){
  76. // this.changeData(list[0]);
  77. // }
  78. // }).catch(err => {
  79. // console.log(err)
  80. // })
  81. },
  82. changeData(data){
  83. this.dicName=data.dicName;
  84. this.$emit('input',data.dicCode);
  85. this.visible=false;
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. </style>