<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-input size="small" style="width:150px;" v-model="keywords" @input="searchAction"
                              @keyup.enter.native='searchAction'
                              placeholder="请输入患者姓名"
                              class="filter-item"/>
                    <el-select size="small" v-model="item_type" placeholder="请选择"
                               style="width:150px;margin-left:10px;" @change="changeItem">
                        <el-option
                                label="全部"
                                value="0">
                        </el-option>
                        <el-option
                                v-for="item,index in items"
                                :key="index"
                                :label="item.name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                    <el-date-picker
                            v-model="chargeDate"
                            type="date"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd"
                            @change="changeDate"
                    >
                    </el-date-picker>
                </div>
            </div>
            <el-table :data="tableData" border :row-style="{ color: '#303133' }" ref="table"
                      :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
                      highlight-current-row>

                <el-table-column align="center" prop="name" label="患者名字">
                    <template slot-scope="scope">{{ scope.row.patient_name }}</template>
                </el-table-column>

                <el-table-column align="center" prop="name" label="处方号">
                    <template slot-scope="scope">{{scope.row.number}}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="创建时间">
                    <template slot-scope="scope">{{getTime(scope.row.record_date, '{y}-{m}-{d}')}}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="创建医生">
                    <template slot-scope="scope">{{scope.row.doctor_name}}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="项目名称">
                    <template slot-scope="scope">
                        <div>{{scope.row.project_name}}</div>
                    </template>
                </el-table-column>

                <el-table-column
                        align="center"
                        label="操作"
                        width="180"
                        class-name="small-padding fixed-width"
                >
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="打印" placement="top">
                            <el-button
                                    type="primary"
                                    size="small"
                                    icon="el-icon-edit-outline"
                                    @click="Print(scope.row, scope.$index)"
                            >
                            </el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>


            </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-sizes="[10, 50, 100]"
                    :page-size="10"
                    background
                    style="margin-top:20px;float: right"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
            >
            </el-pagination>
        </div>

        <el-dialog title="打印" :visible.sync="labelVisible">
            <div>
                <el-row style="float:right;">
                    <el-col :span="24">
                        <el-button size="small" icon="el-icon-printer" type="primary" @click="printAction">打印
                        </el-button>
                    </el-col>
                </el-row>
                  <div id="sign" class="signPrint">
                      <div style="display:flex;margin-bottom:10px;">
                          <div style="margin-left:15px;">
                              <div style="font-weight:bold;font-size:24px;">C</div>
                              <div>{{getTime(current_ctime,'{m}-{d}')}}</div>
                              <div>{{getTime(current_ctime,'{h}:{i}')}}</div>
                          </div>
                          <img style="width:300px;height:200px;margin-left:10px;" id="barcode">
                      </div>
                      <div style="margin-bottom:5px;">{{current_number}}</div>
                      <div style="display:flex;">
                          <div style="padding-left:20px;">{{current_project_name}}</div>
                          <div style="font-size:24px;margin-left:20px;">{{current_name}}</div>
                      </div>
                  </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="labelVisible = false">取 消</el-button>
                <el-button type="primary" @click="labelVisible = false">确 定</el-button>
            </div>
        </el-dialog>
    </div>

</template>


<script>
  import BreadCrumb from '@/xt_pages/components/bread-crumb'
  import { GetLabelList } from '@/api/his/his'
  import { uParseTime } from '@/utils/tools'
  import SignPrint from '../dialysis/signPrint'
  import JsBarcode from 'jsbarcode'

  // import NewStatementPrint from './newStatementPrint'
  const moment = require('moment')
  export default {
    components: {
      SignPrint,
      BreadCrumb

    },
    data() {
      return {
        current_ctime: 0,
        current_number: '',
        current_project_name: '',
        current_name: '',

        labelVisible: false,
        crumbs: [
          { path: false, name: 'HIS工具' },
          { path: false, name: '标签打印' }
        ],
        detail_loading: false,
        tempArr: [],
        pos: 0,
        page: 1,
        limit: 10,
        total: 0,
        current_id: 0,
        sameRowArr: [],
        keywords: '',
        tableData: [],
        chargeDate: moment(new Date()).add('year', 0).format('YYYY-MM-DD'),
        item_type: '0',
        items: [
          { id: 1, name: '已打印' },
          { id: 2, name: '未打印' }
        ]

      }
    },
    methods: {
      printAction: function() {
        const style = '@media print { .sign{width:960px;margin: 0 auto;text-align: center;border-collapse: collapse;}.order_title_panl {text-align: center;.main_title {font-size: 18px;line-height: 40px;font-weight: 500;}}.dialysisTable tr{padding: 10px 0;}.dialysisTable th {color: #000;padding: 0;margin: 0;height: 30px;}.dialysisTable tr td {padding: 12px 0;}.subadvice_content {text-align: left;padding-left: 25px !important;padding-right: 5px !important;}.advice_content {text-align: left;padding-left: 5px !important;padding-right: 5px !important;padding: 15px 5px !important;} }'
        printJS({
          printable: 'sign',
          type: 'html',
          documentTitle: '  ',
          style: style,
          scanStyles: false
        })
      },
      getTime(value, temp) {
        if (value != undefined) {
          return uParseTime(value, temp)
        }
        return ''
      },
      Print(row, index) {
        this.labelVisible = true
        this.current_ctime = row.ctime
        this.current_number = row.number
        this.current_project_name = row.project_name
        this.current_name = row.patient_name
        this.$nextTick(() => {
          JsBarcode('#barcode',row.id, {
            format: 'CODE39',
            lineColor: '#000',
            background: '#EBEEF5',
            width: 3,
            height: 200,
            displayValue: false,
            fontOptions:"bold italic",//使文字加粗体或变斜体
            font:"fantasy",//设置文本的字体
            textAlign:"left",//设置文本的水平对齐方式
            textPosition:"top",//设置文本的垂直位置
            textMargin:5,//设置条形码和文本之间的间距
            fontSize:15,//设置文本的大小
            margin:15//设置条形码周围的空白边距
          })

        });

      },
      handleCurrentChange(page) {
        this.page = page
        this.getList()

      },

      handleSizeChange(limit) {
        this.limit = limit
        this.getList()

      },

      changeDate() {
        this.page = 1
        this.limit = 10
        this.getList()
      },
      changeItem() {
        this.page = 1
        this.limit = 10
        this.getList()
      },
      searchAction() {
        this.page = 1
        this.limit = 10
        this.getList()
      },
      getList() {
        let params = {
          record_date: this.chargeDate,
          is_print: this.item_type,
          keyword: this.keywords,
          page: this.page,
          limit: this.limit
        }
        GetLabelList(params).then(response => {
          if (response.data.state == 0) {

            this.$message.error(response.data.msg)
            return false
          } else {

            this.tableData = response.data.data.labels
            this.total = response.data.data.total

          }

        })
      }
    },
    created() {
      this.getList()

    }, mounted() {

    }
  }
</script>
