Advertisement
roynaldoindra

reservasinew.ts

Aug 9th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.26 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { IonicPage, NavController, NavParams,ActionSheetController, ToastController, Platform, LoadingController, Loading } from 'ionic-angular';
  3. //import { Detilbayar } from '../detilbayar/detilbayar';
  4. import { File } from '@ionic-native/file';
  5. import { Transfer, TransferObject } from '@ionic-native/transfer';
  6. import { FilePath } from '@ionic-native/file-path';
  7. import { Camera } from '@ionic-native/camera';
  8. import { Storage } from '@ionic/storage';
  9. import { SalonDetail } from '../../providers/apisalondetil-service';
  10.  
  11. declare var cordova: any;
  12.  
  13. /**
  14. * Generated class for the Reservasi page.
  15. *
  16. * See http://ionicframework.com/docs/components/#navigation for more info
  17. * on Ionic pages and navigation.
  18. */
  19. @IonicPage({
  20. name : 'reservasi'
  21. })
  22. @Component({
  23. selector: 'page-reservasi',
  24. templateUrl: 'reservasi.html',
  25. })
  26. export class Reservasi {
  27. lastImage: string = null;
  28. loading: Loading;
  29.  
  30. public nama: any;
  31. public alamat: any;
  32. public noTelp: any;
  33.  
  34. public idUser : any;
  35. public idCust : any;
  36. public dataSalon: any;
  37. public datas: any;
  38. public data: any;
  39. public data2: any;
  40. public nama_service: any;
  41. public nama_pelayan: any;
  42. public data_pelayan : any;
  43. public data_service : any;
  44. public tgl_pesan : any;
  45. public data_harga : any;
  46. public nama_bank : any;
  47. public no_rek : any;
  48.  
  49.  
  50. myDate
  51.  
  52.  
  53. constructor(public navCtrl: NavController, public navParams: NavParams,
  54. private camera: Camera, private transfer: Transfer, private file: File,
  55. private filePath: FilePath, public actionSheetCtrl: ActionSheetController,
  56. public toastCtrl: ToastController,
  57. public platform: Platform, public loadingCtrl: LoadingController, private storage: Storage,
  58. private salondetailApi: SalonDetail ) {
  59. this.myDate = new Date().toISOString();
  60. console.log(this.myDate);
  61.  
  62. this.data_pelayan = [];
  63. this.data_service = [];
  64. this.data = {
  65. id_admin : this.navParams.get('id_user')
  66. };
  67. console.log(this.data);
  68.  
  69.  
  70. }
  71.  
  72. ionViewDidLoad() {
  73. console.log('ionViewDidLoad Reservasi');
  74. this.storage.ready().then(()=>{
  75. this.storage.get('loginAuth').then((loginAuth) => {
  76. console.log(loginAuth, 'Data Reservasi Profil')
  77. this.idCust = loginAuth.data["0"].id_cust;
  78. this.nama = loginAuth.data["0"].nama_cust;
  79. this.alamat = loginAuth.data['0'].alamat;
  80. this.noTelp = loginAuth.data['0'].no_hp;
  81. })
  82. })
  83. }
  84.  
  85.  
  86. ionViewDidEnter(){
  87.  
  88. this.idUser = this.navParams.get('id_user')
  89. console.log(this.idUser, 'idUser')
  90.  
  91.  
  92. this.salondetailApi.viewReservasi({ id_user: this.idUser }).then((result) =>{
  93. this.dataSalon = result;
  94. this.datas = this.dataSalon.data;
  95. this.nama_bank = this.data;
  96. this.no_rek = this.data;
  97. this.tgl_pesan=this.data;
  98. this.data_pelayan = this.dataSalon.pelayan;
  99. this.data_service = this.dataSalon.service;
  100. });
  101. }
  102.  
  103. kirim(){
  104. this.salondetailApi.kirimReservasiData(this.data).then(
  105. (response) => {
  106. let r : any = response;
  107. if(r.error){
  108. let toast = this.toastCtrl.create({
  109. message : r.msg,
  110. position : 'top',
  111. duration : 3000
  112. });
  113. toast.present();
  114. return false;
  115. }
  116. let toast = this.toastCtrl.create({
  117. message : 'Terkirim',
  118. position : 'top',
  119. duration : 3000
  120. });
  121. toast.present();
  122. this.navCtrl.pop();
  123. }
  124. );
  125. console.log(this.data,'');
  126. }
  127.  
  128. changeService(idService){
  129.  
  130. //Ini tingal query lagi ke backend untuk dapetin detail servicenya.. berdasarkan ID.. trus masukin ke harga.
  131. this.salondetailApi.viewService({ id: idService }).then(
  132. (result:any) =>{
  133. console.log(result);
  134. this.data.harga = result.data[0].harga;
  135. });
  136. }
  137. /*detilbayar(){
  138. this.navCtrl.push(Detilbayar);
  139. }*/
  140.  
  141. public presentActionSheet() {
  142. let actionSheet = this.actionSheetCtrl.create({
  143. title: 'Select Image Source',
  144. buttons: [
  145. {
  146. text: 'Load from Library',
  147. handler: () => {
  148. this.takePicture(this.camera.PictureSourceType.PHOTOLIBRARY);
  149. }
  150. },
  151. {
  152. text: 'Use Camera',
  153. handler: () => {
  154. this.takePicture(this.camera.PictureSourceType.CAMERA);
  155. }
  156. },
  157. {
  158. text: 'Cancel',
  159. role: 'cancel'
  160. }
  161. ]
  162. });
  163. actionSheet.present();
  164. }
  165.  
  166. public takePicture(sourceType) {
  167. // Create options for the Camera Dialog
  168. var options = {
  169. quality: 100,
  170. sourceType: sourceType,
  171. saveToPhotoAlbum: false,
  172. correctOrientation: true
  173. };
  174.  
  175. // Get the data of an image
  176. this.camera.getPicture(options).then((imagePath) => {
  177. // Special handling for Android library
  178. if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
  179. this.filePath.resolveNativePath(imagePath)
  180. .then(filePath => {
  181. let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
  182. let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
  183. this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
  184. });
  185. } else {
  186. var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
  187. var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
  188. this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
  189. }
  190. }, (err) => {
  191. this.presentToast('Error while selecting image.');
  192. });
  193. }
  194.  
  195. private createFileName() {
  196. var d = new Date(),
  197. n = d.getTime(),
  198. newFileName = n + ".jpg";
  199. return newFileName;
  200. }
  201.  
  202. // Copy the image to a local folder
  203. private copyFileToLocalDir(namePath, currentName, newFileName) {
  204. this.file.copyFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(success => {
  205. this.lastImage = newFileName;
  206. }, error => {
  207. this.presentToast('Error while storing file.');
  208. });
  209. }
  210.  
  211. private presentToast(text) {
  212. let toast = this.toastCtrl.create({
  213. message: text,
  214. duration: 3000,
  215. position: 'top'
  216. });
  217. toast.present();
  218. }
  219.  
  220. // Always get the accurate path to your apps folder
  221. public pathForImage(img) {
  222. if (img === null) {
  223. return '';
  224. } else {
  225. return cordova.file.dataDirectory + img;
  226. }
  227. }
  228.  
  229. public uploadImage() {
  230. // Destination URL
  231. var url = "http://localhost/sss/index.php/ApiKirimReservasi/upload/";
  232.  
  233. // File for Upload
  234. var targetPath = this.pathForImage(this.lastImage);
  235.  
  236. // File name only
  237. var filename = this.lastImage;
  238.  
  239. var options = {
  240. fileKey: "file",
  241. fileName: filename,
  242. chunkedMode: false,
  243. mimeType: "multipart/form-data",
  244. params : {'fileName': filename}
  245. };
  246.  
  247. const fileTransfer: TransferObject = this.transfer.create();
  248.  
  249. this.loading = this.loadingCtrl.create({
  250. content: 'Uploading...',
  251. });
  252. this.loading.present();
  253.  
  254. // Use the FileTransfer to upload the image
  255. fileTransfer.upload(targetPath, url, options).then(data => {
  256. this.loading.dismissAll()
  257. this.presentToast('Image succesful uploaded.');
  258. }, err => {
  259. this.loading.dismissAll()
  260. this.presentToast('Error while uploading file.');
  261. });
  262.  
  263. }
  264.  
  265.  
  266.  
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement