<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入会员手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司名称" prop="companyId" >
        <el-select v-model="queryParams.companyId" placeholder="请选择所属公司" filterable size="small">
          <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="员工" prop="companyUserNickName">
           <el-input  v-model="queryParams.companyUserNickName"  placeholder="请输入员工名称" clearable size="small" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="病人名称" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入病人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评分" prop="pingStar">
           <el-input  v-model="queryParams.pingStar"  placeholder="请输入评分" clearable size="small" onkeyup="value=value.replace(/[^\d]/g,'')" />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
                <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
      </el-form-item>
      <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-form>
    <el-tabs type="card" v-model="tabIndex" @tab-click="handleTabClick">
      <el-tab-pane label="全部" name="0"></el-tab-pane>
      <el-tab-pane v-for="(item,index) in statusOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table border v-loading="loading" :data="drugReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="reportId" />
      <el-table-column label="会员昵称" align="center" prop="nickName" />
      <el-table-column label="患者名称" align="center" prop="patientName" />
      <el-table-column label="咨询总结" show-overflow-tooltip align="center" prop="reportSummary" />
      <el-table-column label="生活建议" show-overflow-tooltip align="center" prop="reportAdvice" />
      <el-table-column label="公司" align="center" prop="companyName" />
      <el-table-column label="员工" align="center" prop="companyNickName" />
      <el-table-column label="提交时间" align="center" prop="createTime" width="180">
      </el-table-column>
      <el-table-column label="评分" align="center" prop="pingStar" />
      <el-table-column label="评价" show-overflow-tooltip align="center" prop="pingContent" />
      <el-table-column label="评价时间" align="center" prop="pingTime" width="180">
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="statusOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="100px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetails(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-drawer
        :with-header="false"
        size="75%"
          :title="show.title" :visible.sync="show.open">
      <drugReportDetails  ref="reportDetails"  />
    </el-drawer>
  </div>
</template>

<script>
import { getDrugReportList } from "@/api/drugReport";
import drugReportDetails from '@/views/components/drugReport/drugReportDetails.vue';
import {getCompanyList} from "@/api/inquiryOrder";
export default {
  name: "DrugReport",
  components: { drugReportDetails },
  data() {
    return {
      tabIndex:"0",
      show:{
        title:"报告详情",
        open:false,
      },
      companyList:[],
      statusOptions:[],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用药报告表格数据
      drugReportList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone:null,
        status:null,
        pingStar:null,
        patientName:null,
        companyId:null,
        companyUserNickName:null,
        sTime:null,
        eTime:null,
      },
      createTime: null,
    };
  },
  created() {
    this.getDicts("sys_drug_report_status").then(response => {
      this.statusOptions = response.data;
    });
    getCompanyList().then(response => {
      this.companyList = response.list;
    });
    this.getList();
  },
  methods: {
    handleDetails(row){
      this.show.open=true;
      setTimeout(() => {
            this.$refs.reportDetails.getDetails(row.reportId);
      }, 100);
    },
    change(){
      if(this.createTime!=null){
          this.queryParams.sTime=this.createTime[0];
          this.queryParams.eTime=this.createTime[1];
      }else{
          this.queryParams.sTime=null;
          this.queryParams.eTime=null;
      }
    },
    handleTabClick(tab, event) {
      if(tab.name=="0"){
        this.queryParams.status=null;
      }else{
        this.queryParams.status=tab.name;
      }
      this.handleQuery();
   },
    /** 查询用药报告列表 */
    getList() {
      this.loading = true;
      getDrugReportList(this.queryParams).then(response => {
        this.drugReportList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.createTime=null;
      this.queryParams.sTime=null;
      this.queryParams.eTime=null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reportId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
