wuxw
2019-07-20 39ceed7f60905297629a45978cc29b6fe8bd05d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(function(vc){
    vc.extends({
        data:{
            positivePhotoInfo:{
                chooseFlag:0,// 1表示选择了照片,0表示未选择照片
                imgInfo:"",
                errorInfo:"",
            }
        },
         _initMethod:function(){
 
         },
         _initEvent:function(){
//              vc.component.$on('errorInfoEvent',function(_errorInfo){
//                     vc.component.registerInfo.errorInfo = _errorInfo;
//                     console.log('errorInfoEvent 事件被监听',_errorInfo)
//                 });
 
         },
        watch:{
            positivePhotoInfo:{
                deep: true,
                handler:function(){
                    vc.component.$emit('positivePhotoEvent',vc.component.positivePhotoInfo);
                }
             }
        },
        methods:{
 
            choosePositivePhoto:function(event){
                var photoFiles = event.target.files;
                if (photoFiles && photoFiles.length > 0) {
                        // 获取目前上传的文件
                        var file = photoFiles[0];// 文件大小校验的动作
                        if(file.size > 1024 * 1024 * 1) {
                            vc.component.positivePhotoInfo.errorInfo = '图片大小不能超过 2MB!';
                            return false;
                        }
                        var reader = new FileReader(); //新建FileReader对象
                        reader.readAsDataURL(file); //读取为base64
                        console.log('render obj:',reader);
                        reader.onloadend = function(e) {
                            vc.component.positivePhotoInfo.imgInfo = reader.result;
                            vc.component.positivePhotoInfo.chooseFlag = 1;
                        }
                    }
            },
            validatePositivePhoto:function(){
                return vc.validate.validate({
                                                   positivePhotoInfo:vc.component.positivePhotoInfo
                                               },{
                                                   'positivePhotoInfo.imgInfo':[
                                                       {
                                                           limit:"required",
                                                           param:"",
                                                           errInfo:"未上传证件照"
                                                       }
                                                   ],
 
                                               });
            }
        }
 
    });
 
})(window.vc);