indexMixin.js 3.67 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12
export default {
  computed: {
    tagValue: {
      get: function () {
        if (this.multiple) {
          return this.selection
        } else {
          return 0 == this.selection.length ? null : this.selection[0]
        }
      },
    },
  },
袁成 committed
13 14 15 16 17 18 19 20 21 22 23 24 25
  // watch: {
  //   value: {
  //     handler: function (newVal) {
  //       if (newVal) {
  //         this.init(newVal)
  //       } else {
  //         this.selection = []
  //         this.sendEvent(null)
  //       }
  //     },
  //     deep: true,
  //   },
  // },
wangcong committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  
  methods: {
    init(value) {
      if (this.multiple) {
        let codes = []
        if (this.isCode) {
          if(value&&value[0] instanceof Object) {
            codes = value.map((item) => item.code.toString())
          } else {
            codes = value.map(item => item.toString())
          }
        } else {
          codes = value.map((item) => item.code.toString())
        }
        if(this.setSelection) {
          this.initBySelection(codes, this.setSelection)
        } else {
          this.initBySelection(codes)
        }
      } else {
        let code = ''
        if (this.isCode) {
          if(value instanceof Object) {
            code = value.code.toString()
          } else {
            code = value.toString()
          }
        } else {
          code = value.code?value.code.toString():value.toString()
        }
        if(this.setSelection) {
          this.initBySelection(code, this.setSelection)
        } else {
          this.initBySelection(code)
        }
      }
    },
    async initBySelection(code, callback) {
      if (this.isOrg) {
        let param = {
          pagination: false,
          queryDataStructure: 'ALL',
        }
        if (this.multiple) {
          param.orgCodes = code
        } else {
          param.code = code
        }
        this.selection = await this.getOrg(param)
      } else {
        let postData = {
          tableName: this.tableName,
          searchKey: '',
          queryDataStructure: 'ALL',
          authType: this.authType,
          versionDate: this.versionDate,
          expression: this.filterFormular,
          'BI-SYNTAX': null
        }
        if (this.multiple) {
          postData.baseDataCodes = code
        } else {
          postData.code = code
        }
        this.getBaseData(postData, '', true)
          .then((response) => {
            const { rows, rs, total } = response.data
            this.selection = rows
            // 这段代码会影响到回显右侧表格的勾选
            // if(this.isCode &&rows&&rows[0]){
            //   this.selectedValue = rows[0].code
            // }else if(rows&&rows[0]){
            //   this.selectedValue = rows[0]
            //   this.selectedValue.id = rows[0].code;
            //   this.selectedValue.text = rows[0].name;
            // }
            // let result = this.getReturnInfo()
            // this.sendEvent(result)
            if (callback) {
              callback(rows)
            }
          })
          .catch((XMLHttpRequest) => {
            this.$Message.error('信息获取失败')
          })
      }
    },
    getReturnInfo() {
      
      if (this.multiple) {
        if (this.isCode) {
          return this.selection.map(item => item.code)
        } else {
          return this.selection
        }
      } else {
        if (this.isCode) {
          return 0 == this.selection.length ? null : this.selection[0].code
        } else {
          return 0 == this.selection.length ? null : this.selection[0]
        }
      }
    },
    sendEvent(result) {
      this.$emit('input', result)
      this.$emit('data-change', result)
      // this.dispatch && this.dispatch('FormItem', 'on-form-change', result)
    },
  }
}