<template>
  <span :id="id" :name="field.name+'_show'" class="component-input-span">
    <template
      v-if="field.displayType == Constant.PermissionType_HIDDEN || field.textType == 'hidden'"
    >
      <!-- 闅愯棌 TODO:娉ㄦ剰锛岄殣钘忔椂涓嶅簲璇ユ湁hidden鐨刦ield瀛樺湪锛屾湁瀹夊叏闂锛屼互鍚庤鏀硅繃鏉ワ細Jarod -->
     <div class="html" v-if="field.mobile&&field.hiddenValue">
        <div class="titleName">
          {{field.discript?field.discript:field.name}}
        </div>
        <div class="view-li">
          <div class="view-li-right">
            {{field.hiddenValue}}
          </div>
        </div>
      </div>
    </template>
    <template v-else-if="field.displayType == Constant.PermissionType_MODIFY">
      <!-- 鍙紪杈� -->
      <!-- <div :style="{ width: field.width, height: field.height }">
      </div> -->
      <div class="html" v-if="field.mobile">
        <div class="titleName">
          {{field.discript?field.discript:field.name}}
        </div>
        <vue-html5-editor :content="field.value" :name="field.name" :z-index="1002" @change="updateData"></vue-html5-editor>
      </div>
    </template>
    <template v-else>
      <!-- 鍙锛堟枃鏈ā寮忥級 -->
      <div class="html">
        <div class="titleName">
          {{field.discript?field.discript:field.name}}
        </div>
        <div :id="field.name+'_show'" class="titleName" v-html="field.value"></div>
      </div>
    </template>
  </span>
</template>

<script>
import Constant from "@/Constant.js";
import Vue from 'vue'


import VueHtml5Editor from 'vue-html5-editor'
import 'font-awesome/css/font-awesome.css'
Vue.use(VueHtml5Editor, {
  // 鍏ㄥ眬缁勪欢鍚嶇О锛屼娇鐢╪ew VueHtml5Editor(options)鏃惰閫夐」鏃犳晥 
  // global component name
  name: "vue-html5-editor",
  // 鏄惁鏄剧ず妯″潡鍚嶇О锛屽紑鍚殑璇濅細鍦ㄥ伐鍏锋爮鐨勫浘鏍囧悗鍙扮洿鎺ユ樉绀哄悕绉�
  // if set true,will append module name to toolbar after icon
  showModuleName: false,
  // 鑷畾涔夊悇涓浘鏍囩殑class锛岄粯璁や娇鐢ㄧ殑鏄痜ont-awesome鎻愪緵鐨勫浘鏍�
  // custom icon class of built-in modules,default using font-awesome
  icons: {
      text: "fa fa-pencil",
      color: "fa fa-paint-brush",
      font: "fa fa-font",
      align: "fa fa-align-justify",
      list: "fa fa-list",
      link: "fa fa-chain",
      unlink: "fa fa-chain-broken",
      tabulation: "fa fa-table",
      image: "fa fa-file-image-o",
      hr: "fa fa-minus",
      eraser: "fa fa-eraser",
      undo: "fa-undo fa",
      "full-screen": "fa fa-arrows-alt",
      info: "fa fa-info",
  },
  // 閰嶇疆鍥剧墖妯″潡
  // config image module
  image: {
      // 鏂囦欢鏈€澶т綋绉紝鍗曚綅瀛楄妭  max file size
      sizeLimit: 512 * 1024,
      // 涓婁紶鍙傛暟,榛樿鎶婂浘鐗囪浆涓篵ase64鑰屼笉涓婁紶
      // upload config,default null and convert image to base64
      upload: {
          url: null,
          headers: {},
          params: {},
          fieldName: {}
      },
      // 鍘嬬缉鍙傛暟,榛樿浣跨敤localResizeIMG杩涜鍘嬬缉,璁剧疆涓簄ull绂佹鍘嬬缉
      // compression config,default resize image by localResizeIMG (https://github.com/think2011/localResizeIMG)
      // set null to disable compression
      compress: {
          width: 1600,
          height: 1600,
          quality: 80
      },
      // 鍝嶅簲鏁版嵁澶勭悊,鏈€缁堣繑鍥炲浘鐗囬摼鎺�
      // handle response data锛宺eturn image url
      uploadHandler(responseText){
          //default accept json data like  {ok:false,msg:"unexpected"} or {ok:true,data:"image url"}
          var json = JSON.parse(responseText)
          if (!json.ok) {
              alert(json.msg)
          } else {
              return json.data
          }
      }
  },
  // 璇█锛屽唴寤虹殑鏈夎嫳鏂囷紙en-us锛夊拰涓枃锛坺h-cn锛�
  //default en-us, en-us and zh-cn are built-in
  language: "zh-cn",
  // 鑷畾涔夎瑷€
  i18n: {
      //specify your language here
      "zh-cn": {
          "align": "瀵归綈鏂瑰紡",
          "image": "鍥剧墖",
          "list": "鍒楄〃",
          "link": "閾炬帴",
          "unlink": "鍘婚櫎閾炬帴",
          "table": "琛ㄦ牸",
          "font": "鏂囧瓧",
          "full screen": "鍏ㄥ睆",
          "text": "鎺掔増",
          "eraser": "鏍煎紡娓呴櫎",
          "info": "鍏充簬",
          "color": "棰滆壊",
          "please enter a url": "璇疯緭鍏ュ湴鍧€",
          "create link": "鍒涘缓閾炬帴",
          "bold": "鍔犵矖",
          "italic": "鍊炬枩",
          "underline": "涓嬪垝绾�",
          "strike through": "鍒犻櫎绾�",
          "subscript": "涓嬫爣",
          "superscript": "涓婃爣",
          "heading": "鏍囬",
          "font name": "瀛椾綋",
          "font size": "鏂囧瓧澶у皬",
          "left justify": "宸﹀榻�",
          "center justify": "灞呬腑",
          "right justify": "鍙冲榻�",
          "ordered list": "鏈夊簭鍒楄〃",
          "unordered list": "鏃犲簭鍒楄〃",
          "fore color": "鍓嶆櫙鑹�",
          "background color": "鑳屾櫙鑹�",
          "row count": "琛屾暟",
          "column count": "鍒楁暟",
          "save": "纭畾",
          "upload": "涓婁紶",
          "progress": "杩涘害",
          "unknown": "鏈煡",
          "please wait": "璇风◢绛�",
          "error": "閿欒",
          "abort": "涓柇",
          "reset": "閲嶇疆"
      }
  },
  // 闅愯棌涓嶆兂瑕佹樉绀哄嚭鏉ョ殑妯″潡
  // the modules you don't want
  hiddenModules: [],
  // 鑷畾涔夎鏄剧ず鐨勬ā鍧楋紝骞舵帶鍒堕『搴�
  // keep only the modules you want and customize the order.
  // can be used with hiddenModules together
  visibleModules: [
      "text",
      "color",
      "font",
      "align",
      "list",
      "link",
      "unlink",
      "tabulation",
      "image",
      "hr",
      "eraser",
      "undo",
      "full-screen",
      "info",
  ],
  // 鎵╁睍妯″潡锛屽叿浣撳彲浠ュ弬鑰僥xamples鎴栨煡鐪嬫簮鐮�
  // extended modules
  modules: {
      //omit,reference to source code of build-in modules
  }
});

export default {
  name: "o-html",
  props: ["id"],
  computed: {
    field: function() {
      return this.$parent.findField(this.id);
    }
  },
  data: function() {
    return { Constant };
  },
  methods: {
    updateData(event){
      this.field.value = event;
    },
  }

};
</script>

<style lang="scss">
</style>