<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="patientid">
        <el-input v-model="queryParams.patientid" placeholder="请输入就诊ID" 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="userId" />
      <el-table-column label="就诊ID" align="center"  width="100px" prop="patientid" />
      <el-table-column label="订单ID" align="center"  width="100px" :show-overflow-tooltip="true" prop="orderno" />
      <el-table-column label="单据ID" align="center" prop="flowno" />
      <el-table-column label="开单科室编号" align="center"  width="100px"  prop="setdepartcode" />
      <el-table-column label="开单科室名称" align="center"  width="100px" :show-overflow-tooltip="true" prop="setdepartname" />
      <el-table-column label="开单时间" align="center" :show-overflow-tooltip="true" prop="billtime" />
      <el-table-column label="项目总金额" align="center"  width="100px"  prop="billmoney" />
      <el-table-column label="医生代码" align="center" prop="doctorcode" />
      <el-table-column label="医生名称" align="center" prop="doctorname" />
      <el-table-column label="就诊流水号" align="center"  width="100px"  :show-overflow-tooltip="true" prop="serialflowno" />
      <el-table-column label="就诊类别" align="center" prop="jzlb" />
      <el-table-column label="账单信息" align="center" prop="billsmsg" />
      <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="zfamount" />
      <el-table-column label="工行ID" align="center" :show-overflow-tooltip="true" prop="icbcorderid" />
      <el-table-column label="工行支付时间" align="center"  width="100px"  :show-overflow-tooltip="true" prop="icbcpaytime" />
      <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 { createMzjf, updateMzjf, deleteMzjf, getMzjf, getMzjfPage, exportMzjfExcel } from "@/api/system/mzjf";

export default {
  name: "Mzjf",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门诊缴费列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        userId: null,
        patientid: null,
        // idtype: null,
        // locktype: null,
        // creatitemname: null,
        // appointmenttime: [],
        // creatdate: [],
        // querytype: null,
        // orderno: null,
        // flowno: null,
        // setdepartcode: null,
        // setdepartname: null,
        // dodepartcode: null,
        // dodepartname: null,
        // billtype: null,
        // billname: null,
        // billdes: null,
        // billtime: [],
        // billmoney: null,
        // doctorcode: null,
        // doctorname: null,
        // sincemoney: null,
        // fairmoney: null,
        // serialno: null,
        // appointno: null,
        // serialflowno: null,
        // jzlb: null,
        // bzdm: null,
        // updatedate: [],
        // billsmsg: null,
        // paynature: null,
        // paytype: null,
        // powertranid: null,
        // powertrancard: null,
        // terminalid: null,
        // referno: null,
        // zfamount: null,
        // ybzhamount: null,
        // ybtcamount: null,
        // yboutmsg: null,
        // hisopernum: null,
        // icbcorderid: null,
        // icbcpaytime: [],
        // appFlag: null,
        // appStatus: null,
        // ctime: [],
        // utime: [],
        appStatus: null,
        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;
      // 执行查询
      getMzjfPage(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,
        patientid: undefined,
        idtype: undefined,
        locktype: undefined,
        creatitemname: undefined,
        appointmenttime: undefined,
        creatdate: undefined,
        querytype: undefined,
        orderno: undefined,
        flowno: undefined,
        setdepartcode: undefined,
        setdepartname: undefined,
        dodepartcode: undefined,
        dodepartname: undefined,
        billtype: undefined,
        billname: undefined,
        billdes: undefined,
        billtime: undefined,
        billmoney: undefined,
        doctorcode: undefined,
        doctorname: undefined,
        sincemoney: undefined,
        fairmoney: undefined,
        serialno: undefined,
        appointno: undefined,
        serialflowno: undefined,
        jzlb: undefined,
        bzdm: undefined,
        updatedate: undefined,
        billsmsg: undefined,
        paynature: undefined,
        paytype: undefined,
        powertranid: undefined,
        powertrancard: undefined,
        terminalid: undefined,
        referno: undefined,
        zfamount: undefined,
        ybzhamount: undefined,
        ybtcamount: undefined,
        yboutmsg: undefined,
        hisopernum: undefined,
        icbcorderid: undefined,
        icbcpaytime: undefined,
        appFlag: undefined,
        appStatus: undefined,
        ctime: undefined,
        utime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForms");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门诊缴费";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getMzjf(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) {
          updateMzjf(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createMzjf(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 deleteMzjf(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 exportMzjfExcel(params);
        }).then(response => {
          this.$download.excel(response, '门诊缴费.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
