Newer
Older
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import {Component} from '@angular/core';
import {ActionSheetController, IonicPage, LoadingController, NavController, NavParams} from 'ionic-angular';
import {AppGlobal} from "../../../../service/http.service";
import {CommonService} from "../../../../provide/common.service";
import {Camera, CameraOptions} from "@ionic-native/camera";
import {FileTransfer, FileTransferObject, FileUploadOptions} from "@ionic-native/file-transfer";
import {ServeService} from "../../serve.service";
@Component({
selector: 'page-repair-apply',
templateUrl: 'repair-apply.html',
})
export class RepairApplyPage {
rId;
pictrue = AppGlobal.domain + '/wisdomgroup';
obj = <any>{
equipmentName: '',
remark: '',
urlList: []
};
status;
actionSheet_image;
constructor(public navCtrl: NavController, public navParams: NavParams,
public camera: Camera, private serveSer: ServeService,
public loadingCtrl: LoadingController, public transfer: FileTransfer,
private actionSheetCtrl: ActionSheetController, private commonSer: CommonService) {
}
ionViewDidLoad() {
this.rId = this.navParams.get('id');
if (this.rId) this.getDetail();
}
getDetail() {
this.serveSer.editRepair(this.rId).subscribe(
(res) => {
for (let key in this.obj) {
if (res.data[key]) this.obj[key] = res.data[key];
}
this.status = res.data.status;
}
)
}
tackePic() {
this.actionSheet_image = this.actionSheetCtrl.create({
cssClass: 'cameraAction',
buttons: [
{
text: '拍照',
role: 'fromCamera',
handler: () => {
console.log('fromCamera');
this.selectPicture(1);
}
}, {
text: '从相册中选',
role: 'fromPhoto',
handler: () => {
console.log('fromPhoto');
this.selectPicture(0);
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
this.actionSheet_image.present();
}
//选择图片
selectPicture(srcType) {
if (this.obj.urlList.length > 8) {
this.commonSer.toast('一批文章最多上传9个图片');
return false;
}
const options: CameraOptions = {
quality: 70,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: srcType,
saveToPhotoAlbum: false
};
const option: FileUploadOptions = {
httpMethod: 'POST',
headers: {
'Accept': 'application/json',
},
fileName: 'image.png'
};
this.camera.getPicture(options).then((imagedata) => {
let filePath = imagedata;
if (filePath.indexOf('?') !== -1) { //获取文件名
filePath = filePath.split('?')[0];
}
let arr = filePath.split('/');
console.log(imagedata);
option.fileName = arr[arr.length - 1];
this.upload(imagedata, option);
})
}
upload(file, options) {
this.commonSer.log(file);
const uploadLoading = this.loadingCtrl.create({
content: '上传中...',
dismissOnPageChange: true,
enableBackdropDismiss: true,
});
uploadLoading.present();
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.upload(file, AppGlobal.domain + '/wisdomgroup/modules/common/file/upload1', options).then(
(res) => {
uploadLoading.dismiss();
this.commonSer.toast('上传成功');
const data = JSON.parse(res.response);
this.commonSer.log(data.data[0].filePath);
this.obj.urlList.push(data.data[0].filePath);
}, err => {
uploadLoading.dismiss();
this.commonSer.toast('上传错误');
});
fileTransfer.onProgress((listener) => {
let per = <any>(listener.loaded / listener.total) * 100;
per = Math.round(per * Math.pow(10, 2)) / Math.pow(10, 2)
uploadLoading.setContent('上传中...' + per + '%');
})
}
//删除文件
deleteFile(i) {
this.obj.urlList.splice(i, 1);
}
//提交
submit() {
this.commonSer.alert('确定提交申请?', () => {
if (this.rId) this.obj.id = this.rId;
this.serveSer.saveRepair(this.obj).subscribe(
(res) => {
if (res.errcode == 1000) {
this.commonSer.toast('申请报修成功');
this.navCtrl.pop();
} else {
this.commonSer.toast(res.errmsg);
}
}
)
});
}
}