<template>
  <div class="aacontainer">
    <el-tabs type="card" v-model="actName" @tab-click="handleClickX">
      <el-tab-pane label="全部订单" name="10"></el-tab-pane>
      <el-tab-pane v-for="(item,index) in prescribeStatusOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="prescribeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="处方单编号" align="center" prop="prescribeCode" width="180px" />
      <el-table-column label="处方类型" align="center" prop="prescribeType" >
            <template slot-scope="scope">
              <dict-tag :options="prescribeType" :value="scope.row.prescribeType"/>
            </template>
      </el-table-column>

      <el-table-column label="患者年龄" align="center" prop="patientAge" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="诊断" align="center" prop="diagnose" />
      <el-table-column label="医生名称" align="center" prop="doctorName" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <dict-tag :options="prescribeStatusOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
    </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">
     <orderDetails  ref="Details" />
   </el-drawer> -->
  </div>
</template>

<script>
import { listPrescribe, getPrescribe, delPrescribe, addPrescribe, updatePrescribe, exportPrescribe } from "@/api/his/prescribe";

export default {
  name: "userPrescribeDetails",
  props:["data"],
  data() {
    return {
      createTime:null,
      pjtUrl: process.env.VUE_APP_BASE_API+"/",
      show:{
              title:"订单详情",
              open:false,
            },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 处方表格数据
      prescribeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        prescribeType: null,
        inquiryOrderId: null,
        storeOrderId: null,
        userId: null,
        patientId: null,
        prescribeCode: null,
        patientDescs: null,
        nowIllness: null,
        historyIllness: null,
        patientAge: null,
        patientName: null,
        weight: null,
        sTime:null,
        eTime:null,
        isHistoryAllergic: null,
        historyAllergic: null,
        liverUnusual: null,
        renalUnusual: null,
        isLactation: null,
        patientTel: null,
        patientGender: null,
        recordPic: null,
        prescribeImgUrl: null,
        auditReason: null,
        diagnose: null,
        doctorId: null,
        status: null,
        auditTime: null
      },
       actName:"10",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      prescribeStatusOptions:[],
      prescribeType:[],
      orOptions:[],
      sexOptions:[],
    };
  },
  created() {
    this.getDicts("sys_prescribe_status").then(response => {
        this.prescribeStatusOptions = response.data;
      });
    this.getDicts("sys_prescribe_type").then(response => {
        this.prescribeType = response.data;
      });
    this.getDicts("sys_sex").then(response => {
        this.sexOptions = response.data;
      });
    this.getDicts("sys_company_or").then(response => {
        this.orOptions = response.data;
      });
  },
  methods: {
    handleClickX(tab, event) {
     if(tab.name=="10"){
       this.queryParams.status=null;
     }else{
       this.queryParams.status=tab.name;
     }
      this.handleQuery();
    },
    /** 查询处方列表 */
    getList() {
      this.loading = true;
      listPrescribe(this.queryParams).then(response => {
        this.prescribeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    PrescribeDetails(id){
      this.queryParams.patientId=id;
      this.getList();
    },
    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;
      }

    },
    // 表单重置
    reset() {
      this.form = {
        prescribeId: null,
        prescribeType: null,
        inquiryOrderId: null,
        storeOrderId: null,
        userId: null,
        patientId: null,
        prescribeCode: null,
        patientDescs: null,
        nowIllness: null,
        historyIllness: null,
        patientAge: null,
        patientName: null,
        weight: null,
        isHistoryAllergic: null,
        historyAllergic: null,
        liverUnusual: null,
        renalUnusual: null,
        isLactation: null,
        patientTel: null,
        patientGender: null,
        recordPic: null,
        prescribeImgUrl: null,
        auditReason: null,
        diagnose: null,
        doctorId: null,
        createTime: null,
        status: 0,
        auditTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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.prescribeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加处方";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const prescribeId = row.prescribeId || this.ids
      getPrescribe(prescribeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改处方";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.prescribeId != null) {
            updatePrescribe(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPrescribe(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const prescribeIds = row.prescribeId || this.ids;
      this.$confirm('是否确认删除处方编号为"' + prescribeIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPrescribe(prescribeIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有处方数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportPrescribe(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
