<style>

</style>
<template>
  <div :class="{'active':copyData.isCked}">
    <div class="diy-component-options" v-if="copyData.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 style="padding: 28px 28px;" :style="cStyle" flex="main:center cross:center">
        <div>
          <div v-if="data.picUrl" style="text-align: center;">
            <img :src="getIconLink(data.picUrl)" style="width: 160px;height: 50px;">
          </div>
          <div style="text-align: center;color: #333;">{{data.text}}</div>
        </div>
      </div>
    </div>
    <div class="diy-component-edit" v-if="copyData.isCked">
      <el-form label-width="100px" @submit.native.prevent>
        <el-form-item label="版权文字">
          <el-input size="small" v-model="data.text"></el-input>
        </el-form-item>
        <el-form-item label="版权图标">
          <div class="zk_pic_box" @click="choicImg=true" flex="main:center cross:center"
            :style="{backgroundImage:'url(' + getIconLink(data.picUrl) + ')'}">
            <i v-if="data.picUrl==''" class="el-icon-picture-outline"></i>
            <div class="size-tip">50 × 50</div>
            <el-button type="danger" v-if="data.picUrl!=''" class="image-delete" size="mini" icon="el-icon-close"
              @click.stop="data.picUrl=''" circle></el-button>
          </div>
        </el-form-item>
        <el-form-item class="chooseLink" label="版权链接">
          <!--:disabled="true"-->
          <el-input v-model="data.link" placeholder="点击选择链接"  size="small">
            <el-button slot="append" size="small" @click="isShowLink=true">选择链接</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="背景颜色">
          <el-color-picker size="small" v-model="data.backgroundColor"></el-color-picker>
          <el-input size="small" style="width: 80px;margin-right: 25px;" v-model="data.backgroundColor"></el-input>
        </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: ["copyData", "index", "dataLeng"],
    components: {
      ChooseImg,
      chooseMenu
    },
    data() {
      return {
        choicImg: false,
        isShowLink: false,
        data: this.copyData.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=obj.PageUrl
        this.isShowLink = false;
      },
    },
    computed: {
      cStyle() {
        if (this.data.backgroundColor) {
          return `background-color: ${this.data.backgroundColor};`
        } else {
          return ``
        }
      },

    },
    mounted() {

    }
  };

</script>
