<template>
  <div>
    <div ref="table">
      <el-form
        ref="queryForm"
        :model="informationqueryParams"
        label-width="80px"
        :inline="true"
      >
        <el-form-item
          label="短信模板名称"
          prop="textMessageName"
          label-width="100px"
        >
          <el-input
            v-model="informationqueryParams.textMessageName"
            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="55" align="center" label="序号" />
        <el-table-column
          label="短信模板名称"
          align="center"
          prop="textMessageName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="短信ID"
          align="center"
          prop="textMessageId"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="短信内容"
          align="center"
          prop="textMessageContent"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :show-overflow-tooltip="true"
          label="适用任务类型"
          align="center"
          prop="suitTaskTypeName"
        >
          <template slot-scope="scope">
            {{
              scope.row.suitTaskTypeName != "null"
                ? scope.row.suitTaskTypeName
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="短信通道"
          align="center"
          prop="textMessageChannel"
        >
          <template slot-scope="scope">
            {{
              scope.row.textMessageChannel == "WATER_DROPLET_PLATFORM"
                ? "水滴平台"
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="短信状态"
          align="right"
          prop="textMessageStatus"
          width="90px"
        >
          <template slot-scope="scope">
            <el-tag
              v-if="scope.row.textMessageStatus == 'GROUNDING'"
              type="success"
            >
              上架
            </el-tag>
            <el-tag
              v-if="scope.row.textMessageStatus == 'OFF_SHELF'"
              type="danger"
            >
              下架
            </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 {
  props: ['Nameinfo'],
  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      infolist: [],
      loading: false,
      datalist: [],
      informationqueryParams: {
        pageNum: 1,
        pageSize: 10,
        type: 'MESSAGE',
        textMessageStatus:'GROUNDING',
        hospitalAgencyId: 46,
        textMessageName: null,
      },
      totaldepartment: 0,

    }
  },
  watch: {
    datalist(val) {
      this.$emit('submit', val);
    },
    'Nameinfo': {
      handler(val, oldval) {
        // console.log(val,'Nameinfo111111111111')
      },
      deep: true,
      immediate: true,
    },
  },
  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);
      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,
      };
      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>