<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 inquiryStatusOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="inquiryOrderList" @selection-change="handleSelectionChange">
      <el-table-column label="订单号" align="center" prop="orderSn" width="200px"/>
      <el-table-column label="问诊标题" align="center" prop="title" show-overflow-tooltip />
      <el-table-column label="病人名称" align="center" prop="patientName" />
      <el-table-column label="医生名称" align="center" prop="doctorName" />
      <el-table-column label="订单类型" align="center" prop="orderType">
            <template slot-scope="scope">
              <dict-tag :options="inquiryOrderOptions" :value="scope.row.orderType"/>
            </template>
      </el-table-column>
      <el-table-column label="订单金额" align="center" prop="money" />
      <el-table-column label="支付金额" align="center" prop="payMoney" />
      <el-table-column label="支付类型" align="center" prop="payType" >
        <template slot-scope="scope">
          <dict-tag :options="inquiryPayOptions" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="是否支付" align="center" prop="isPay" >
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.isPay"/>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180"/>
     <el-table-column label="状态" align="center" prop="status" >
       <template slot-scope="scope">
         <dict-tag :options="inquiryStatusOptions" :value="scope.row.status" />
       </template>
     </el-table-column>
     <el-table-column label="订单类型" align="center" prop="orderType">
           <template slot-scope="scope">
             <dict-tag :options="inquiryOrderOptions" :value="scope.row.orderType"/>
           </template>
     </el-table-column>
     <el-table-column label="订单子类型" align="center" prop="inquirySubType">
           <template slot-scope="scope">
             <dict-tag :options="inquirySubTypeOptions" :value="scope.row.inquirySubType"/>
           </template>
     </el-table-column>



     <el-table-column label="支付类型" align="center" prop="payType" >
       <template slot-scope="scope">
         <dict-tag :options="inquiryPayOptions" :value="scope.row.payType"/>
       </template>
     </el-table-column>
     <el-table-column label="是否支付" align="center" prop="isPay" >
       <template slot-scope="scope">
         <dict-tag :options="orOptions" :value="scope.row.isPay"/>
       </template>
     </el-table-column>
     <el-table-column label="订单金额" align="center" prop="money" />
     <el-table-column label="支付金额" align="center" prop="payMoney" />
     <el-table-column label="优惠金额" align="center" prop="discountMoney" />
     <el-table-column label="支付时间" align="center" prop="payTime" width="180"/>
     <el-table-column label="审核时间" align="center" prop="auditTime" width="180"/>
     <el-table-column label="审核人" align="center" prop="userName" width="180"/>
     <el-table-column label="问诊开始时间" align="center" prop="startTime" width="180" />
     <el-table-column label="结束时间" align="center" prop="finishTime" width="180" />
      <el-table-column label="是否评价" align="center" prop="isPing" >
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.isPing"/>
        </template>
      </el-table-column>
      <el-table-column label="评分" align="center" prop="pingStar" width="170px">
        <template slot-scope="scope" >
          <el-rate v-if="scope.row.pingStar!=null"
            v-model="scope.row.pingStar"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}">
          </el-rate>
        </template>

      </el-table-column>
      <el-table-column label="科室名称" align="center" prop="deptName" />
    </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">
     <oexpertDetails  ref="Details" />
   </el-drawer> -->


  </div>
</template>

<script>
import { listinquiryOrder, getinquiryOrder, delinquiryOrder, addinquiryOrder, updateinquiryOrder, exportinquiryOrder } from "@/api/his/inquiryOrder";
export default {
  name: "inquiryOrderUser",
  data() {
    return {

      show:{
        title:"问诊详情",
        open:false,
          },
      startTime:null,
      // 遮罩层
      loading: true,
      actName:"10",
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 问诊订单表格数据
      inquiryOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderSn: null,
        title: null,
        imgs: null,
        userId: null,
        patientId: null,
        orderType: null,
        money: null,
        payMoney: null,
        payType: null,
        isPay: null,
        doctorId: null,
        payTime: null,
        status: null,
        startTime: null,
        sTime:null,
        eTime:null,
        finishTime: null,
        isPing: null,
        pingStar: null,
        pingContent: null,
        departmentId: null,
        inquiryType: null,
        doctorName:null,
        patientName:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      inquiryStatusOptions:[],
      inquiryTypeOptions:[],
      inquiryPayOptions:[],
      inquiryOrderOptions:[],
      inquirySubTypeOptions:[],
      orOptions:[],
    };
  },

  created() {
      this.getDicts("sys_inquiry_status").then(response => {
          this.inquiryStatusOptions = response.data;
        });
      this.getDicts("sys_inquiry_type").then(response => {
          this.inquiryTypeOptions = response.data;
        });
      this.getDicts("sys_inquiry_pay").then(response => {
          this.inquiryPayOptions = response.data;
        });
      this.getDicts("sys_inquiry_order_type").then(response => {
          this.inquiryOrderOptions = response.data;
        });
        this.getDicts("sys_inquiry_sub_type").then(response => {
          this.inquirySubTypeOptions = response.data;
        });
      this.getDicts("sys_company_or").then(response => {
          this.orOptions = response.data;
        });

  },
  methods: {
    change(){
      if(this.startTime!=null){
        this.queryParams.sTime=this.startTime[0];
        this.queryParams.eTime=this.startTime[1];
      }else{
        this.queryParams.sTime=null;
        this.queryParams.eTime=null;
      }

    },
    // handledetails(row){
    //         this.show.open=true;
    //         setTimeout(() => {
    //              this.$refs.Details.getDetails(row.orderId);
    //         }, 1);
    //     },
    /** 查询问诊订单列表 */
    /** 查询问诊订单列表 */
    getList() {
      this.loading = true;
      listinquiryOrder(this.queryParams).then(response => {
        this.inquiryOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getInquiryDetails(id,o){
      if(o==1){
        this.queryParams.userId=id
      }else{
        this.queryParams.patientId=id
      }

        this.getList();
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        orderSn: null,
        title: null,
        imgs: null,
        userId: null,
        patientId: null,
        orderType: null,
        money: null,
        payMoney: null,
        payType: null,
        isPay: null,
        doctorId: null,
        createTime: null,
        payTime: null,
        status: null,
        startTime: null,
        finishTime: null,
        remark: null,
        isPing: null,
        pingStar: null,
        pingContent: null,
        departmentId: null,
        inquiryType: 1,
        doctorName:null,
        patientName:null,
        sTime:null,
        eTime:null,
      };

      this.resetForm("form");

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");

      this.startTime=null;
      this.queryParams.sTime=null;
      this.queryParams.eTime=null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加问诊订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getOexpert(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改问诊订单";
      });
    },
  handleClickX(tab, event) {
   if(tab.name=="10"){
     this.queryParams.status=null;
   }else{
     this.queryParams.status=tab.name;
   }
    this.handleQuery();
  },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateOexpert(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOexpert(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$confirm('是否确认删除问诊订单编号为"' + orderIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOexpert(orderIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有问诊订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportOexpert(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
