<template>
  <el-form label-width="100px" >
    <el-form-item label="模板类型：" prop="tempType">
      <el-radio-group v-model="tempType">
        <el-radio label="indexTemp">首页模板</el-radio>
        <el-radio label="designatedTemp">列表页模板[指定具体栏目]</el-radio>
        <el-radio label="listTemp">列表页模板</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="指定栏目：" prop="catalog" v-show="tempType!=='listTemp'">
      <tree-select :value.sync="catalog" :clearable="true" :items="catalogTree" @click-change="onTreeClick" width="80%" placeholder="请选择栏目">
      </tree-select>
    </el-form-item>
    <el-form-item label="分页设置：">
      每页视频数<el-input-number size="small" controls-position="right" :min='1' v-model="lineCount"></el-input-number>
      视频标题字数<el-input-number size="small" controls-position="right" :min='1' v-model="charWidth"></el-input-number>
    </el-form-item>
    <el-form-item label="显示层级：">
      <el-select filterable placeholder="" v-model="level" class="form-item">
        <el-option v-for="item in levels" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="排序类型：">
      <el-select filterable placeholder="" v-model="orderType" class="form-item">
        <el-option v-for="item in OrderTypes" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="布局类型：" prop="layoutType">
      <el-radio-group  v-model="layoutType">
        <el-radio label="li">列表[li]</el-radio>
        <el-radio label="br">换行[br]</el-radio>
        <el-radio label="tr">表格[tr]</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="其他选项：">
      <el-checkbox v-model="dateAdd">在视频标题后添加发布日期，日期格式为</el-checkbox>
      <el-select filterable placeholder="" v-model="dateFormat" :disabled="!dateAdd">
        <el-option v-for="item in dateFormats" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
  </el-form>
</template>
<script>
/* eslint-disable no-template-curly-in-string */
import TreeSelect from '@src/components/TreeSelect.vue'
export default {
  data() {
    return {
      dateAdd: false,
      tempType: 'indexTemp',
      level: 'Root',
      lineCount: 15,
      charWidth: 30,
      catalogTree: [],
      catalog: 0,
      alias: '',
      types: [],
      layoutType: 'li',
      levels: [
        {
          value: 'Root',
          label: '所有根栏目的视频'
        }, {
          value: 'Current',
          label: '当前栏目下的视频'
        }, {
          value: 'Child',
          label: '当前栏目下子栏目的所有视频(不包含当前栏目)'
        }, {
          value: 'CurrentAndChild',
          label: '当前栏目下子栏目的所有视频(包含当前栏目)'
        }
      ],
      orderType: 'Recent',
      OrderTypes: [
        {
          value: 'Recent',
          label: '按发布时间'
        }, {
          value: 'Relate',
          label: '按相关新闻'
        }, {
          value: 'Hot',
          label: '按点击率'
        }
      ],
      dateFormat: '',
      dateFormats: [
        {
          value: 'yyyy-MM-dd',
          label: 'yyyy-MM-dd'
        }, {
          value: 'yyyy年MM月dd日',
          label: 'yyyy年MM月dd日'
        }, {
          value: 'yyyy-MM-dd HH:mm:ss',
          label: 'yyyy-MM-dd HH:mm:ss'
        }
      ]
    }
  },
  methods: {
    onTreeClick(data) {
      this.alias = data.alias
    },
    getCode() {
      let curCatalog = `catalogAlias="${this.alias}"`
      if (this.tempType === 'listTemp') {
        curCatalog += ` pagesize="${this.lineCount}" page="true"`
      } else if (this.tempType === 'designatedTemp') {
        curCatalog += ` pagesize="${this.lineCount}" page="true"`
      } else {
        curCatalog += ` count="${this.lineCount}"`
      }
      let str
      if (this.layoutType === 'li') {
        str = '<ul>\n'
        str += `  <cms:video ${curCatalog} type="${this.orderType}" level="${this.level}">\n`
        str += '    <z:list>\n'
        str += '      <li><a href="${Video.Link}" title="${Video.Title}">'
        str += '$' + `{charWidth(Video.Title, ${this.charWidth},"...")}`
        str += '</a>'
        if (this.dateAdd) {
          str += '$' + `{format(Video.PublishDate,"${this.dateFormat}")}`
        }
        str += '</li>\n'
        str += '    </z:list>\n'
        str += '  </cms:video>\n'
        str += '</ul>'
      } else if (this.layoutType === 'br') {
        str = `  <cms:video ${curCatalog} type="${this.orderType}" level="${this.level}">\n`
        str += '    <z:list>\n'
        str += '      <a href="${Video.Link}" title="${Video.Title}">'
        str += '$' + `{charWidth(Video.Title, ${this.charWidth},"...")}`
        str += '</a>'
        if (this.dateAdd) {
          str += '$' + `{format(Video.PublishDate,"${this.dateFormat}")}`
        }
        str += '    <br/></z:list>\n'
        str += '  </cms:video>\n'
      } else if (this.layoutType === 'tr') {
        str = '<table cellspace="1" border="0">\n'
        str += `  <cms:video ${curCatalog} type="${this.orderType}" level="${this.level}">\n`
        str += '    <z:list>\n'
        str += '      <tr><td><a href="${Video.Link}" title="${Video.Title}">'
        str += '$' + `{charWidth(Video.Title, ${this.charWidth},"...")}`
        str += '</a>'
        if (this.dateAdd) {
          str += '$' + `{format(Video.PublishDate,"${this.dateFormat}")}`
        }
        str += '</td></tr>\n'
        str += '    </z:list>\n'
        str += '  </cms:video>\n'
        str += '</table>'
      }
      return str
    },
    async init() {
      let catalogTreeResp = await axios.get('/ui/catalog')
      this.catalogTree = catalogTreeResp.data.data
    }
  },
  watch: {
  },
  async created() {
  },
  mounted() {

  },
  components: {
    'tree-select': TreeSelect
  }
}
</script>
