<template>
  <div>
    <div ref="table">
      <el-form
        ref="queryForm"
        :model="informationqueryParams"
        label-width="80px"
        :inline="true"
      >
        <el-form-item
          label="宣教名称"
          prop="propagandaTitle"
          label-width="100px"
        >
          <el-input
            v-model="informationqueryParams.propagandaTitle"
            placeholder="请输入宣教名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="宣教类型" prop="propagandaType">
          <el-select
            v-model="informationqueryParams.propagandaType"
            placeholder="请选择"
          >
            <el-option
              v-for="item in optionstype"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </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="id" type="index" />
        <el-table-column
          label="宣教名称"
          align="center"
          prop="propagandaTitle"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column label="宣教类型" align="center" prop="propagandaType">
          <template slot-scope="scope">
            {{
              scope.row.propagandaType == "MEDICATION_KNOWLEDGE"
                ? "用药知识"
                : ""
            }}
            {{
              scope.row.propagandaType == "DISEASE_POPULARIZATION"
                ? "疾病科普"
                : ""
            }}
            {{
              scope.row.propagandaType == "SPORT_NUTRITION" ? "运动营养" : ""
            }}
            {{
              scope.row.propagandaType == "OTHER_KNOWLEDGE" ? "其他知识" : ""
            }}
            {{
              scope.row.propagandaType == "CUSTOMIZED_CONTENT" ? "定制内容" : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="宣教ID"
          align="center"
          prop="propagandaCode"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="宣教状态"
          align="center"
          prop="propagandaStatus"
        >
          <template slot-scope="scope">
            {{ scope.row.propagandaStatus == "CREATE_PROCESS" ? "创作中" : "" }}
            {{
              scope.row.propagandaStatus == "CREATE_COMPLETE" ? "创作完成" : ""
            }}
            {{ scope.row.propagandaStatus == "IN_REVIEW" ? "审核中" : "" }}
            {{ scope.row.propagandaStatus == "APPROVED" ? "审核通过" : "" }}
            {{
              scope.row.propagandaStatus == "REVIEW_FAILED" ? "审核不通过" : ""
            }}
            <div></div>
          </template>
        </el-table-column>
        <el-table-column
          label="宣教来源"
          align="center"
          prop="hospitalAgencyName"
        />
        <el-table-column label="创建时间" align="center" prop="createTime" />
        <el-table-column label="更新时间" align="center" prop="updateTime" />
      </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: 'PROPAGANDA',
        propagandaStatus: 'APPROVED',
        hospitalAgencyId: 46,
        propagandaTitle: null,
        propagandaType: null,
      },
      optionstype: [{
        value: 'MEDICATION_KNOWLEDGE',
        label: '用药知识'
      }, {
        value: 'DISEASE_POPULARIZATION',
        label: '疾病科普'
      }, {
        value: 'SPORT_NUTRITION',
        label: '运动营养'
      }, {
        value: 'OTHER_KNOWLEDGE',
        label: '其他知识'
      }, {
        value: 'CUSTOMIZED_CONTENT',
        label: '定制内容'
      }],
      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: 'PROPAGANDA',
        propagandaStatus: 'APPROVED',
        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>