<template>
  <div>
    <div ref="table">
      <el-form
        ref="queryForm"
        :model="informationqueryParams"
        label-width="80px"
        :inline="true"
      >
      <el-form-item
              label="微信模版名称"
              prop="wechatTemplateName"
              label-width="100px"
            >
              <el-input
                v-model="informationqueryParams.wechatTemplateName"
                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
              type="index"
              width="52"
              align="center"
              label="序号"
            />
            <el-table-column
              label="微信模版名称"
              align="center"
              prop="wechatTemplateName"
            />
            <el-table-column label="模板ID" align="center" prop="templateId" />
            <el-table-column
              label="模板来源"
              align="center"
              prop="templateSource"
            >
              <template slot-scope="scope">
                {{
                  scope.row.templateSource == "WE_CHAT_APPLET" ? "小程序" : ""
                }}
                {{
                  scope.row.templateSource == "WE_CHAT_OFFICIAL_ACCOUNT"
                    ? "公众号"
                    : ""
                }}
              </template>
            </el-table-column>
            <el-table-column
              label="适用任务类型"
              align="center"
              prop="suitTaskTypeName"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="病种名称"
              align="center"
              prop="diseaseTypeName"
            />
            <el-table-column
              prop="templateContent"
              label="模板内容"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
      </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:'WECHAT',
        hospitalAgencyId:46,
        operationName: 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:'WECHAT',
        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: 70px !important;
  }
}
</style>