<template>
  <div class="form-item-text">
    <template v-if="form[item.prop]">
      <span v-if="item.prepend">{{ item.prepend }}</span>
      <span>
        <span
          v-if="item.prop == 'risk_rank'"
          :style="{
            color:
              form[item.prop] == '中危'
                ? '#FF9F33'
                : form[item.prop] == '低危'
                ? 'green'
                : '',
          }"
        >
          {{ form[item.prop] }}
        </span>
        <span
          v-else-if="item.prop == 'screening_advise'"
          style="color: #4e68ff"
        >
          {{ form[item.prop] }}
        </span>
        <span v-else style="margin: 0 5px">{{
          form[item.prop] | getItemText(item.dicData, item.type)
        }}</span>
      </span>
      <span v-if="item.append && !item.toothBit" class="append">{{
        item.append
      }}</span>
    </template>
    <template v-else> -- </template>
  </div>
</template>

<script>
import { formatDicList } from "@/utils/index"
export default {
  name: "FormItemText",
  props: {
    item: Object,
    form: Object | Array,
  },
  data() {
    return {}
  },
  filters: {
    getItemText(val, list, type) {
      if (!val) return ""
      if (["radio", "select", "checkbox", "cascader"].includes(type)) {
        return formatDicList(list, val, type === "cascader" ? "/" : ",")
      }
      if (Array.isArray(val) && type.includes("range")) {
        return val.join("-")
      }
      return val
    },
  },
}
</script>
<style scoped>
.append {
  background-color: #f5f7fa;
  padding: 2px 5px;
  color: #909399;
}
.form-item-text {
  word-break: break-all;
  line-height: 1.2;
}
</style>
