IntroduceInputControl.vue 5.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
<template>
  <div @click.stop="canGoDetail ? goDetail() : ''" :class="{ 'can-go-detail':canGoDetail }">
    <Input
      v-if="vifValue && !isContent && controlDisplay"
      ref="setfocus"
      v-show="vshowValue"
      style="width: 100%"
      v-model="value"
      :rows="define.config.maxRows"
      :placeholder="define.config.placeholder"
      :maxlength="computedDefinition.length"
      :type="define.config.inputType || 'text'"
      :readonly="true"
      clearable
      @on-blur="onBlur"
    >
      <Icon
        type="ios-menu"
        slot="suffix"
        style="cursor: point"
        @click.stop="executeAction"
        v-if="isShowIcon"
      />
    </Input>
    <div v-if="isContent && controlDisplay">
      {{ getValue() }}
    </div>
  </div>
</template>

<script>
import introduce from "./util/introduce.js";
import bc_input from "./util/bc_input.js";
import stateFormulaMixins from "./util/control-state-formula.js";
import util from "./util/util";

function validateNull(val) {
  if (val instanceof Array) {
    if (val.length === 0) {
      return true;
    }
  } else if (val instanceof Object) {
    if (JSON.stringify(val) === "{}") {
      return true;
    }
  } else {
    if (
      val === "null" ||
      val === null ||
      val === "undefined" ||
      val === undefined ||
      val === ""
    ) {
      return true;
    }
    return false;
  }
  return false;
}

export default {
  mixins: [bc_input],
  data() {
    return {
      value: "",
    };
  },
  computed: {
    button() {
      const define = this.define;
      const button =
        (define.slots &&
          define.slots.children &&
          define.slots.children.elements &&
          define.slots.children.elements[0]) ||
        {};
      return button;
    },
    isShowIcon() {
      return !validateNull(this.button);
    },
    canGoDetail() {
      return !!this.value;
    },
    computedDefinition() {
      const MAX_LENGTH = 255;
      const PRECISION = 19;
      const SCALE = 6;
      const field = this.define.config.field;
      const [tableName, fieldName] = field.split(".");
      const tableType = this.context.bill.getTableType(tableName);
      const maxLength = Math.min(
        this.define.config.maxlength || MAX_LENGTH,
        MAX_LENGTH
      );
      const precision = Math.min(
        this.define.config.precision || PRECISION,
        PRECISION
      );
      const scale = Math.min(this.define.config.scale || SCALE, SCALE);
      let curDefinition = {};

      let flag = false;
      const getColumnDefinition = (attr) => {
        let obj = {};
        for (let annotation of attr.annotations) {
          if (annotation.type == "javax.persistence.Column") {
            obj = { ...annotation.values };
          } else if (annotation.type == "org.hibernate.annotations.Type") {
            if (annotation.values.type == "text") {
              flag = true;
            }
          }
        }
        return obj;
      };
      for (let attribute of tableType.attributes) {
        if (attribute.name == fieldName) {
          curDefinition = { ...getColumnDefinition(attribute) };
        }
      }
      curDefinition = {
        ...curDefinition,
        length: flag
          ? 1e5
          : Math.min(maxLength, curDefinition.length || MAX_LENGTH),
        precision: Math.min(precision, curDefinition.precision || PRECISION),
        scale: Math.min(scale, curDefinition.scale || SCALE),
      };
      return curDefinition;
    },
    getInputStyle() {
      let style = {};
      this.getTextAlign(style);
      this.getTextColor(style);
      this.getInputHeight(style);
      this.getInputWidth(style);
      return style;
    },
  },
  methods: {
    goDetail() {
      let param = this.context.bill.getActionParam(this.button.config.action);
      if(!param || !param.param) return 
      let defineName = param.param.billDefine && param.param.billDefine[0] 
      let templateName = param.param.templateName
      const datasource = 'querysource.' + templateName.split('.')[1]
      const postBody = {"datasource": datasource,"page":{"pageNum":1,"size":20000},"groupBy":[],"orders":[],"queryFields":["id","单据编号"],"conditions":[{"type":"UNDEFINED"}]}
      GMS.$http.post("/bcp/query/advance/query", postBody).then((res) => {
        const data = res.data.rows
        let map = {}
        data.forEach(d=>{
          map[d['单据编号']] = d.id
        })
        let id = map[this.value]
        let a = "/showBillForm/" + defineName + "_E/" + id;
        let routeData = GMS.routerManager.getRouter().resolve({
          path: a,
        });
      window.open(routeData.href, "_blank");
      });
      
    },
    executeAction() {
      this.context.bill.executeAction(this.button.config.action);
    },
  },
};
</script>

<style lang="less" scoped>
.input-height {
  /deep/.ivu-input-default {
    height: 100%;
  }
}
.input-center {
  /deep/.ivu-input-default {
    text-align: center;
  }
}
.input-left {
  /deep/.ivu-input-default {
    text-align: left;
  }
}
.input-right {
  /deep/.ivu-input-default {
    text-align: right;
  }
}
.input-control-wrapper {
  display: inline-block;
  width: 100%;
  position: relative;
}
.can-go-detail {
  /deep/ .ivu-input {
    cursor: pointer;
  }
  
}
/deep/ .ivu-input-suffix{
    cursor: pointer;
  }
</style>