<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="就诊卡id" prop="cardId">
        <el-input v-model="queryParams.cardId" placeholder="请输入就诊卡id" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="病人名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入病人名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker v-model="queryParams.startDate" style="width: 240px" value-format="yyyy-MM-dd" type="date"/>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker v-model="queryParams.endDate" style="width: 240px" value-format="yyyy-MM-dd" type="date"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="患者 ID" align="center"   width="100px" prop="patientId" />
      <el-table-column label="病人名称" align="center" prop="name" />
      <el-table-column label="科室名称" align="center" :show-overflow-tooltip="true" prop="ksmc" />
      <el-table-column label="医生名称" align="center" prop="ysmc" />
      <el-table-column label="票据编号" align="center" :show-overflow-tooltip="true" prop="reptNum" />
      <el-table-column label="排班 ID" align="center" :show-overflow-tooltip="true" prop="scheduleId" />
      <el-table-column label="医生编码" align="center" prop="doctorCode" />
      <el-table-column label="科室编码" align="center" prop="departCode" />
      <el-table-column label="手机号码" align="center"   width="110px" prop="mobile" />
      <el-table-column label="号票编号" align="center" :show-overflow-tooltip="true" prop="ticketNo" />
      <el-table-column label="取号确认订单ID" align="center" :show-overflow-tooltip="true" prop="orderNo" />
      <el-table-column label="取号确认时间段" align="center" prop="timeInterval" />
      <el-table-column label="出诊日期" align="center"   width="100px" prop="registerdate" />
      <el-table-column label="诊查费" align="center" prop="clinicFee" />
      <el-table-column label="挂号费" align="center" prop="registrationFee" />
      <el-table-column label="收费性质" align="center" prop="payNature" />
      <el-table-column label="支付方式" align="center" prop="payType" />
      <el-table-column label="交易 ID" align="center" :show-overflow-tooltip="true" prop="powerTranID" />
      <el-table-column label="提交时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope"> 
          <span>{{ parseTime(scope.row.ctime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

  </div>
</template>

<script>
import { createReserve8, updateReserve8, deleteReserve8, getReserve8, getReserve8Page, exportReserve8Excel } from "@/api/system/reserve8";

export default {
  name: "Reserve8",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约挂号列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        userId: null,
        cardId: null,
        name: null,
        ksmc: null,
        ysmc: null,
        subHospitalID: null,
        reptNum: null,
        lockType: null,
        hisOrderNO: null,
        scheduleId: null,
        doctorCode: null,
        departCode: null,
        parTimeId: null,
        lockTime: [],
        patientId: null,
        mobile: null,
        serialNo: null,
        location: null,
        ticketNo: null,
        orderNo: null,
        timeInterval: null,
        registerdate: [],
        clinicFee: null,
        registrationFee: null,
        payNature: null,
        payType: null,
        powerTranID: null,
        powerTranCARD: null,
        terminalId: null,
        zFAmount: null,
        yBZHAmount: null,
        yBTCAmount: null,
        yBOutMsg: null,
        hisOperNum: null,
        referNo: null,
        token: null,
        appFlag: null,
        appStatus: null,
        appType: null,
        ctime: [],
        utime: [],
        startDate: null,
        endDate: null,        
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    const end = new Date();//获取当前的日期
    this.queryParams.startDate=this.dateFormat(end);
    this.queryParams.endDate=this.dateFormat(end);

    this.getList();
  },
  methods: {
    dateFormat(dateData) {
        var date = new Date(dateData)
        var y = date.getFullYear()
        var m = date.getMonth() + 1
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        const time = y + '-' + m + '-' + d;
        return time;
    },    

    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getReserve8Page(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        cardId: undefined,
        name: undefined,
        ksmc: undefined,
        ysmc: undefined,
        subHospitalID: undefined,
        reptNum: undefined,
        lockType: undefined,
        hisOrderNO: undefined,
        scheduleId: undefined,
        doctorCode: undefined,
        departCode: undefined,
        parTimeId: undefined,
        lockTime: undefined,
        patientId: undefined,
        mobile: undefined,
        serialNo: undefined,
        location: undefined,
        ticketNo: undefined,
        orderNo: undefined,
        timeInterval: undefined,
        registerdate: undefined,
        clinicFee: undefined,
        registrationFee: undefined,
        payNature: undefined,
        payType: undefined,
        powerTranID: undefined,
        powerTranCARD: undefined,
        terminalId: undefined,
        zFAmount: undefined,
        yBZHAmount: undefined,
        yBTCAmount: undefined,
        yBOutMsg: undefined,
        hisOperNum: undefined,
        referNo: undefined,
        token: undefined,
        appFlag: undefined,
        appStatus: undefined,
        appType: undefined,
        ctime: undefined,
        utime: undefined,
        // startDate: null,
        // endDate: null,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预约挂号";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getReserve8(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预约挂号";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateReserve8(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createReserve8(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除预约挂号编号为"' + id + '"的数据项?').then(function() {
          return deleteReserve8(id);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有预约挂号数据项?').then(() => {
          this.exportLoading = true;
          return exportReserve8Excel(params);
        }).then(response => {
          this.$download.excel(response, '预约挂号.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
