<template>
  <el-form label-width="160px" style="margin-top:140px" :rules="tagRules" ref="tagForm">
    <el-form-item label="友情链接：">
      <el-select filterable placeholder="" v-model="link" class="form-item">
        <el-option v-for="item in links" :key="item.ID" :label="item.name" :value='item.code'>
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="链接类型：">
      <el-radio-group  v-model="linkType">
        <el-radio label="word">文字</el-radio>
        <el-radio label="image">图片</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="显示数目：" prop="count">
      <el-input v-model="count" class="form-item"></el-input>
    </el-form-item>
  </el-form>
</template>
<script>
/* eslint-disable no-template-curly-in-string */
import util from '@src/common/util.js'
export default {
  data() {
    return {
      link: '',
      linkType: 'word',
      links: [],
      count: '10',
      tagRules: {
        count: [
          { required: true, message: '请输入显示数目', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    getCode() {
      if (!this.count) {
        util.showErrorMessageBox('请输入显示数目')
        return ''
      }
      let str = `<cms:link code="${this.link}" count="${this.count}">\n`
      str += '  <z:list>'
      str += '<a href="${Link.URL}" target="_blank">'
      if (this.linkType === 'image') {
        str += '<img src="${Link.ImagePath}" alt="${Link.Name}"/>'
      } else {
        str += '${Link.Name}'
      }
      str += '</a>'
      str += '</z:list>\n'
      str += '</cms:link>'
      return str
    },
    async init() {
      let res = await axios.get('/ui/links')
      this.links = res.data.status === 1 ? res.data.data : this.links
    }
  },
  async created() {
  }
}
</script>
