<template>
  <base-form slot="content" :data="searchData" ref="ruleForm">
    <div slot="footer">
      <el-button :loading="listLoading" icon="el-icon-search" class="xl-form-btn bgc1" @click="searchHandle">查询小程序主题：{{this.parentData.$route.query.theme_name}}</el-button>
      <el-button :loading="listLoading" class="xl-form-btn bgc2" @click="createHandle" v-if="this.parentData.tableData.length === 0">一键生成模板</el-button>
    </div>
  </base-form>
</template>
<script>
export default {
  props: {
    listLoading: Boolean
  },
  inject: ['parentData'],
  data () {
    return {
      searchData: [
        {label: '标题', key: 'title'},
        {label: '链接', key: 'link'},
        {label: '分类', key: 'type', type: 'select', options: this.$dictData.app_theme_type},
        {label: '状态', key: 'hide_status', type: 'select', options: this.$dictData.hide_status},
      ]
    }
  },
  methods: {
    createHandle () {
      this.$api.other.admthemetemplate({
        theme_id: this.parentData.$route.query.id
      }).then(res => {
        this.parentData.fetchData()
      })
    },
    searchHandle () {
      const oldform = this.$refs.ruleForm.baseForm
      let newForm = {...oldform}
      newForm.theme_id = this.parentData.$route.query.id
      this.$emit('change', newForm)
    },
  }
}
</script>
