<!--RFID管理-->
<template>
  <div class="app-container approval_handle">
    <div class="approval_handle-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" style="margin-top:20px;" :inline="true">
        <el-form-item label="关键字" prop="name">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="标签码"
            clearable
            maxLength="30"
            size="small"
          />
        </el-form-item>
        <el-form-item label="添加时间" prop="dateRange">
          <el-date-picker
            :clearable="false"
            v-model="dateRange"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item style="float: right;">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleClick('','','add')"
              v-hasPermi="['airbottle:tag:add']"
            >新增</el-button>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="标签码" align="left" prop="tagCode"/>
        <el-table-column label="是否绑定" align="left" prop="isBind">
          <template slot-scope="scope">
            <span v-if="scope.row.isBind == 1">绑定</span>
            <span v-if="scope.row.isBind == 0">未绑定</span>
          </template>
        </el-table-column>
        <el-table-column label="添加时间" align="left" prop="createTime"></el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="260">
          <template slot-scope="scope">
            <div class="button-box">
              <p class="table-min-button"
                 style="margin-right: 10px"
                 @click="handleClick('',scope.row,'reprint')"
              >二维码补打</p>
              <p class="table-min-button"
                 @click="handleClick('',scope.row,'delete')"
                 v-hasPermi="['airbottle:tag:remove']"
              >删除</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination :page-sizes="[20, 30, 40, 50]"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- -->
    <el-dialog title="RFID标签录入" :visible.sync="dialogVisible " @close="handleClose" width="500px" append-to-body>
      <div style="text-align: center">
        <el-form ref="form" :model="form" label-width="80px">
          <p class="entering_t">请将RFID标签放置在RIFD读写器上进行识别</p>
          <img class="entering_img" src="@/assets/ZDimages/gasManage3_0/rfid_icon.png"/>
          <el-input  ref="clickPosition" style="width: 320px;margin: 20px 0;" v-model="form.tagCode" placeholder="rfid标签" />
        </el-form>
        <div id="form1" style="display: none">{{form.tagCode}}</div>
        <div slot="footer" class="dialog-footer" >
          <el-button style="width: 120px" type="primary" @click="printQRcode()">打印二维码</el-button>
        </div>
<!--        <vue-qr id="form1"  style="display: block;height:200px;width:200px;cursor:pointer;margin:0 auto;" text="12123123123123" :size="200"></vue-qr>-->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  qualificationApplyAdd,
  qualificationApplyList,
  RFIDtagAdd,
  RFIDtagDelete,
  RFIDtagList
} from '@/api/gasManage3_0/gasManage'
import { getToken } from "@/utils/auth";
import { getLodop } from "@/utils/LodopFuncs";
import vueQr from 'vue-qr'
import { delGroup } from '@/api/laboratory/group'
export default {
  name: "Approval",
  components: {
    vueQr
  },
  data() {
    return {
      dialogVisible :false,
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:'',
      },
      form:{
        tagCode:'',
      },
      total:0,
      tableData:[],
      dateRange:[],
    };


  },
  methods: {
    //监听弹窗关闭
    handleClose(){
      this.getList()
    },
    //新增的打印
    CreateOneFormPage() {
      LODOP = getLodop()

      LODOP.PRINT_INIT('') //打印初始化

      LODOP.SET_PRINT_STYLE('Bold', 1) //设置对象风格
      LODOP.ADD_PRINT_TEXT(138,30,300,200,this.form.tagCode,) //增加纯文本项
      LODOP.SET_PRINT_STYLEA(0,'FontSize', 14) //设置对象风格
      LODOP.SET_PRINT_PAGESIZE(1, 500, 300, '') //设定纸张大小
      LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '60%')//设置缩放
      LODOP.SET_PREVIEW_WINDOW(2, 2, 0, 0, 0, '')//设置窗口
      //LODOP.ADD_PRINT_HTM(2,80,160,160, document.getElementById("form1").innerHTML);//增加超文本项

      LODOP.ADD_PRINT_BARCODE(2,80,160, 160,'QRCode',this.form.tagCode);

    },

      handleClick(index,row,doType){
        let _this=this;
        if(doType=='add'){//添加
          _this.form.tagCode='';
         _this.dialogVisible=true;
         this.$nextTick(()=>{
           this.$refs.clickPosition.focus()
         })
        }else if(doType=='reprint'){//补打
          this.$confirm('是否确认补打二维码标签？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            _this.form.tagCode=row.tagCode
            setTimeout(function () {
              _this.CreateOneFormPage()
              LODOP.PREVIEW() //打印预览
            },100)
          }).catch(() => {});
        }else if(doType=='delete'){//删除
          this.$confirm('是否确认删除当前数据项?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            RFIDtagDelete(row.id).then( response => {
              if(response.code==200){
                _this.getList();
                _this.msgSuccess("删除成功");
              }
            });
          }).then(() => {

          }).catch(() => {});
        }else if(doType=='back'){//重新申请
          _this.pageType=1;
        }
      },
      //打印二维码
      printQRcode(){
        let _this=this;

        if(_this.form.tagCode==''){
          _this.msgError("请先录入RFID标签!");
          return
        }
        _this.submitForm();
        setTimeout(function () {
          _this.CreateOneFormPage()
          LODOP.PREVIEW() //打印预览
        },100)

      },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.searchValue = "";
      this.dateRange=[];
      this.queryParams.startTime=null;
      this.queryParams.endTime=null
      this.handleQuery();
    },
    getList(){
        let _this=this;
        if(this.dateRange&&this.dateRange.length>0) {
          this.queryParams.startTime=this.dateRange[0]
          this.queryParams.endTime=this.dateRange[1]
        } else {
          this.queryParams.startTime=null;
          this.queryParams.endTime=null
        }
        RFIDtagList(_this.queryParams).then( response => {
          let res=response.rows;
          _this.tableData=res;
          _this.total=response.total;
        });

      },
      submitForm(){
        let _this = this;
        RFIDtagAdd(_this.form).then(res => {
          this.$message({
            type: 'success',
            message: '操作成功!',
            duration:2000,
            onClose:function(){
              _this.backPage();
              _this.loading = false;
            }
          });
        });
      },


  },
  mounted() {
    this.getList();
  }
};
</script>

<style scoped lang="scss">
  .approval_handle {
    display: flex!important;
    flex-direction: column;
    .approval_handle-page{
      flex:1;
      display: flex!important;
      flex-direction: column;
      box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:20px 20px 20px!important;
      border-radius:10px;

      .button-box{
        width:200px;
        display: flex;
      }
    }
    .entering_t{
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
      line-height: 16px;
      margin: 36px auto 25px;
      text-align: center;
    }
    .entering_img{
      width: 288px;
      height: 140px;
    }
    .entering_input{
      width: 288px;
    }

  }
</style>
