
<template>
  <div class="base_form">
    <div class="label">
      <img class="pre-tag" src="../../../assets/images/template/pre-tag.png" />
      <div class="label-text" :title="label">{{ label }}</div>
    </div>
    <div class="input-box">
      <input
        class="input"
        v-if="showInput"
        v-model="inputValue"
        @input="change"
        type="text"
        :placeholder="'请输入' + label"
        :readonly="isDisabled"
      />
      <i v-if="iconDown" class="iconfont iconxiangxia icon_down"></i>
    </div>
    <slot></slot>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";

/**
 * 以普通输入框为基础
 * @author yuanzeyu
 * @date 2019-05-29
 * @desc
 */
@Component
export default class BaseForm extends Vue {
  @Prop({ type: String, required: true }) label!: string;
  @Prop({ type: String, default: `` }) value!: string;
  @Prop({ type: String, default: `` }) watchValue!: string; // 用于显示的值
  @Prop({ type: Boolean, default: true }) showInput!: boolean;
  @Prop() isDisabled!: boolean;
  @Prop({ type: Boolean, default: false }) iconDown!: boolean;
  public inputValue = ``;

  mounted() {
    this.inputValue = this.watchValue ? this.watchValue : this.value;
  }
  @Watch(`watchValue`)
  watchValueCb(val: any) {
    this.inputValue = this.watchValue;
  }

  public change() {
    this.$nextTick(() => {
      this.$emit(`changeValue`, this.inputValue, `value`);
    });
  }
}
</script>

<style scoped lang="less">
.base_form {
  flex-shrink: 0;
  padding-left: 18px;
  line-height: 65px;
  height: 65px;
  font-size: 0;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.label {
  display: inline-block;
  width: 150px; /* 104 - 18 */
  flex-shrink: 0;
  height: 44px;
  cursor: pointer;
  line-height: 44px;
  color: #797d84; /* todo ui图颜色不一致 */
  font-size: 14px;
  font-weight: 300;
  position: relative;
}
.label-text {
  text-overflow: ellipsis;
  white-space: nowrap; /*规定段落中的文本不进行换行 */
  overflow: hidden;
}

.icon_down {
  position: absolute;
  right: 26px;
  color: #b8b8b8;
  font-size: 12px; /* todo ui图有空白 */
  transform: scale(0.67);
  cursor: pointer;
}
.input-box {
  position: relative;
  line-height: 65px;
}

.input {
  box-sizing: border-box;
  width: 800px;
  flex-shrink: 0;
  margin-top: 11px;
  min-height: 44px;
  border-radius: 4px;
  border: 1px solid #DCDFE6; /* todo 边框、背景色ui图颜色不一致 */
  outline: none;
  padding-left: 24px;
  font-size: 14px;
  font-weight: 300;
  &::-webkit-input-placeholder {
    color: #bababa;
  }
  &::-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: #bababa;
  }

  &:-ms-input-placeholder {
    /* Internet Explorer 10+ */
    color: #bababa;
  }
}

.pre-tag {
  position: absolute;
  left: -30px;
  top: 14px;
  display: none;
}
</style>
