<template>
<div class='m-container'>
    <h2>
      <el-page-header @back="onCancel" :content="titleName"></el-page-header>
    </h2>
    <div class="m-core">
      <save-form
        :inline="true"
        ref="searchForm"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
      >
        <el-form-item prop="search">
          <el-input
            v-model.trim="searchForm.search"
            clearable
            @keyup.enter.native="search"
            placeholder="编号/姓名/手机号"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="primary">搜索</el-button>
          <el-button native-type="reset" type="danger">重置</el-button>
          <el-button type="primary" @click="onExport" v-if="$helpers.permission('questionnaireUserResult/export')">导出</el-button>
        </el-form-item>
      </save-form>
      <el-card class="box-card" v-for="item in tableList" :key="item.id">
          <el-row>
            <el-col :xs="24" :sm="24" :md="6" :lg="5" :xl="5">
              <el-form label-position="left" inline label-width="90px" class="demo-table-expand">
                <el-form-item label="学生编号">
                  <span><copy-text>{{ item.userId}}</copy-text></span>
                </el-form-item>
                <el-form-item label="学生姓名">
                  <span><copy-text>{{ item.username}}</copy-text></span>
                </el-form-item>
                <el-form-item label="学生手机号">
                  <span><copy-text>{{ item.phone}}</copy-text></span>
                </el-form-item>
              </el-form>
              <!-- <el-row :gutter="10" style="font-size: 14px">
                <el-col :span="24" style="padding-bottom: 8px"><>学生编号：<copy-text>{{ item.userId}}</copy-text></el-col>
                <el-col :span="24" style="padding-bottom: 8px">学生姓名：<copy-text>{{ item.username}}</copy-text></el-col>
                <el-col :span="24" style="padding-bottom: 8px">学生手机号：<copy-text>{{ item.phone}}</copy-text></el-col>
              </el-row> -->
            </el-col>
            <el-col :xs="24" :sm="24" :md="18" :lg="19" :xl="19">
              <el-collapse>
                <el-collapse-item title="查看答案" name="1">
                  <div v-for="(o, index) in item.questionnaireResultDtoList" :key="index" class="text item">
                    <el-alert :title="o.content" type="info" :closable="false"></el-alert>
                    <div style="padding: 8px 20px; font-size: 14px;" v-if="o.answerValue || o.additionalValue">{{ o.answerValue ? o.answerValue : o.additionalValue }}</div>
                    <!-- <div style="padding: 8px 20px; font-size: 14px;" v-else>未答题</div> -->
                    <el-tag style="margin: 8px 20px; font-size: 14px;" type="danger" v-else>未答题</el-tag>
                  </div>
                </el-collapse-item>
              </el-collapse>
              <!-- <div v-for="(o, index) in item.questionnaireResultDtoList" :key="index" class="text item">
                <el-alert :title="o.content" type="info" :closable="false"></el-alert>
                <div style="padding: 8px 20px; font-size: 14px;">{{ o.answerValue }}</div>
              </div> -->
            </el-col>
          </el-row>
      </el-card>
      <empty v-if="tableList.length <= 0" />
      <pagination
          sync
          :total.sync="pageInfo.total"
          :page.sync="pageInfo.page"
          :limit.sync="pageInfo.limit"
          :page-sizes="pageInfo.page_size"
          @pagination="getList"
        />
    </div>
</div>
</template>
<script>
import { questionnaireUserResultQueryPage } from './api'
import { Export } from '@/utils/downLoadFile'
import pagination from "@/components/Pagination/index";
export default {
    name: 'operationQuestion',
    components: { pagination },
    data () {
        let query = this.$route.query
        let titleName = '问答详情'
        return {
            titleName: titleName,
            id: query.id,
            topicId: query.topicId,
            searchForm: {
              search: null,
            },
            tableList: [],
            pageInfo: {
              // 分页规则
              limit: 10, // 限制显示条数
              page: 1, // 当前页
              total: 0, // 总条数
              page_size: [10, 20, 40, 50], // 选择限制显示条数
            },
        }
    },
    async mounted () {
      this.getList()
    },
    methods: {
      search() {
        this.pageInfo.page = 1;
        this.getList();
      },
      onReSet() {
        this.$refs.searchForm.resetFields();
        this.search();
      },
      async getList() {
        try {
          let params = {
            activeId: this.id,
            activeType: 'REPLACEMENT',
            page: this.pageInfo.page,
            rows: this.pageInfo.limit,
            ...this.searchForm
          }
          let result = await questionnaireUserResultQueryPage(params)
          this.tableList = result.data.rows
          this.pageInfo.total = result.data.total
        } catch {

        }
      },
      onCancel() {
        this.$store.dispatch('delVisitedViews', this.$route)
        this.$router.push({ path: '/otherManager/reaplceMusicPlayer' })
      },
      onExport() {
        Export(this, {
          url: '/api-web/questionnaireUserResult/export',
          fileName: '问答详情.xls',
          method: 'get',
          params: { cooperationId: this.id }
        }, '您确定导出问答详情?')
      }
    }
}
</script>
<style lang="scss" scoped>
.box-card {
  margin-bottom: 10px;
}
/deep/.el-collapse-item__header {
  background: #EDEEF0;
  color: #444;
  padding: 0 10px;
}
/deep/.el-collapse-item__wrap {
  border: 0;
}
/deep/.el-collapse-item__content {
  padding-bottom: 0;
}

.demo-table-expand {
    font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 100%;
}
</style>