<template>
  <!-- <div class="main-contain outpatientChargesManagement">
      <div class="position">
          <bread-crumb :crumbs='crumbs'></bread-crumb>
      </div> -->
  <div>
    <div style="display: flex;justify-content: space-between;margin-bottom:10px;">
      <div>


        <el-date-picker
            v-model="month"
            type="month"
            placeholder="选择年月">
        </el-date-picker>
      </div>
      <div>
        <el-button size="small" type="primary" @click="getYidiClear()">提取异地清分</el-button>
        <el-button size="small" type="primary" @click="comfirmClear()">异地清分确认</el-button>
      </div>
    </div>
    <el-table :data="tableData" border :row-style="{ color: '#303133' }" ref="table"
              :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
              show-summary
              max-height="600"
              highlight-current-row>
      <el-table-column align="center" prop="name" label="清分机构">
        <template slot-scope="scope">{{scope.row.org_name}}</template>
      </el-table-column>
      <el-table-column align="center" prop="name" label="清分时间">
        <template slot-scope="scope">{{getTime(scope.row.ctime) ? getTime(scope.row.ctime): ''}}</template>
      </el-table-column>
      <el-table-column align="center" prop="name" label="清分流水号">
        <template slot-scope="scope">{{scope.row.msg_id}}</template>
      </el-table-column>
    </el-table>

    <el-dialog title="异地清分明细" :visible.sync="dialogTableVisible">
      <el-table :data="tableData" border :row-style="{ color: '#303133' }" ref="table"
                :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
                show-summary
                max-height="600"
                highlight-current-row>
        <el-table-column align="center" prop="name" label="身份证号码">
          <template slot-scope="scope">{{scope.row.certno}}</template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="就诊登记号">
          <template slot-scope="scope">{{scope.row.mdtrt_id}}</template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="就诊结算时间">
          <template slot-scope="scope">{{scope.row.mdtrt_setl_time}}</template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="就诊流水号">
          <template slot-scope="scope">{{scope.row.setl_sn}}</template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="全额垫付标志">
          <template slot-scope="scope" v-if="scope.row.fulamt_advpay_flag == 0">{{医院报销}}</template>
          <template slot-scope="scope" v-if="scope.row.fulamt_advpay_flag == 1">{{零星报销}}</template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="总费用">
          <template slot-scope="scope">{{scope.row.medfee_sumamt}}</template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="经办机构支付总额">
          <template slot-scope="scope">{{scope.row.optins_pay_sumamt}}</template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>

  <!-- </div> -->
</template>


<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import { getYidiClearRecord } from '@/api/his/his'
import { uParseTime } from '@/utils/tools'
import axios from 'axios'
const moment = require('moment')
export default {
  components: {
    BreadCrumb

  },
  data() {
    return {
      dialogTableVisible:false,
      year:'',
      month:'',
      tableData:[],
    }
  },
  methods: {
    getYidiClear(){
      var that = this;
      let params = {
        'year':this.month.split("-")[0],
        'month':this.month.split("-")[1],
        'admin_user_id':this.$store.getters.xt_user.user.id,
      };
      axios.get('http://127.0.0.1:9532/api/allopatry/get',{params:params}).then(function(response) {
        if (response.data.state == 0) {
          that.$message.error(response.data.data.msg);
          return false
        } else {
          this.dialogTableVisible = true
          this.tableData = []
          for(let i = 0; i < response.data.data.list.length; i++){
            let obj = {
              certno: response.data.data.list[i].certno,
              mdtrt_id:response.data.data.list[i].mdtrt_id,
              mdtrt_setl_time:response.data.data.list[i].mdtrt_setl_time,
              setl_sn:response.data.data.list[i].setl_sn,
              fulamt_advpay_flag:response.data.data.list[i].fulamt_advpay_flag,
              medfee_sumamt:response.data.data.list[i].medfee_sumamt,
              optins_pay_sumamt:response.data.data.list[i].optins_pay_sumamt,
            }
            this.tableData.push(obj)
          }
        }
      }).catch(function(error) {
      })
    },comfirmClear(){
      var that = this;
      let params = {
        'year':this.month.split("-")[0],
        'month':this.month.split("-")[1],
        'admin_user_id':this.$store.getters.xt_user.user.id,
      };
      axios.post('http://127.0.0.1:9532/api/comfirmallopatry/post',{params:params}).then(function(response) {
        if (response.data.state == 0) {
          that.$message.error(response.data.data.msg);
          return false
        } else {
          that.$message.success("异地清分确认成功");
        }
      }).catch(function(error) {
      })

    },
    getTime(value, temp) {
      if (value != undefined) {
        return uParseTime(value, temp)
      }
      return ''
    },
    getYidiClearRecord() {
      getYidiClearRecord({}).then(response => {
        if (response.data.state == 1) {



        } else {
          this.$message.error(response.data.msg)
        }
      })
    },
  },
  created() {
    this.getYidiClearRecord()

  }
}
</script>
