userFrom.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.customFrom}}</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. const app = getApp({allowDefault: true});
  14. export default{
  15. props:{
  16. placeholder:String,
  17. value: String,
  18. },
  19. model: {
  20. prop: 'value',
  21. },
  22. data(){
  23. return{
  24. dicName:'',
  25. visible:false,
  26. list:[]
  27. }
  28. },
  29. onBackPress() {
  30. if(this.visible) {
  31. this.visible = false;
  32. return true;
  33. }
  34. },
  35. watch: {
  36. value(newval, oldval) {
  37. // var code = this.type == 'object' ? newval.dicCode : newval;
  38. var list = this.list.filter((item) => item.id == newval);
  39. //数据不存在时
  40. if (list.length == 0) {
  41. this.getData();
  42. }else{
  43. this.changeData(list[0]);
  44. }
  45. }
  46. },
  47. mounted() {
  48. this.getData();
  49. },
  50. methods:{
  51. getData() {
  52. this.$axios.get('app/customFrom/findByStoreId/'+uni.getStorageSync('storeId')).then(res => {
  53. console.log(res)
  54. this.list = res.data.list;
  55. var list = this.list.filter((item) => item.id == this.value);
  56. if(list.length>0){
  57. this.changeData(list[0]);
  58. }
  59. }).catch(err => {
  60. console.log(err)
  61. })
  62. },
  63. changeData(data){
  64. console.log(data)
  65. this.dicName=data.customFrom;
  66. this.$emit('input',data.id);
  67. this.$emit('changeDetail',data);
  68. this.visible=false;
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. </style>