|  | @@ -1,11 +1,11 @@
 | 
	
		
			
				|  |  |  <template>
 | 
	
		
			
				|  |  |    <div class="nfc-popup">
 | 
	
		
			
				|  |  | -    <van-popup v-model="visible" get-container="nfc-popup" lock-scroll>
 | 
	
		
			
				|  |  | +    <van-popup v-model="visible" get-container="nfc-popup" lock-scroll :close-on-click-overlay="closeOverlay">
 | 
	
		
			
				|  |  |        <div class="nfc-panel">
 | 
	
		
			
				|  |  |          <div>
 | 
	
		
			
				|  |  |            <p v-if="showBottomBox" class="top-text">将手机背部靠近NFC标签扫描</p>
 | 
	
		
			
				|  |  |            <div class="image-box">
 | 
	
		
			
				|  |  | -            <img class="nfc-image" v-show="nfcImage" :src="nfcImage" alt="">
 | 
	
		
			
				|  |  | +            <img class="nfc-image" v-show="nfcImage" :src="nfcImage" alt="" @click="nfcTakePhotos">
 | 
	
		
			
				|  |  |            </div>
 | 
	
		
			
				|  |  |            <div v-if="showBottomBox" class="bottom-box">
 | 
	
		
			
				|  |  |              <div>
 | 
	
	
		
			
				|  | @@ -17,6 +17,10 @@
 | 
	
		
			
				|  |  |                <span @click="nfcTakePhotos">拍照</span>
 | 
	
		
			
				|  |  |              </div>
 | 
	
		
			
				|  |  |            </div>
 | 
	
		
			
				|  |  | +          <div v-else>
 | 
	
		
			
				|  |  | +            <select-cell title="点击选择NFC列表" @change="changeNFC" v-model="selectNFC" :prop="prop" :dataList="dataList"/>
 | 
	
		
			
				|  |  | +            <van-button v-if="showBtn" type="primary"  size="small" block plain @click="onConfirm">确定</van-button>
 | 
	
		
			
				|  |  | +          </div>
 | 
	
		
			
				|  |  |          </div>
 | 
	
		
			
				|  |  |        </div>
 | 
	
		
			
				|  |  |        <input v-show="false" ref="upload" type='file' accept="image/*" @change="fileChange"/>
 | 
	
	
		
			
				|  | @@ -25,49 +29,86 @@
 | 
	
		
			
				|  |  |  </template>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  <script>
 | 
	
		
			
				|  |  | +import SelectCell from "@/components/selectCell";
 | 
	
		
			
				|  |  |  import {baseImg} from "@/views/menu/LZRegister/api";
 | 
	
		
			
				|  |  |  import {upload} from "@/api/public";
 | 
	
		
			
				|  |  |  import ImageCompressor from "js-image-compressor";
 | 
	
		
			
				|  |  |  export default {
 | 
	
		
			
				|  |  | -  name: "index",
 | 
	
		
			
				|  |  | +  components:{SelectCell},
 | 
	
		
			
				|  |  |    data(){
 | 
	
		
			
				|  |  |      return {
 | 
	
		
			
				|  |  |        //nfc弹窗
 | 
	
		
			
				|  |  |        visible:false,
 | 
	
		
			
				|  |  | -      //nfc图片(base64)
 | 
	
		
			
				|  |  | +      //上传的nfc图片
 | 
	
		
			
				|  |  |        nfcImage:null,
 | 
	
		
			
				|  |  |        //是否显示底部按钮
 | 
	
		
			
				|  |  |        showBottomBox:true,
 | 
	
		
			
				|  |  | +      //nfc数据
 | 
	
		
			
				|  |  | +      dataList:[],
 | 
	
		
			
				|  |  | +      //选中的nfc
 | 
	
		
			
				|  |  | +      selectNFC:null,
 | 
	
		
			
				|  |  | +      //自定义字段
 | 
	
		
			
				|  |  | +      prop:{
 | 
	
		
			
				|  |  | +        label:'checkName',
 | 
	
		
			
				|  |  | +        value:'nfccdoe'
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +      //是否可点击遮罩层关闭
 | 
	
		
			
				|  |  | +      closeOverlay:true,
 | 
	
		
			
				|  |  | +      showBtn:false,
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  |    watch:{
 | 
	
		
			
				|  |  |      visible(val){
 | 
	
		
			
				|  |  | -      if(val){
 | 
	
		
			
				|  |  | -        this.nfcImage = null;
 | 
	
		
			
				|  |  | -        this.showBottomBox = true;
 | 
	
		
			
				|  |  | +      if(!this.visible){
 | 
	
		
			
				|  |  | +        this.clear();
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  |    methods:{
 | 
	
		
			
				|  |  | +    onConfirm(){
 | 
	
		
			
				|  |  | +      let data = {
 | 
	
		
			
				|  |  | +        nfcCode:this.selectNFC,
 | 
	
		
			
				|  |  | +        url:this.nfcImage,
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      this.$emit('change',data);
 | 
	
		
			
				|  |  | +      this.visible = false;
 | 
	
		
			
				|  |  | +      this.clear();
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    //切换nfc后可点击退出
 | 
	
		
			
				|  |  | +    changeNFC(){
 | 
	
		
			
				|  |  | +      this.showBtn = true;
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    //清空数据
 | 
	
		
			
				|  |  | +    clear(){
 | 
	
		
			
				|  |  | +      this.nfcImage = null;
 | 
	
		
			
				|  |  | +      this.showBottomBox = true;
 | 
	
		
			
				|  |  | +      this.selectNFC = null;
 | 
	
		
			
				|  |  | +      this.dataList = [];
 | 
	
		
			
				|  |  | +      this.closeOverlay = true;
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    //显示弹窗
 | 
	
		
			
				|  |  | +    show(list){
 | 
	
		
			
				|  |  | +      this.visible = true;
 | 
	
		
			
				|  |  | +      this.dataList = list;
 | 
	
		
			
				|  |  | +      console.log(this.dataList,'datalist')
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |      //上传前
 | 
	
		
			
				|  |  |      async fileChange(e){
 | 
	
		
			
				|  |  |        let file = e.target.files[0];
 | 
	
		
			
				|  |  | -      let fileName = e.target.files[0].name;
 | 
	
		
			
				|  |  | +     // let fileName = e.target.files[0].name;
 | 
	
		
			
				|  |  |        let imgFile = await this.imageCompress(file);
 | 
	
		
			
				|  |  | -      console.log(imgFile,'imgFile')
 | 
	
		
			
				|  |  |        let formData = new FormData();
 | 
	
		
			
				|  |  |        formData.append('file',imgFile);
 | 
	
		
			
				|  |  |        upload(formData,'image').then(res=>{
 | 
	
		
			
				|  |  | -        console.log(res,'resssss')
 | 
	
		
			
				|  |  | -        this.nfcImage = baseImg.base;
 | 
	
		
			
				|  |  | -        this.$emit('change',baseImg)
 | 
	
		
			
				|  |  | +        //上传成功后,将图片显示在页面上并禁用退出
 | 
	
		
			
				|  |  | +        this.nfcImage = res.data.url;
 | 
	
		
			
				|  |  |          this.showBottomBox = false;
 | 
	
		
			
				|  |  | +        this.closeOverlay = false;
 | 
	
		
			
				|  |  |        })
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |      //压缩图片
 | 
	
		
			
				|  |  |      imageCompress(file){
 | 
	
		
			
				|  |  | -      let imageCom = new Promise((resolve,reject)=>{
 | 
	
		
			
				|  |  | +       return new Promise((resolve,reject)=>{
 | 
	
		
			
				|  |  |          new ImageCompressor({
 | 
	
		
			
				|  |  |            file,
 | 
	
		
			
				|  |  |            quality: 0.6,
 | 
	
	
		
			
				|  | @@ -88,7 +129,6 @@ export default {
 | 
	
		
			
				|  |  |            },
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |        });
 | 
	
		
			
				|  |  | -      return imageCom;
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |      //拍照
 | 
	
		
			
				|  |  |      nfcTakePhotos(){
 | 
	
	
		
			
				|  | @@ -122,6 +162,7 @@ export default {
 | 
	
		
			
				|  |  |  .image-box{
 | 
	
		
			
				|  |  |    width: 100%;
 | 
	
		
			
				|  |  |    height: 350px;
 | 
	
		
			
				|  |  | +  padding: 20px;
 | 
	
		
			
				|  |  |    display: flex;
 | 
	
		
			
				|  |  |    align-items: center;
 | 
	
		
			
				|  |  |    justify-content: center;
 | 
	
	
		
			
				|  | @@ -129,6 +170,7 @@ export default {
 | 
	
		
			
				|  |  |  .nfc-image{
 | 
	
		
			
				|  |  |    width: 300px;
 | 
	
		
			
				|  |  |    height: 300px;
 | 
	
		
			
				|  |  | +  background-color: #fff;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  .bottom-box{
 | 
	
		
			
				|  |  |    display: flex;
 |