<template>
<!--  充值明细-->
  <div class="main-contain">
    <div class="app-container">
      <div
        style="
          justify-content: flex-start;
          margin: 0px 0 12px 0;
          display: flex;
          align-items: center;
        "
      >
        <div style="display: flex">
          <div style="width: 250px">
            <el-input
              size="small"
              style="width: 200px; margin-left: 10px"
              class="filter-item"
              placeholder="请输入编号/患者名称"
              v-model.trim="keyword"
            />
          </div>

          <div style="width: 465px">
            <span>日期查询：</span>
            <el-date-picker
              v-model="value1"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </div>
          <el-button
            size="small"
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="search"
            >查询</el-button
          >
        </div>
      </div>

      <el-table
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266',
        }"
        max-height="550"
        :data="tableData"
        show-summary
        sum-text="充值金额合计"
        border
      >
        <el-table-column type="index" label="序号" align="center" width="200">
        </el-table-column>
        <el-table-column label="单据编号" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.deposit_code	 ? scope.row.deposit_code	 : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="患者名称" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.his_name	 ? scope.row.his_name	 : "" }}</span>
          </template>
        </el-table-column>

        <el-table-column label="充值金额" align="center" prop="deposit">
          <template slot-scope="scope">
            <span>{{ scope.row.deposit	 ? scope.row.deposit	 : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" align="center">
          <template slot-scope="scope">
<!--            <span>{{ scope.row.trial_status	 ? scope.row.trial_status	 : "" }}</span>-->
            <span v-if="scope.row.trial_status == 1">审核通过</span>
            <span v-if="scope.row.trial_status == 0">未审核</span>
            <span v-if="scope.row.trial_status == 2">审核拒绝</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.name	 ? scope.row.name	 : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="充值时间" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.starttime	 ? scope.row.starttime	 : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.remarks	 ? scope.row.remarks	 : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="350px">
          <template slot-scope="scope">
            <span v-if="scope.row.trial_status != 1">
            <el-button
              size="small"
              type="primary"
              @click="examine(scope.row, scope.row.$index)"
            >
              审核
            </el-button>
            </span>
           
            <span v-if="scope.row.trial_status == 1">
            <el-button
              size="small"
              type="primary"
              @click="print(scope.row, scope.row.$index)"
            >
              打印凭证
            </el-button>
            </span>
            <el-button
              size="small"
              type="danger"
              @click="toDelete(scope.row, scope.row.$index)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- <div>
          充值金额合计：<span>{{sum}}</span>
      </div> -->
    </div>
  </div>
</template>
<script>
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import {
  rechargedetails,
  deletehistory,
  updeposit,
  getweektime
}from "@/api/deposit";
export default {
  components: {
    BreadCrumb,
  },
  data() {
    return {
      crumbs: [
        { path: false, name: "押金管理" },
        { path: "/DepositManagement/DepositSearch", name: "押金查询" },
      ],
      tableData: [],
      // total: 0,
      // page: 1,
      // limit: 10,
      keyword: "",
      value1:"",//日期
      start_time:"",
      end_time:"",
      sum:""
    };
  },
  created(){
    this.init();
    // this.search()
  },
  methods: {
    // 初始化数据
    init() {
      var params = {}
      getweektime(params).then((res) => {
        if (res.data.state == 1){
            this.value1 = [res.data.data.srart_time,res.data.data.end_time]
        }
        this.search()
      })
    },

    // 查询操作
    search() {
      if (this.value1 != null){
        if(this.value1[0] != undefined && this.value1[1] != undefined){
          this.start_time = this.value1[0]
          this.end_time = this.value1[1]
        }
      }else {
        this.start_time = ""
        this.end_time = ""
      }
      var params = {
        keyword: this.keyword,
        start_time: this.start_time,
        end_time: this.end_time,
      };
      rechargedetails(params).then((res) => {
        if (res.data.state == 1){
          this.tableData = res.data.data.list;
          this.sum = res.data.data.sum;
        }
      })
    },

    // 删除
    toDelete(val,index) {
      var params = {
        id:val.id,
      };
      this.$confirm("是否确定删除?", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      }).then(() => {
        deletehistory(params).then((res) => {
          if (res.data.state == 1) {
            this.$message.success(res.data.data.list);
          }else {
            this.$message.error(res.data.msg);
          }
        })//刷新
          .then(() =>{
            this.search();
          })
          .catch((err) => {
            console.log(err)
          })
      }).catch(() => {});
    },

    // 审核
    examine(val,index) {
      var params = {
        id:val.id,
      };
      updeposit(params).then((res) =>{
        if (res.data.state == 1) {
          this.$message.success(res.data.data.list);
        }else {
          this.$message.error(res.data.msg);
        }
      })
      setTimeout(() => {
        this.search();
      },500)
    },

    // 打印凭证
    print(data,val){
      console.log("data",data)
      // alert("aaaaaaa")
      this.$router.push({path:"/DepositManagement/printindex",query:{key:data}})
    },
  },
};
</script>
<style lang="scss" scoped>

</style>
