<template>
  <div>
    <div ref="table">
      <el-form
        ref="queryForm"
        :model="informationqueryParams"
        label-width="80px"
        :inline="true"
      >
        <el-form-item
          label="通用话术名称"
          prop="commonScriptName"
          label-width="100px"
        >
          <el-input
            v-model="informationqueryParams.commonScriptName"
            placeholder="请输入通用话术名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="话术名称" prop="scriptName">
          <el-input
            v-model="informationqueryParams.scriptName"
            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="序号" align="center" prop="sort" type="index" />

        <el-table-column
          label="通用话术名称"
          align="center"
          prop="commonScriptName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="话术名称"
          align="center"
          prop="scriptName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="话术ID"
          align="center"
          prop="scriptId"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="平台ID"
          align="center"
          prop="platformId"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="话术状态" align="center" prop="scriptStatus">
          <template slot-scope="scope">
            {{ scope.row.scriptStatus == "NORMAL" ? "正常" : "" }}
            {{ scope.row.scriptStatus == "OFF_SHELF" ? "下架" : "" }}
            {{ scope.row.scriptStatus == "SUSPEND" ? "暂停" : "" }}
          </template>
        </el-table-column>
        <el-table-column
          label="话术简介"
          align="center"
          prop="scriptIntroduction"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="病种名称"
          align="center"
          prop="diseaseTypeName"
          :show-overflow-tooltip="true"
        />
      </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:'SCRIPT',
        scriptStatus:'NORMAL',
        hospitalAgencyId:46,
        commonScriptName: null,
        scriptName: 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);
      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:'SCRIPT',
        scriptStatus:'NORMAL',
        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>