<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="88px">
      <el-row>
        <el-col :span="8">
          <el-form-item class="treeselectForm treeselectForm2" label="组织架构" prop="deptIds">
            <tree
              @treeselectFn="treeselectFn"
              :treeval="queryParams.deptIds"
              style="width: 193px"></tree>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="点评人" prop="remarkUserId">
            <user
              :userId="queryParams.remarkUserId"
              :orgIds="queryParams.deptIds"
              @userIdFn="userIdFn"></user>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="点评人岗位" prop="postName">
            <el-input
              v-model="queryParams.postName"
              placeholder="请输入点评人岗位"
              clearable
              size="small"
              style="width: 240px"
              @input="onInput()"
              @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="汇报类型" prop="reportTypeList">
            <el-select
              v-model="queryParams.reportTypeList"
              clearable
              multiple
              collapse-tags
              placeholder="请选择汇报类型"
              @change="onInput">
              <el-option
                v-for="item in reportTypeOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="岗位类型" prop="reportPostType">
            <el-select
              v-model="queryParams.reportPostType"
              clearable
              collapse-tags
              placeholder="请选择岗位类型"
              @change="onInput">
              <el-option
                v-for="dict in dict.type.report_post_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="点评时间" prop="datetimerange">
            <el-date-picker
              style="width: 193px"
              v-model="datetimerange"
              type="daterange"
              align="right"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="datetimeRangeChange">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sfa:reportRemark:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="reportRemarkList"
      @selection-change="handleSelectionChange">
      <!-- 点评人公司、点评人大区、点评人销售部、点评人、点评人工号、点评人岗位、点评时间、点评内容、
       汇报日期、公司、大区、销售部、汇报人工号、汇报人、汇报人岗位、汇报类型、汇报状态、提交时间 -->
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="点评人公司" align="center" prop="gsName" width="140" />
      <el-table-column label="点评人大区" align="center" prop="dqName" width="140" />
      <el-table-column label="点评人销售部" align="center" prop="deptName" width="140" />
      <el-table-column label="点评人" align="center" prop="remarkNickName" width="80" />
      <el-table-column label="点评人工号" align="center" prop="remarkWorkCode" width="100" />
      <el-table-column label="点评人岗位" align="center" prop="remarkPostName" width="140" />
      <el-table-column label="点评时间" align="center" prop="sendTime" width="150" />
      <el-table-column
        label="点评内容"
        align="center"
        prop="remarkContent"
        width="250px"
        :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="汇报日期" align="center" prop="date" width="150" />
      <el-table-column label="汇报人公司" align="center" prop="ugsName" width="140" />
      <el-table-column label="汇报人大区" align="center" prop="udqName" width="140" />
      <el-table-column label="汇报人销售部" align="center" prop="udeptName" width="140" />
      <el-table-column label="汇报人工号" align="center" prop="reportWorkCode" width="100" />
      <el-table-column label="汇报人" align="center" prop="reportNickName" width="80" />
      <el-table-column label="汇报人岗位" align="center" prop="reportPostName" width="140" />
      <el-table-column label="汇报类型" align="center" prop="reportTypeStr" width="80" />
      <el-table-column label="汇报状态" align="center" prop="statusStr" width="80" />
      <el-table-column label="提交时间" align="center" prop="commitTime" width="150" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import {
  listReportRemark,
  delReportRemark,
  addReportRemark,
  updateReportRemark,
} from '@/api/sfa/reportRemark';
import tree from '@/views/components/sfa/treeselectParent';
import user from '@/views/components/sfa/user';
export default {
  name: 'ReportRemark',
  dicts: ['report_post_type'],
  components: { tree, user },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 汇报点评表格数据
      reportRemarkList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptIds: null,
        remarkUserId: null,
        reportTypeList: ['1', '2', '3'], //汇报类型：1-日报、2-周报、3-半月报，可多选
        reportPostType: null, //岗位类型：对应字典report_post_type的value，参照汇报查询中的使用方式
        postName: '', //	string	点评人岗位
        remarkStartTime: '', //	Date	点评开始时间
        remarkEndTime: '', //	Date	点评结束时间
      },
      reportTypeOptions: [
        {
          dictValue: '1',
          dictLabel: '日报',
        },
        {
          dictValue: '2',
          dictLabel: '周报',
        },
        {
          dictValue: '3',
          dictLabel: '半月报',
        },
      ],
      datetimerange: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    onInput() {
      this.$forceUpdate();
    },
    treeselectFn(val) {
      this.queryParams.deptIds = val;
    },
    userIdFn(val) {
      this.queryParams.remarkUserId = val;
    },
    datetimeRangeChange(val) {
      this.$forceUpdate();
      if (val == undefined || val == null) {
        this.datetimerange = [];
        this.queryParams.remarkStartTime = '';
        this.queryParams.remarkEndTime = '';
      } else {
        this.queryParams.remarkStartTime = val[0];
        this.queryParams.remarkEndTime = val[1];
      }
    },
    /** 查询汇报点评列表 */
    getList() {
      this.loading = true;
      listReportRemark(this.queryParams).then((response) => {
        this.reportRemarkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        deptIds: null,
        remarkUserId: null,
        reportTypeList: ['1', '2', '3'], //汇报类型：1-日报、2-周报、3-半月报，可多选
        reportPostType: null, //岗位类型：对应字典report_post_type的value，参照汇报查询中的使用方式
        postName: '', //	string	点评人岗位
        remarkStartTime: '', //	Date	点评开始时间
        remarkEndTime: '', //	Date	点评结束时间
      };
      this.datetimerange = [];
      this.resetForm('queryForm');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'sfa/reportRemark/export',
        {
          ...this.queryParams,
        },
        `reportRemark_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
