<template>
    <div>
      <div ref="table">
        <el-form
          ref="queryForm"
          :model="informationqueryParams"
          label-width="80px"
          :inline="true"
        >
          <el-form-item label="问卷标题" prop="questionnaireName">
            <el-input
              v-model="informationqueryParams.questionnaireName"
              placeholder="请输入问卷标题"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="病种名称" prop="diseaseTypeName">
            <el-input
              v-model="informationqueryParams.diseaseTypeName"
              placeholder="请输入病种名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="informationInfoinfo"
              >搜索</el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="addresetQuerylist"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
  
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="infolist"
          @selection-change="handleSelectionChange"
          :row-key="getRowKey"
          @cell-dblclick="handleRowDbClick"
        >
          <el-table-column
            type="selection"
            width="55"
            align="center"
            :reserve-selection="true"
          />
          <el-table-column label="序号" type="index" width="48" align="center" />
          <!-- <el-table-column
            label="问卷模板名称"
            align="center"
            prop="questionnaireName"
          /> -->
          <el-table-column label="问题个数" align="center" prop="questionCount" />
          <el-table-column
            label="问卷模板ID"
            align="center"
            prop="questionnaireId"
          />
          <el-table-column label="问卷类型" align="center" prop="questionType">
            <template slot-scope="scope">
              <div v-if="scope.row.questionType == 'REGULAR_QUESTIONNAIRE'">
                普通问卷
              </div>
              <div v-if="scope.row.questionType == 'SATISFACTION_QUESTIONNAIRE'">
                满意度问卷
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="问卷状态"
            align="center"
            prop="questionnaireStatus"
          >
            <template slot-scope="scope">
              <el-tag
                type="success"
                v-if="scope.row.questionnaireStatus == 'PUBLISHED'"
                >已发布</el-tag
              >
              <el-tag type="warning" v-else>未发布</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="病种名称"
            align="center"
            prop="diseaseTypeName"
          />
        </el-table>
        <div class="bottom">
          <myPagination
            v-show="totaldepartment > 0"
            :total="totaldepartment"
            :pageSize="informationqueryParams.pageSize"
            :indexFromWrap="informationqueryParams.pageNum"
            @updateCPage="updateCPagetwo"
          ></myPagination>
        </div>
      </div>
    </div>
  </template>
    <script>
  import { getBaseList } from "@/api/system/exportinfo";
  export default {
    data() {
      return {
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        infolist: [],
        loading: false,
        datalist: [],
        informationqueryParams: {
          pageNum: 1,
          pageSize: 10,
          type: 'QUESTION',
          questionnaireStatus:'PUBLISHED',
          hospitalAgencyId: 46,
          questionnaireName: null,
          diseaseTypeName: null,
        },
        totaldepartment: 0,
  
      }
    },
    watch: {
      datalist(val) {
        this.$emit('submit', val);
      },
    },
    created() {
      this.informationInfoinfo()
    },
    methods: {
      resetTable() {
        this.$refs.multipleTable.clearSelection();
      },
      // 列表
      informationInfoinfo() {
        getBaseList(this.informationqueryParams).then((response) => {
          this.infolist = response.rows;
          this.totaldepartment = response.total;
          this.loading = false;
        });
      },
      getRowKey(row) {
        return row.id
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        // this.datalist = selection
        this.datalist = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      handleRowDbClick(row, column, event) {// 双击选中该行
        const index = this.datalist.indexOf(row);
        console.log(index, '0000000000')
        if (index !== -1) {
          this.datalist.splice(index, 1);
        } else {
          this.datalist.push(row);
        }
        // 通过`toggleRowSelection`方法来切换选中状态
        this.$refs.multipleTable.toggleRowSelection(row, index === -1);
      },
      // 重置
      addresetQuerylist() {
        this.informationqueryParams = {
          pageNum: 1,
          pageSize: 10,
          type: 'QUESTION',
          questionnaireStatus:'PUBLISHED',
          hospitalAgencyId: 46,
        };
        this.informationInfoinfo();
      },
      // 分页
      updateCPagetwo(index, size) {
        this.informationqueryParams.pageNum = index
        this.informationqueryParams.pageSize = size
        this.informationInfoinfo();
      },
    },
    mounted() {
  
    },
  
  }
    </script>
    
    <style lang="scss" scoped>
  .bottom {
    .pagination {
      bottom: 62px !important;
    }
  }
  </style>