<template>
  <div class="role">
    <div ref="leftContainer" class="left">
      <el-form :inline="true">
        <!--项目编号/实验名称-->
        <el-form-item :label="$t('feedBack:search:trials')" v-if="level > 8">
          <el-input
            v-model="searchData.a"
            clearable
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <!--中心-->
        <el-form-item :label="$t('feedBack:search:site')" v-if="level > 7">
          <el-input
            v-model="searchData.a"
            clearable
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <!--受试者访视-->
        <el-form-item
          :label="$t('feedBack:search:subjectVisit')"
          v-if="level > 7"
        >
          <el-input
            v-model="searchData.a"
            clearable
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <!--角色-->
        <el-form-item :label="$t('feedBack:search:role')" v-if="level > 7">
          <el-select
            v-model="searchData.NoticeTypeEnum"
            clearable
            style="width: 150px"
          >
            <el-option
              v-for="item of $d.NoteType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <!--反馈人-->
        <el-form-item :label="$t('feedBack:search:user')" v-if="level > 7">
          <el-input
            v-model="searchData.a"
            clearable
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <!--问题类型-->
        <el-form-item :label="$t('feedBack:search:questionType')">
          <el-select
            v-model="searchData.NoticeTypeEnum"
            clearable
            style="width: 150px"
          >
            <el-option
              v-for="item of $d.NoteType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <!--问题描述-->
        <el-form-item :label="$t('feedBack:search:description')">
          <el-input
            v-model="searchData.a"
            clearable
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <!--状态-->
        <el-form-item :label="$t('feedBack:search:status')" v-if="level > 7">
          <el-select
            v-model="searchData.NoticeTypeEnum"
            clearable
            style="width: 150px"
          >
            <el-option
              v-for="item of $d.NoteType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <!--反馈日期-->
        <el-form-item :label="$t('feedBack:search:time')">
          <el-date-picker
            v-model="datetimerange"
            type="datetimerange"
            :default-time="['00:00:00', '23:59:59']"
            :start-placeholder="$t('feedBack:search:beginTime')"
            :end-placeholder="$t('feedBack:search:endTime')"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="handleDatetimeChange"
            style="width: 250px"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getList"
          >
            {{ $t("common:button:search") }}
          </el-button>
          <!-- 重置 -->
          <el-button
            size="mini"
            icon="el-icon-refresh-left"
            @click="handleReset"
          >
            {{ $t("common:button:reset") }}
          </el-button>
          <el-button
            type="primary"
            size="mini"
            @click="report"
            v-if="level > 7"
          >
            {{ $t("common:button:export") }}
          </el-button>
        </el-form-item>
        <el-button
          type="primary"
          size="mini"
          @click="resolve"
          style="float: right"
          v-if="level > 7"
        >
          {{ $t("feedBack:button:resolve") }}
        </el-button>
      </el-form>
      <el-table
        v-loading="loading"
        v-adaptive="{ bottomOffset: 45 }"
        height="100"
        :data="list"
        class="table"
        @selection-change="handleSelectChange"
        @sort-change="handleSortByColumn"
        :default-sort="{ prop: 'StudyTime', order: 'descending' }"
      >
        <el-table-column
          type="selection"
          align="center"
          width="45"
          v-if="level > 7"
        />
        <el-table-column type="index" width="50" />
        <el-table-column
          :label="$t('feedBack:form:trialCode')"
          prop="NoticeLevelEnum"
          min-width="120"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 8"
        />
        <el-table-column
          :label="$t('feedBack:form:study')"
          prop="NoticeTypeEnum"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 8"
        />
        <el-table-column
          :label="$t('feedBack:form:siteCode')"
          prop="NoticeContent"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 7"
        />
        <el-table-column
          :label="$t('feedBack:form:subjectVisit')"
          prop="NoticeStateEnum"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 7"
        />
        <el-table-column
          :label="$t('feedBack:form:role')"
          prop="ApplicableProjectEnum"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 7"
        />
        <el-table-column
          :label="$t('feedBack:form:user')"
          prop="ApplicableProjectEnum"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 7"
        />
        <el-table-column
          :label="$t('feedBack:form:questionType')"
          prop="NoticeUserTypeList"
          min-width="80"
          show-overflow-tooltip
          sortable="custom"
        />
        <el-table-column
          :label="$t('feedBack:form:description')"
          prop="NoticeModeEnum"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
        />
        <el-table-column
          :label="$t('feedBack:form:time')"
          prop="StartDate"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
        />
        <el-table-column
          :label="$t('feedBack:form:status')"
          prop="PublishUserName"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 7"
        />
        <el-table-column
          :label="$t('feedBack:form:uploadTime')"
          prop="PublishedTime"
          min-width="100"
          show-overflow-tooltip
          sortable="custom"
          v-if="level > 7"
        />
        <el-table-column
          :label="$t('common:action:action')"
          fixed="right"
          prop="UserTypeShortName"
          width="80"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="getDetail(scope.row)">
              {{ $t("common:button:view") }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination" style="text-align: right; margin-top: 5px">
        <pagination
          :total="total"
          :page.sync="searchData.PageIndex"
          :limit.sync="searchData.PageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
import Pagination from "@/components/Pagination";
const searchDataDefault = () => {
  return {
    Asc: true,
    SortField: "",
    NoticeContent: null,
    FileName: null,
    NoticeTypeEnum: null,
    NoticeLevelEnum: null,
    ApplicableProjectEnum: null,
    NoticeModeEnum: null,
    NoticeStateEnum: null,
    PageIndex: 1,
    PageSize: 20,
  };
};
export default {
  components: { Pagination },
  dicts: [
    "NoticeApplicableTrial",
    "NoteLevel",
    "NoteType",
    "NoticeState",
    "NoticeMode",
  ],
  data() {
    return {
      list: [{ PublishUserName: 1 }],
      total: 0,
      loading: false,
      datetimerange: [],
      // 查询参数
      searchData: searchDataDefault(),
      tableSelectData: [],
    };
  },
  computed: {
    level() {
      if (this.hasPermi(["role:dev", "role:admin"])) {
        return 9;
      }
      if (this.hasPermi(["role:pm"])) {
        return 8;
      }
      if (this.hasPermi(["role:ir", "role:crc"])) {
        return 7;
      }
      return 0;
    },
  },
  mounted() {},
  methods: {
    getList() {},
    handleDatetimeChange(val) {
      if (val) {
        this.searchData.StartTime = val[0];
        this.searchData.EndTime = val[1];
      } else {
        this.searchData.StartTime = "";
        this.searchData.EndTime = "";
      }
    },
    // 重置列表查询
    handleReset() {
      this.datetimerange = null;
      this.handleDatetimeChange();
      this.searchData = searchDataDefault();
      this.getList();
    },
    // 设为解决
    resolve() {},
    // 导出
    report() {},
    // 表格选择
    handleSelectChange(selection) {
      // console.log(selection, "handleSelectChange");
      this.tableSelectData = selection;
    },
    // 排序
    handleSortByColumn(column) {
      if (column.order === "ascending") {
        this.searchData.Asc = true;
      } else {
        this.searchData.Asc = false;
      }
      this.searchData.SortField = column.prop;
      this.searchData.PageIndex = 1;
      this.getList();
    },
    // 获取详情
    getDetail(row) {
      this.$FB({
        type: "detail",
        Id: row.Id,
      });
    },
  },
};
</script>
<style lang="scss">
.role {
  height: 100%;
  box-sizing: border-box;
  display: flex;
  padding: 10px;
  border-radius: 5px;
  .left {
    display: flex;
    flex-direction: column;
    width: 0;
    flex-grow: 4;
    // border-right: 1px solid #ccc;
    .filter-container {
      display: flex;
      align-items: center;
      margin: 5px;
    }
    .data-table {
      flex: 1;
      padding: 5px 0px;
    }
    .pagination-container {
      text-align: right;
    }
  }
  .right {
    width: 0;
    flex-grow: 6;
    overflow-y: auto;
    border-right: 1px solid #ccc;
  }
  .selected-row {
    background-color: cadetblue;
  }
}
</style>
