<!--
 * @Author: zwq
 * @Date: 2022-08-11 16:22:07
 * @LastEditors: zwq
 * @LastEditTime: 2022-08-11 16:48:39
 * @Description:
-->
<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      style="display: flex; align-items: center; justify-content: right;"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          size="small"
          v-model="key"
          placeholder="搜索问题"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="getDataList()">
          <icon-svg class="iconClass" name="sousuo"></icon-svg>
          查询
        </el-button>
        <el-button size="small" type="primary" @click="addOrUpdateHandle()">
          <icon-svg class="iconClass" name="新建"></icon-svg>
          新增
        </el-button>
      </el-form-item>
    </el-form>
    <el-collapse v-model="activeNames">
      <el-collapse-item
        v-for="(item, index) in problemArr"
        :key="index"
        :name="index"
      >
        <template slot="title">
          <span style="color:#409EFF">
            {{ item.question }}<i class="el-icon-question"></i>
          </span>
        </template>
        <div>
          {{ item.answer }}
        </div>
      </el-collapse-item>
    </el-collapse>
    <!-- 弹窗, 新增 / 修改 -->
    <problem-add
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
    ></problem-add>
  </div>
</template>

<script>
import ProblemAdd from './Problem-add'
export default {
  data () {
    return {
      key: '',
      addOrUpdateVisible: false,
      activeNames: [],
      problemArr: []
    }
  },
  components: {
    ProblemAdd
  },
  created () {
    this.getDataList()
  },
  methods: {
    getDataList () {
      this.$http({
        url: this.$http.adornUrl('/questionAnswer/page'),
        method: 'post',
        data: this.$http.adornData({
          current: 1,
          size: 200,
          key: this.key
          // paramKey: this.dataForm.paramKey
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.problemArr = data.data.records
        } else {
          this.problemArr = []
        }
      })
    },
    // 新增
    addOrUpdateHandle () {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>

<style></style>
