<style>
  .diy-link {
    width: 100%;
    padding: 30px 0;
    position: relative;
  }

  .diy-link>div {
    width: 100%;
  }

  .diy-link .title {
    flex-grow: 1;
    padding: 0 24px;
  }

  .diy-link .title>div {
    display: inline-block;
    vertical-align: middle;
  }

  .diy-link .arrow {
    width: 12px;
    height: 22px;
    position: absolute;
    right: 24px;
    top: 50%;
    margin-top: -6px;
  }

  .diy-component-edit .link-page .el-input-group__append {
    background-color: #fff
  }

  .diy-link .big-style {
    height: 50px;
    line-height: 50px;
    font-size: 36px;
  }

  .diy-link .big-style .title-icon {
    width: 50px;
    height: 50px;
    margin-right: 16px;
    vertical-align: middle;
  }

  .diy-link .medium-style {
    height: 36px;
    line-height: 36px;
    font-size: 28px;
  }

  .diy-link .medium-style .title-icon {
    width: 36px;
    height: 36px;
    margin-right: 16px;
    vertical-align: middle;
  }

  .diy-link .small-style {
    height: 28px;
    line-height: 28px;
    font-size: 24px;
  }

  .diy-link .small-style .title-icon {
    width: 28px;
    height: 28px;
    margin-right: 16px;
    vertical-align: middle;
  }

  .title-line {
    width: 82px;
    height: 5px;
    vertical-align: middle;
    margin: 0 20px;
  }

  .title-line.star {
    height: 20px;
    width: 28px;
  }

  .title-line.star .top-icon {
    width: 28px;
    height: 4px;
    margin-bottom: 12px;
  }

  .title-line.star .bottom-icon {
    width: 28px;
    height: 4px;
  }

  .title-line.div {
    width: 8px;
    height: 28px;
    margin: 0 10px 0 0;
  }

  .title-line.radius {
    width: 28px;
    height: 28px;
    margin: 0 10px 0 0;
    border-radius: 14px;
    border: 2px solid #353535;
  }

  .link-gallery-item {
    width: 100px;
    height: 100px;
    border: 1px solid #e3e3e3;
    border-radius: 2px;
    margin-right: 10px;
    margin-bottom: 10px;
    position: relative;
  }

</style>
<template>
  <div :class="{'active':linkData.isCked}">
    <div class="diy-component-options" v-if="linkData.isCked">
      <el-button type="primary" icon="el-icon-delete" style="left: -25px; top: 0px;" @click="delPlugin()"></el-button>
      <el-button type="primary" icon="el-icon-document-copy" style="left: -25px; top: 30px;"></el-button>
      <el-button type="primary" icon="el-icon-arrow-up" v-if="index>0" @click="resetSord(0)"
        style="right: -25px; top: 0;"></el-button>
      <el-button type="primary" icon="el-icon-arrow-down" v-if="index!=dataLeng-1" @click="resetSord(1)"
        style="right: -25px; top: 30px;"></el-button>
    </div>
    <div class="diy-component-preview">
      <div class="diy-link" :style="cStyle" flex="cross:center">
        <div :class="style" flex="dir:left cross:center">
          <div v-if="data.style == 1" class="title" :style="{textAlign: data.position}">
            <img v-if="data.picSwitch" class="title-icon" :src="data.picUrl" alt="">
            <div style="font-weight: 600">{{data.title?data.title:'这里是标题示例'}}</div>
          </div>
          <div v-else-if="data.style == 2" class="title" style="text-align: center">
            <img :style="{backgroundColor: data.styleColor}" class="title-line"
              :src="domainManager().ImageUrl+'/Static/line-style.png'">
            <div style="font-weight: 600">{{data.title?data.title:'这里是标题示例'}}</div>
            <img :style="{backgroundColor: data.styleColor}" class="title-line"
              :src="domainManager().ImageUrl+'/Static/line-style.png'">
          </div>
          <div v-else-if="data.style == 3" class="title" style="text-align: center">
            <div class="title-line star">
              <div :style="{backgroundColor: data.styleColor}" class="top-icon"></div>
              <div :style="{backgroundColor: data.styleColor}" class="bottom-icon"></div>
            </div>
            <div style="font-weight: 600">{{data.title?data.title:'这里是标题示例'}}</div>
            <div class="title-line star">
              <div :style="{backgroundColor: data.styleColor}" class="top-icon"></div>
              <div :style="{backgroundColor: data.styleColor}" class="bottom-icon"></div>
            </div>
          </div>
          <div v-else-if="data.style == 4" class="title" style="text-align: left">
            <img :style="{backgroundColor: data.styleColor}" class="title-line div"
              :src="domainManager().ImageUrl+'/Static/div-style.png'">
            <div style="font-weight: 600">{{data.title?data.title:'这里是标题示例'}}</div>
          </div>
          <div v-else-if="data.style == 5" class="title" style="text-align: left">
            <div :style="[{'borderColor':data.styleColor,'backgroundColor':data.background}]" class="title-line radius">
            </div>
            <div style="font-weight: 600">{{data.title?data.title:'这里是标题示例'}}</div>
          </div>
          <img class="arrow" :src="domainManager().ImageUrl+'/Static/icon-jiantou-r.png'" v-if="data.arrowsSwitch">
        </div>
      </div>
    </div>
    <div class="diy-component-edit" v-if="linkData.isCked">
      <el-form label-width="100px" @submit.native.prevent>
        <el-form-item label="标题">
          <label slot="label">标题
            <el-tooltip class="item" effect="dark" content="标题长度不超过30个字" placement="top">
              <i class="el-icon-info"></i>
            </el-tooltip>
          </label>
          <el-input size="small" v-model="data.title" maxlength="30"></el-input>
        </el-form-item>
        <el-form-item label="字体大小">
          <el-radio v-model="data.fontSize" label="36">大</el-radio>
          <el-radio v-model="data.fontSize" label="28">中</el-radio>
          <el-radio v-model="data.fontSize" label="24">小</el-radio>
        </el-form-item>
        <el-form-item label="文字颜色">
          <el-color-picker size="small" v-model="data.color"></el-color-picker>
          <el-input size="small" style="width: 80px;margin-right: 25px;" v-model="data.color"></el-input>
        </el-form-item>
        <el-form-item label="背景颜色">
          <el-color-picker size="small" v-model="data.background"></el-color-picker>
          <el-input size="small" style="width: 80px;margin-right: 25px;" v-model="data.background"></el-input>
        </el-form-item>
        <el-form-item label="标题样式">
          <el-radio v-model="data.style" label="1">样式1</el-radio>
          <el-radio v-model="data.style" label="2">样式2</el-radio>
          <el-radio v-model="data.style" label="3">样式3</el-radio>
          <el-radio v-model="data.style" label="4">样式4</el-radio>
          <el-radio v-model="data.style" label="5">样式5</el-radio>
        </el-form-item>
        <el-form-item v-if="data.style == '1'" label="标题位置">
          <el-radio v-model="data.position" label="left">居左</el-radio>
          <el-radio v-model="data.position" label="center">居中</el-radio>
          <el-radio v-model="data.position" label="right">居右</el-radio>
        </el-form-item>
        <el-form-item v-if="data.style != '1'" label="样式颜色">
          <el-color-picker v-model="data.styleColor"></el-color-picker>
          <el-input size="small" style="width: 80px;margin-right: 25px;" v-model="data.styleColor"></el-input>
        </el-form-item>
        <el-form-item label="链接页面">
          <el-input size="small" class="link-page" v-model="data.link.name">
            <template slot="append">
              <el-button @click="isShowLink=true">选择链接</el-button>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item v-if="data.style == '1'" label="图标开关">
          <el-switch v-model="data.picSwitch"></el-switch>
        </el-form-item>
        <template v-if="data.picSwitch">
          <el-form-item label="图标">
            <label slot="label">图标
              <el-tooltip class="item" effect="dark" content="最大宽度750px，最大高度36px，图标等比例缩放" placement="top">
                <i class="el-icon-info"></i>
              </el-tooltip>
            </label>
            <el-button size="mini" @click="choicImg=true">选择图标</el-button>
            <div flex="main:center cross:center" class="link-gallery-item">
              <img v-if="data.picUrl!=''" style="max-width:100%;max-height: 100%;" :src="getIconLink(data.picUrl)" />
            </div>
          </el-form-item>
        </template>
        <el-form-item label="箭头开关">
          <el-switch v-model="data.arrowsSwitch"></el-switch>
        </el-form-item>
      </el-form>
    </div>
    <!-- 选择图片文件 -->
    <el-dialog title="选择文件" :visible.sync="choicImg" width="1240px">
      <ChooseImg @SelectId="SelectId"></ChooseImg>
    </el-dialog>
    <el-dialog title="选择链接" :visible.sync="isShowLink" width="800px">
      <chooseMenu ref="chooseMenu"></chooseMenu>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="isShowLink=false">取 消</el-button>
        <el-button size="small" type="danger" @click="getChoiceLink()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import ChooseImg from "@/components/global/ChooseImg.vue";
  import chooseMenu from "../../common/chooseMenu.vue";
  export default {
    props: ["linkData", "index", "dataLeng"],
    components: {
      ChooseImg,
      chooseMenu
    },
    data() {
      return {
        choicImg: false,
        isShowLink: false,
        data: this.linkData.data,
      };
    },
    watch: {
      linkData(newVal, oldVal) {
        this.data = this.linkData.data;
      },
    },
    created() {

    },
    methods: {
      //向父组件传值 并调用排序
      resetSord(IsUp) {
        this.$emit('getSord', this.index, IsUp);
      },
      //点击触发父组件删除
      delPlugin() {
        this.$emit('comDelPlugin', this.index);
      },
      //选择图片
      SelectId(msg) {
        this.data.picUrl = this.getIconLink(msg.url);
        this.choicImg = false;
      },
      //获取选择链接
      getChoiceLink() {
        //调用子组件方法
        var obj = this.$refs.chooseMenu.getChooseMenu();
        this.data.link.name = obj.PageName;
        this.data.link.url = obj.PageUrl;
        this.isShowLink = false;
      },

    },
    computed: {
      cStyle() {
        if (this.data.background) {
          return `color: ${this.data.color};` +
            `background: ${this.data.background};`
        } else {
          return `color: ${this.data.color};`
        }
      },
      style() {
        if (this.data.fontSize == '36') {
          return `big-style`
        } else if (this.data.fontSize == '28') {
          return `medium-style`
        } else {
          return `small-style`;
        }
      }
    },
    mounted() {

    }
  };

</script>
