<template>
  <div>
    <div class="panel-fieldset">
      <h4 class="panel-legend">定时发布</h4>
      <el-form-item label="定时全量发布启用状态：">
        <el-switch v-model="extend.cronPublishEnable" :disabled="disabled" active-value="Y" inactive-value="N"></el-switch>
      </el-form-item>
      <el-form-item label="定时全量发布起始时间：">
        <el-date-picker v-model="extend.cronPublishStartTime" type="datetime" placeholder="选择日期时间" :disabled="extend.cronPublishEnable!=='Y' || disabled" value-format="yyyy-MM-dd HH:mm:ss" class="form-item"></el-date-picker>
      </el-form-item>
      <el-form-item label="定时发布执行周期：">
        每隔
        <el-input v-model="extend.cronPublishPeriod" :disabled="extend.cronPublishEnable!=='Y' || disabled" style="width:54px;"></el-input>
        <el-select v-model="extend.cronPublishPeriodType" :disabled="extend.cronPublishEnable!=='Y' || disabled">
          <el-option label="小时" value="Hour"></el-option>
          <el-option label="天" value="day"></el-option>
          <el-option label="月" value="month"></el-option>
        </el-select>
      </el-form-item>
    </div>

    <div class="panel-fieldset">
      <h4 class="panel-legend">站点资源水印图片设置</h4>
      <el-form-item label="水印图片：">
        <water-path
          :path.sync="extend.waterImagePath"
          :site-id="siteID"
          :prefix="extend.prefix"
          :disabled="disabled"
        ></water-path>
      </el-form-item>
      <el-form-item label="水印位置：">
        <water-position-picker :position.sync="extend.waterImagePosition" :disabled="disabled"></water-position-picker>
      </el-form-item>
    </div>

    <div class="panel-fieldset">
      <h4 class="panel-legend">发布平台配置</h4>
      <el-form-item label="发布平台：">
        <el-checkbox-group v-model="extend.publishPlatform" :disabled="disabled">
          <el-checkbox v-for="item in plantforms" :key="item.ID" :label="item.ID">{{item.name}}</el-checkbox>
        </el-checkbox-group>
        <router-link to="/datachannel/publishPlatform" :disabled="disabled">发布平台管理</router-link>
      </el-form-item>
    </div>

    <div class="panel-fieldset">
      <h4 class="panel-legend">静态化配置</h4>
      <el-form-item label="静态化文件类型：">
        <el-select v-model="extend.staticFileType" clearable class="form-item" :disabled="disabled">
          <el-option v-for="item in staticFileTypeSelection" :key="item.value" :label="item.key" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="站点前端动态地址：">
        <el-input v-model="extend.frontAppContxtAddr" class="form-item" :disabled="disabled"></el-input>
      </el-form-item>
    </div>

    <div class="panel-fieldset">
      <h4 class="panel-legend">内容标题查重配置</h4>
      <el-form-item label="内容标题查重选项：">
        <el-select v-model="extend.contentTitleCheckType" class="form-item" :disabled="disabled">
          <el-option v-for="item in contentTitleCheckTypeSelection" :key="item.value" :label="item.key" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
    </div>

    <div class="panel-fieldset">
      <h4 class="panel-legend">栏目配置</h4>
      <el-form-item label="栏目默认是否启用：">
        <el-switch v-model="extend.catalogVisibleFlag" :disabled="disabled" active-value="Y" inactive-value="N"></el-switch>
      </el-form-item>
      <el-form-item label="栏目是否启用重名校验：">
        <el-switch v-model="extend.catalogNameRepeat" :disabled="disabled" active-value="Y" inactive-value="N"></el-switch>
      </el-form-item>
      <el-form-item label="是否允许栏目撤销：">
        <el-switch v-model="extend.catalogUndoEnable" :disabled="disabled" active-value="Y" inactive-value="N"></el-switch>
      </el-form-item>
    </div>

    <div class="panel-fieldset">
      <h4 class="panel-legend">历史版本数量上限配置</h4>
      <el-form-item label="保留历史版本数量：">
        <el-input-number v-model="extend.historyVersionLimit" :min="1" :max="1000000" :disabled="disabled"></el-input-number>
      </el-form-item>
    </div>

  </div>
</template>
<script>
import WaterPath from './WaterPath.vue'
import WaterPositionPicker from './WaterPositionPicker.vue'

export default {
  data() {
    return {
      plantforms: [],
      staticFileTypeSelection: [], // 静态化文件类型下拉款值
      contentTitleCheckTypeSelection: [] // 内容标题查重选项
    }
  },
  computed: {
    extend: {
      get() {
        return this.extends
      },
      set(val) {
        this.$emit('update:extends', val)
      }
    }
  },
  methods: {
    imageCuttingCallback(sPath, path) {
      this.extend.waterImagePath = path
    }
  },
  async created() {
    let getPlatform = await axios.get('/ui/publishplatform')
    this.plantforms = getPlatform.data.data
    let getStaticFileType = await axios.get('/ui/staticfiletype')
    this.staticFileTypeSelection = getStaticFileType.data.data
    let getContentTitleCheckType = await axios.get(
      '/ui/sitecontenttitlechecktypes'
    )
    this.contentTitleCheckTypeSelection = getContentTitleCheckType.data.data
  },
  props: {
    extends: {
      type: Object,
      default: function () {
        return {
          cronPublishEnable: 'N', // 定时发布启用状态
          cronPublishStartTime: '', // 定时发布起始时间
          cronPublishPeriod: '', // 定时发布执行周期
          cronPublishPeriodType: '',
          waterImageSrc: '', // 水印图片
          waterImagePosition: '9', // 水印位置
          publishPlatform: ['pc'], // 发布平台
          staticFileType: '.shtml', // 静态化文件类型
          frontAppContxtAddr: '', // 站点前端动态地址
          contentTitleCheckType: 'Site', // 内容标题查重选项
          catalogVisibleFlag: 'Y', // 栏目默认是否启用
          catalogNameRepeat: 'Y', // 栏目是否启用重名校验
          catalogUndoEnable: 'N', // 栏目是否允许栏目撤销
          historyVersionLimit: 1 // 保留历史版本数量
        }
      }
    },
    siteID: {
      type: [String, Number],
      default: 0
    },
    disabled: {
      type: Boolean
    }
  },
  components: {
    'water-path': WaterPath,
    'water-position-picker': WaterPositionPicker
  }
}
</script>
