user-data.ts 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. import { Injectable } from '@angular/core';
  2. import { Events, LoadingController, ToastController } from '@ionic/angular';
  3. import { Storage } from '@ionic/storage';
  4. import { HTTP } from '@ionic-native/http/ngx';
  5. import { from } from 'rxjs';
  6. import { Router } from '@angular/router';
  7. import { AlertController } from '@ionic/angular';
  8. import { finalize } from 'rxjs/operators';
  9. import { queryForm } from './query';
  10. import { environment } from '../environments/environment';
  11. @Injectable({
  12. providedIn: 'root'
  13. })
  14. export class UserData {
  15. // tslint:disable-next-line:variable-name
  16. _favorites: string[] = [];
  17. HAS_LOGGED_IN = 'hasLoggedIn';
  18. HAS_SEEN_TUTORIAL = 'hasSeenTutorial';
  19. constructor(
  20. public events: Events,
  21. private nativeHttp: HTTP,
  22. private loadingCtrl: LoadingController,
  23. public alertController: AlertController,
  24. public storage: Storage,
  25. public queryForm: queryForm,
  26. private router: Router,
  27. private toastCtrl: ToastController
  28. ) {
  29. // this.nativeHttp.setDataSerializer('json')
  30. }
  31. // hasFavorite(sessionName: string): boolean {
  32. // return (this._favorites.indexOf(sessionName) > -1);
  33. // }
  34. // addFavorite(sessionName: string): void {
  35. // this._favorites.push(sessionName);
  36. // }
  37. // removeFavorite(sessionName: string): void {
  38. // const index = this._favorites.indexOf(sessionName);
  39. // if (index > -1) {
  40. // this._favorites.splice(index, 1);
  41. // }
  42. // }
  43. // 登录
  44. login(account: string, password: string): Promise<any> {
  45. return this.storage.set(this.HAS_LOGGED_IN, false).then(async () => {
  46. const loading = await this.loadingCtrl.create();
  47. await loading.present();
  48. // Returns a promise, need to convert with of() to Observable (if want)!
  49. // this.nativeHttp.setDataSerializer('json')
  50. // tslint:disable-next-line:max-line-length
  51. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/auth/oauth/token?username=${account}&password=${encodeURIComponent(password)}&grant_type=password&scope=server`,
  52. {},
  53. { Authorization: 'Basic cGlnOnBpZw==', TENANT_ID: '1', isToken: 'false', })).pipe(
  54. finalize(() => loading.dismiss())
  55. ).subscribe(async data => {
  56. if (JSON.parse(data.data).code == 1) {
  57. const toast = await this.toastCtrl.create({
  58. message: JSON.parse(data.data).msg,
  59. duration: 1000,
  60. position: 'top'
  61. });
  62. await toast.present();
  63. } else {
  64. this.storage.set('access_token', JSON.parse(data.data).access_token);
  65. this.storage.set('username', JSON.parse(data.data).username);
  66. this.storage.set('user_id', JSON.parse(data.data).user_id);
  67. this.storage.set(this.HAS_LOGGED_IN, true);
  68. this.router.navigateByUrl('/home');
  69. return this.events.publish('user:login');
  70. }
  71. }, async err => {
  72. console.log(err);
  73. const toast = await this.toastCtrl.create({
  74. message: err.error + err.url,
  75. duration: 1000,
  76. position: 'top'
  77. });
  78. await toast.present();
  79. });
  80. return;
  81. });
  82. }
  83. // signup(username: string): Promise<any> {
  84. // return this.storage.set(this.HAS_LOGGED_IN, true).then(() => {
  85. // this.setUsername(username);
  86. // return this.events.publish('user:signup');
  87. // });
  88. // }
  89. getToken(): Promise<any> {
  90. return this.storage.get('access_token').then((val) => {
  91. return val;
  92. });
  93. }
  94. // 获取App menu
  95. async getAppMenu(): Promise<any> {
  96. const token = await this.getToken();
  97. return new Promise((resolve, reject) => {
  98. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/admin/menu/app`,
  99. {},
  100. { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' })).pipe(
  101. finalize(() => { })
  102. ).subscribe(async data => {
  103. // console.log(JSON.parse(data.data))
  104. resolve(JSON.parse(data.data).data)
  105. }, async err => {
  106. console.log(err);
  107. const toast = await this.toastCtrl.create({
  108. message: '查询目录失败',
  109. duration: 1000,
  110. position: 'top'
  111. });
  112. await toast.present();
  113. });
  114. return;
  115. })
  116. }
  117. async logout(): Promise<any> {
  118. const alert = await this.alertController.create({
  119. header: '安全退出',
  120. message: '确定要登出吗',
  121. buttons: [
  122. {
  123. text: '确定',
  124. role: 'cancel',
  125. cssClass: 'secondary',
  126. handler: () => {
  127. this.router.navigateByUrl('/login');
  128. return this.storage.remove(this.HAS_LOGGED_IN).then(async () => {
  129. }).then(() => {
  130. this.events.publish('user:logout');
  131. });
  132. }
  133. }, {
  134. text: '取消'
  135. }
  136. ]
  137. });
  138. await alert.present();
  139. return this.storage.clear();
  140. }
  141. // 开单号扫描
  142. async ssfCodeScan(data: object): Promise<any> {
  143. const token = await this.getToken();
  144. const loading = await this.loadingCtrl.create();
  145. await loading.present();
  146. this.nativeHttp.setDataSerializer('json');
  147. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  148. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/sample/factory/`,
  149. data,
  150. headers)).pipe(
  151. finalize(() => { })
  152. ).subscribe(data => {
  153. this.storage.set('ssfId', JSON.parse(data.data).data.ssfId)
  154. }, async err => {
  155. console.log(err)
  156. let toast = await this.toastCtrl.create({
  157. message: '获取数据失败',
  158. duration: 1000,
  159. position: 'top'
  160. });
  161. await toast.present();
  162. });
  163. return;
  164. }
  165. // 货号扫描
  166. async pCodeScan(data: object): Promise<any> {
  167. const token = await this.getToken();
  168. const loading = await this.loadingCtrl.create();
  169. await loading.present();
  170. this.nativeHttp.setDataSerializer('json');
  171. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  172. return new Promise((resolve, reject) => {
  173. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/sample/factory/pCode`,
  174. data,
  175. headers)).pipe(
  176. finalize(() => loading.dismiss() )
  177. ).subscribe(async data => {
  178. if (JSON.parse(data.data).code == 1) {
  179. const toast = await this.toastCtrl.create({
  180. message: JSON.parse(data.data).msg,
  181. duration: 1000,
  182. position: 'top'
  183. });
  184. await toast.present();
  185. resolve([]);
  186. } else if (JSON.parse(data.data).code == 0) {
  187. resolve(JSON.parse(data.data).data)
  188. }
  189. }, async err => {
  190. console.log(err)
  191. let toast = await this.toastCtrl.create({
  192. message: '获取数据失败',
  193. duration: 1000,
  194. position: 'top'
  195. });
  196. await toast.present();
  197. });
  198. })
  199. }
  200. // 新增样品工厂详细
  201. async saveFactoryDetails(data: object): Promise<any> {
  202. const token = await this.getToken();
  203. const loading = await this.loadingCtrl.create();
  204. await loading.present();
  205. this.nativeHttp.setDataSerializer('json');
  206. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  207. return new Promise((resolve, reject) => {
  208. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/sample/factory/details/`,
  209. data,
  210. headers)).pipe(
  211. finalize(() => loading.dismiss())
  212. ).subscribe(async data => {
  213. let message = ''
  214. if (JSON.parse(data.data).code == 1) {
  215. message = JSON.parse(data.data).msg
  216. resolve([]);
  217. } else if (JSON.parse(data.data).code == 0) {
  218. message = '保存成功'
  219. resolve(JSON.parse(data.data).data)
  220. }
  221. const toast = await this.toastCtrl.create({
  222. message: message,
  223. duration: 1000,
  224. position: 'top'
  225. });
  226. await toast.present();
  227. }, async err => {
  228. console.log(err)
  229. let toast = await this.toastCtrl.create({
  230. message: '保存失败',
  231. duration: 1000,
  232. position: 'top'
  233. });
  234. await toast.present();
  235. });
  236. })
  237. }
  238. // 获取样品单列表
  239. async getSampleTableData(form: object): Promise<any> {
  240. const token = await this.getToken();
  241. const loading = await this.loadingCtrl.create();
  242. await loading.present();
  243. this.nativeHttp.setDataSerializer('json');
  244. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  245. return new Promise((resolve, reject) => {
  246. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/search/samples/mobile/page`,
  247. form,
  248. headers)).pipe(
  249. finalize(() => loading.dismiss())
  250. ).subscribe(async data => {
  251. if (JSON.parse(data.data).code == 1) {
  252. const toast = await this.toastCtrl.create({
  253. message: JSON.parse(data.data).msg,
  254. duration: 1000,
  255. position: 'top'
  256. });
  257. await toast.present();
  258. reject()
  259. } else if (JSON.parse(data.data).code == 0) {
  260. resolve(JSON.parse(data.data))
  261. }
  262. // this.storage.set('sample-table-data', data.data);
  263. // this.router.navigateByUrl('/sample-table');
  264. }, async err => {
  265. console.log(err);
  266. const toast = await this.toastCtrl.create({
  267. message: '查询失败',
  268. duration: 1000,
  269. position: 'top'
  270. });
  271. await toast.present();
  272. });
  273. return;
  274. })
  275. }
  276. // 获得采购合同列表
  277. async getContractTableData(form: object): Promise<any> {
  278. const token = await this.getToken();
  279. const loading = await this.loadingCtrl.create();
  280. await loading.present();
  281. this.nativeHttp.setDataSerializer('json');
  282. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  283. return new Promise((resolve, reject) => {
  284. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/search/supplier/contract/mobile/page`,
  285. form,
  286. headers)).pipe(
  287. finalize(() => loading.dismiss())
  288. ).subscribe(async data => {
  289. if (JSON.parse(data.data).code == 1) {
  290. const toast = await this.toastCtrl.create({
  291. message: JSON.parse(data.data).msg,
  292. duration: 1000,
  293. position: 'top'
  294. });
  295. await toast.present();
  296. reject()
  297. } else if (JSON.parse(data.data).code == 0) {
  298. resolve(JSON.parse(data.data))
  299. }
  300. }, async err => {
  301. console.log(err);
  302. const toast = await this.toastCtrl.create({
  303. message: '查询失败',
  304. duration: 1000,
  305. position: 'top'
  306. });
  307. await toast.present();
  308. });
  309. return;
  310. })
  311. }
  312. // 获取样品单详情
  313. // tslint:disable-next-line:ban-types
  314. async getSampleDetail(sdId: Number): Promise<any> {
  315. const token = await this.getToken();
  316. const loading = await this.loadingCtrl.create();
  317. await loading.present();
  318. this.nativeHttp.setDataSerializer('json');
  319. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  320. return new Promise((resolve, reject) => {
  321. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/samples/mobile/${sdId}`, {},
  322. headers)).pipe(
  323. finalize(() => loading.dismiss())
  324. ).subscribe(async data => {
  325. resolve(data.data);
  326. }, async err => {
  327. console.log(err);
  328. const toast = await this.toastCtrl.create({
  329. message: '查询失败',
  330. duration: 1000,
  331. position: 'top'
  332. });
  333. await toast.present();
  334. });
  335. });
  336. }
  337. // 获取样品单QA详情
  338. async getSampleQAlog(sdpId: Number): Promise<any> {
  339. const token = await this.getToken();
  340. this.nativeHttp.setDataSerializer('json');
  341. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  342. return new Promise((resolve, reject) => {
  343. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/samples/mobile/qalog/${sdpId}`, {},
  344. headers)).pipe(
  345. finalize(() => {})
  346. ).subscribe(async data => {
  347. resolve(data.data);
  348. }, async err => {
  349. console.log(err);
  350. const toast = await this.toastCtrl.create({
  351. message: '查询失败',
  352. duration: 1000,
  353. position: 'top'
  354. });
  355. await toast.present();
  356. });
  357. });
  358. }
  359. // 样品单保存(添加QA日志)
  360. async saveSampleDetail(form: any): Promise<any> {
  361. const token = await this.getToken();
  362. const loading = await this.loadingCtrl.create();
  363. await loading.present();
  364. this.nativeHttp.setDataSerializer('urlencoded');
  365. // let headers = new Headers({
  366. // 'Authorization': `Bearer ${token}`,
  367. // 'enctype': 'multipart/form-data; boundary=----WebKitFormBoundaryuL67FWkv1CA'
  368. // })
  369. const header = { Authorization: `Bearer ${token}` };
  370. return new Promise((resolve, reject) => {
  371. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/samples/mobile/qalog`, form,
  372. header)).pipe(
  373. finalize(() => loading.dismiss())
  374. ).subscribe(async data => {
  375. let message = '';
  376. if (JSON.parse(data.data).code == 1) {
  377. message = JSON.parse(data.data).msg;
  378. resolve([]);
  379. } else if (JSON.parse(data.data).code == 0) {
  380. message = '保存成功';
  381. resolve(data.data);
  382. }
  383. const toast = await this.toastCtrl.create({
  384. message: message,
  385. duration: 1000,
  386. position: 'top'
  387. });
  388. await toast.present();
  389. }, async err => {
  390. console.log(err);
  391. const toast = await this.toastCtrl.create({
  392. message: '保存失败',
  393. duration: 1000,
  394. position: 'top'
  395. });
  396. await toast.present();
  397. });
  398. });
  399. }
  400. // 删除qa日志
  401. async deleteSampleQa(id: any): Promise<any> {
  402. const token = await this.getToken();
  403. const loading = await this.loadingCtrl.create();
  404. await loading.present();
  405. const header = { Authorization: `Bearer ${token}` };
  406. return new Promise((resolve, reject) => {
  407. from(this.nativeHttp.delete(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog/${id}`, {},
  408. header)).pipe(
  409. finalize(() => loading.dismiss())
  410. ).subscribe(async data => {
  411. if (JSON.parse(data.data).code == 1) {
  412. const toast = await this.toastCtrl.create({
  413. message: JSON.parse(data.data).msg,
  414. duration: 1000,
  415. position: 'top'
  416. });
  417. await toast.present();
  418. }
  419. }, async err => {
  420. console.log(err);
  421. const toast = await this.toastCtrl.create({
  422. message: '操作失败',
  423. duration: 1000,
  424. position: 'top'
  425. });
  426. await toast.present();
  427. });
  428. });
  429. }
  430. // 删除qc日志
  431. async deleteSampleQc(id: any): Promise<any> {
  432. const token = await this.getToken();
  433. const loading = await this.loadingCtrl.create();
  434. await loading.present();
  435. const header = { Authorization: `Bearer ${token}` };
  436. return new Promise((resolve, reject) => {
  437. from(this.nativeHttp.delete(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog/${id}`, {},
  438. header)).pipe(
  439. finalize(() => loading.dismiss())
  440. ).subscribe(async data => {
  441. if (JSON.parse(data.data).code == 1) {
  442. const toast = await this.toastCtrl.create({
  443. message: JSON.parse(data.data).msg,
  444. duration: 1000,
  445. position: 'top'
  446. });
  447. await toast.present();
  448. }
  449. }, async err => {
  450. console.log(err);
  451. const toast = await this.toastCtrl.create({
  452. message: '操作失败',
  453. duration: 1000,
  454. position: 'top'
  455. });
  456. await toast.present();
  457. });
  458. });
  459. }
  460. // 获取采购合同详情
  461. async getContractDetail(sscId: Number): Promise<any> {
  462. const token = await this.getToken();
  463. const loading = await this.loadingCtrl.create();
  464. await loading.present();
  465. this.nativeHttp.setDataSerializer('json');
  466. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  467. return new Promise((resolve, reject) => {
  468. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/purchase/mobile/${sscId}`, {},
  469. headers)).pipe(
  470. finalize(() => loading.dismiss())
  471. ).subscribe(async data => {
  472. resolve(data.data);
  473. }, async err => {
  474. console.log(err);
  475. const toast = await this.toastCtrl.create({
  476. message: '查询失败',
  477. duration: 1000,
  478. position: 'top'
  479. });
  480. await toast.present();
  481. });
  482. });
  483. }
  484. // 保存采购合同qa日志
  485. async contractQAlog(form: any): Promise<any> {
  486. const token = await this.getToken();
  487. const loading = await this.loadingCtrl.create();
  488. await loading.present();
  489. this.nativeHttp.setDataSerializer('urlencoded');
  490. const headers = { Authorization: `Bearer ${token}` };
  491. return new Promise((resolve, reject) => {
  492. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog`, form,
  493. headers)).pipe(
  494. finalize(() => loading.dismiss())
  495. ).subscribe(async data => {
  496. let message = '';
  497. if (JSON.parse(data.data).code == 1) {
  498. message = JSON.parse(data.data).msg;
  499. resolve([]);
  500. } else if (JSON.parse(data.data).code == 0) {
  501. message = '保存成功';
  502. resolve(data.data);
  503. }
  504. const toast = await this.toastCtrl.create({
  505. message,
  506. duration: 1000,
  507. position: 'top'
  508. });
  509. await toast.present();
  510. }, async err => {
  511. console.log(err);
  512. const toast = await this.toastCtrl.create({
  513. message: '保存失败',
  514. duration: 1000,
  515. position: 'top'
  516. });
  517. await toast.present();
  518. });
  519. });
  520. }
  521. // 获取采购合同QA日志
  522. async getQAlog(sscId: any, pId: any): Promise<any> {
  523. const token = await this.getToken();
  524. this.nativeHttp.setDataSerializer('json');
  525. const headers = { Authorization: `Bearer ${token}` };
  526. return new Promise((resolve, reject) => {
  527. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog/${sscId}/${pId}`, {},
  528. headers)).pipe(
  529. finalize(() => { })
  530. ).subscribe(async data => {
  531. resolve(data.data);
  532. }, async err => {
  533. console.log(err);
  534. const toast = await this.toastCtrl.create({
  535. message: '查询失败',
  536. duration: 1000,
  537. position: 'top'
  538. });
  539. await toast.present();
  540. });
  541. });
  542. }
  543. // 获取采购合同QC日志
  544. async getQClog(sscId: any, pId: any): Promise<any> {
  545. const token = await this.getToken();
  546. const headers = { Authorization: `Bearer ${token}` };
  547. return new Promise((resolve, reject) => {
  548. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog/${sscId}/${pId}`, {},
  549. headers)).pipe(
  550. finalize(() => { })
  551. ).subscribe(async data => {
  552. resolve(data.data);
  553. }, async err => {
  554. console.log(err);
  555. const toast = await this.toastCtrl.create({
  556. message: '查询失败',
  557. duration: 1000,
  558. position: 'top'
  559. });
  560. await toast.present();
  561. });
  562. });
  563. }
  564. // 获取入库详情
  565. async getStoreDetail(sscId: number, pId: number): Promise<any> {
  566. const token = await this.getToken();
  567. const loading = await this.loadingCtrl.create();
  568. await loading.present();
  569. this.nativeHttp.setDataSerializer('json');
  570. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  571. return new Promise((resolve, reject) => {
  572. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/enterStore/mobile/detail?sscId=${sscId}&pId=${pId}`, {},
  573. headers)).pipe(
  574. finalize(() => loading.dismiss())
  575. ).subscribe(async data => {
  576. if (data.data === null) {
  577. const toast = await this.toastCtrl.create({
  578. message: '无数据',
  579. duration: 1000,
  580. position: 'top'
  581. });
  582. await toast.present();
  583. resolve([]);
  584. }
  585. resolve(data.data);
  586. }, async err => {
  587. console.log(err);
  588. const toast = await this.toastCtrl.create({
  589. message: '查询失败',
  590. duration: 1000,
  591. position: 'top'
  592. });
  593. await toast.present();
  594. });
  595. });
  596. }
  597. // 获取仓库样品
  598. async getStoreSampleDetail(code: string): Promise<any> {
  599. const token = await this.getToken();
  600. const loading = await this.loadingCtrl.create();
  601. await loading.present();
  602. this.nativeHttp.setDataSerializer('json');
  603. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  604. return new Promise((resolve, reject) => {
  605. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/code?code=${code}`, {},
  606. headers)).pipe(
  607. finalize(() => loading.dismiss())
  608. ).subscribe(async data => {
  609. if (JSON.parse(data.data).code === 1) {
  610. const toast = await this.toastCtrl.create({
  611. message: JSON.parse(data.data).msg,
  612. duration: 1000,
  613. position: 'top'
  614. });
  615. await toast.present();
  616. resolve([]);
  617. }
  618. resolve(data.data);
  619. }, async err => {
  620. console.log(err);
  621. const toast = await this.toastCtrl.create({
  622. message: '查询失败',
  623. duration: 1000,
  624. position: 'top'
  625. });
  626. await toast.present();
  627. });
  628. });
  629. }
  630. // 生成入库单
  631. async saveStoreDetail(list: Array<[]>): Promise<any> {
  632. const token = await this.getToken();
  633. const loading = await this.loadingCtrl.create();
  634. await loading.present();
  635. this.nativeHttp.setDataSerializer('json');
  636. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  637. return new Promise((resolve, reject) => {
  638. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/enterStore/mobile/`, list,
  639. headers)).pipe(
  640. finalize(() => loading.dismiss())
  641. ).subscribe(async data => {
  642. let message = '';
  643. if (JSON.parse(data.data).code === 0) {
  644. message = `保存成功,入库单号为${JSON.parse(data.data).data}`;
  645. } else if (JSON.parse(data.data).code === 1) {
  646. message = JSON.parse(data.data).msg;
  647. }
  648. const alert = await this.alertController.create({
  649. // header: 'Confirm!',
  650. message,
  651. buttons: [
  652. {
  653. text: '确定',
  654. role: 'cancel',
  655. cssClass: 'secondary',
  656. handler: (blah) => {
  657. }
  658. }
  659. ]
  660. });
  661. await alert.present();
  662. resolve(data.data);
  663. }, async err => {
  664. console.log(err);
  665. const toast = await this.toastCtrl.create({
  666. message: '保存失败',
  667. duration: 1000,
  668. position: 'top'
  669. });
  670. await toast.present();
  671. });
  672. });
  673. }
  674. // 获取货架列表
  675. async getStoreSampleList(current: number, size: number): Promise<any> {
  676. const token = await this.getToken();
  677. const loading = await this.loadingCtrl.create();
  678. await loading.present();
  679. this.nativeHttp.setDataSerializer('json');
  680. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  681. return new Promise((resolve, reject) => {
  682. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile?${current}&${size}`, {},
  683. headers)).pipe(
  684. finalize(() => loading.dismiss())
  685. ).subscribe(async data => {
  686. if (data.data === null || JSON.parse(data.data).data.records == null) {
  687. const toast = await this.toastCtrl.create({
  688. message: '无数据',
  689. duration: 1000,
  690. position: 'top'
  691. });
  692. await toast.present();
  693. resolve([]);
  694. }
  695. resolve(JSON.parse(data.data).data.records);
  696. }, async err => {
  697. console.log(err);
  698. const toast = await this.toastCtrl.create({
  699. message: '查询失败',
  700. duration: 1000,
  701. position: 'top'
  702. });
  703. await toast.present();
  704. });
  705. });
  706. }
  707. // 货架借出销毁
  708. async changeShelf(list: object): Promise<any> {
  709. const token = await this.getToken();
  710. const loading = await this.loadingCtrl.create();
  711. await loading.present();
  712. this.nativeHttp.setDataSerializer('json');
  713. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  714. return new Promise((resolve, reject) => {
  715. from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/shelf/mobile`, list,
  716. headers)).pipe(
  717. finalize(() => loading.dismiss())
  718. ).subscribe(async data => {
  719. let message = '';
  720. if (JSON.parse(data.data).code == 0) {
  721. message = '操作成功';
  722. } else if (JSON.parse(data.data).code == 1) {
  723. message = JSON.parse(data.data).msg;
  724. }
  725. const alert = await this.alertController.create({
  726. // header: 'Confirm!',
  727. message,
  728. buttons: [
  729. {
  730. text: '确定',
  731. role: 'cancel',
  732. cssClass: 'secondary',
  733. handler: (blah) => {
  734. }
  735. }
  736. ]
  737. });
  738. await alert.present();
  739. resolve(data.data);
  740. }, async err => {
  741. console.log(err);
  742. const toast = await this.toastCtrl.create({
  743. message: '查询失败',
  744. duration: 1000,
  745. position: 'top'
  746. });
  747. await toast.present();
  748. });
  749. });
  750. }
  751. // 货架借出
  752. async changeShelfLend(code: string): Promise<any> {
  753. const token = await this.getToken();
  754. const loading = await this.loadingCtrl.create();
  755. await loading.present();
  756. const headers = { Authorization: `Bearer ${token}` };
  757. return new Promise((resolve, reject) => {
  758. from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/lend?code=${code}`, {},
  759. headers)).pipe(
  760. finalize(() => loading.dismiss())
  761. ).subscribe(async data => {
  762. console.log(data)
  763. let message = '';
  764. if (JSON.parse(data.data).code == 0) {
  765. message = '操作成功';
  766. } else if (JSON.parse(data.data).code == 1) {
  767. message = JSON.parse(data.data).msg;
  768. }
  769. const alert = await this.alertController.create({
  770. // header: 'Confirm!',
  771. message,
  772. buttons: [
  773. {
  774. text: '确定',
  775. role: 'cancel',
  776. cssClass: 'secondary',
  777. handler: (blah) => {
  778. }
  779. }
  780. ]
  781. });
  782. await alert.present();
  783. resolve(data.data);
  784. }, async err => {
  785. console.log(err);
  786. const toast = await this.toastCtrl.create({
  787. message: '查询失败',
  788. duration: 1000,
  789. position: 'top'
  790. });
  791. await toast.present();
  792. });
  793. });
  794. }
  795. // 生成条形码
  796. async createBarCode(code: string): Promise<any> {
  797. const token = await this.getToken();
  798. const loading = await this.loadingCtrl.create();
  799. await loading.present();
  800. this.nativeHttp.setDataSerializer('json');
  801. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  802. return new Promise((resolve, reject) => {
  803. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/12`, {},
  804. headers)).pipe(
  805. finalize(() => loading.dismiss())
  806. ).subscribe(async data => {
  807. resolve(data);
  808. }, async err => {
  809. const toast = await this.toastCtrl.create({
  810. message: '查询失败',
  811. duration: 1000,
  812. position: 'top'
  813. });
  814. await toast.present();
  815. });
  816. });
  817. }
  818. // 货架货号绑定
  819. async shelveBinding(list: Object): Promise<any> {
  820. const token = await this.getToken();
  821. const loading = await this.loadingCtrl.create();
  822. await loading.present();
  823. this.nativeHttp.setDataSerializer('json');
  824. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  825. return new Promise((resolve, reject) => {
  826. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/bind/sample`, list,
  827. headers)).pipe(
  828. finalize(() => loading.dismiss())
  829. ).subscribe(async data => {
  830. let message = '';
  831. if (JSON.parse(data.data).code == 0) {
  832. message = '绑定成功';
  833. } else if (JSON.parse(data.data).code == 1) {
  834. message = JSON.parse(data.data).msg;
  835. }
  836. const toast = await this.toastCtrl.create({
  837. message,
  838. duration: 1000,
  839. position: 'top'
  840. });
  841. await toast.present();
  842. resolve(data);
  843. }, async err => {
  844. console.log(err);
  845. const toast = await this.toastCtrl.create({
  846. message: '绑定失败',
  847. duration: 1000,
  848. position: 'top'
  849. });
  850. await toast.present();
  851. });
  852. });
  853. }
  854. // 获取待验货物列表
  855. async getStorePendingList(current: number, size: number): Promise<any> {
  856. const token = await this.getToken();
  857. const loading = await this.loadingCtrl.create();
  858. await loading.present();
  859. this.nativeHttp.setDataSerializer('json');
  860. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  861. return new Promise((resolve, reject) => {
  862. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/Pending?${current}&${size}`, {},
  863. headers)).pipe(
  864. finalize(() => loading.dismiss())
  865. ).subscribe(async data => {
  866. if (data.data === null || JSON.parse(data.data).data.records == null) {
  867. const toast = await this.toastCtrl.create({
  868. message: '无数据',
  869. duration: 1000,
  870. position: 'top'
  871. });
  872. await toast.present();
  873. resolve([]);
  874. }
  875. resolve(JSON.parse(data.data).data.records);
  876. }, async err => {
  877. console.log(err);
  878. const toast = await this.toastCtrl.create({
  879. message: '查询失败',
  880. duration: 1000,
  881. position: 'top'
  882. });
  883. await toast.present();
  884. });
  885. });
  886. }
  887. // 获取待备样列表
  888. async getStoreSamplePendingList(current: number, size: number): Promise<any> {
  889. const token = await this.getToken();
  890. const loading = await this.loadingCtrl.create();
  891. await loading.present();
  892. this.nativeHttp.setDataSerializer('json');
  893. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  894. return new Promise((resolve, reject) => {
  895. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/pending?${current}&${size}`, {},
  896. headers)).pipe(
  897. finalize(() => loading.dismiss())
  898. ).subscribe(async data => {
  899. if (data.data === null || JSON.parse(data.data).data.records == null) {
  900. const toast = await this.toastCtrl.create({
  901. message: '无数据',
  902. duration: 1000,
  903. position: 'top'
  904. });
  905. await toast.present();
  906. resolve([]);
  907. }
  908. resolve(JSON.parse(data.data).data.records);
  909. }, async err => {
  910. console.log(err);
  911. const toast = await this.toastCtrl.create({
  912. message: '查询失败',
  913. duration: 1000,
  914. position: 'top'
  915. });
  916. await toast.present();
  917. });
  918. });
  919. }
  920. // 获取待备货列表
  921. async getWarehouseManagePendingList(current: number, size: number): Promise<any> {
  922. const token = await this.getToken();
  923. const loading = await this.loadingCtrl.create();
  924. await loading.present();
  925. this.nativeHttp.setDataSerializer('json');
  926. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  927. return new Promise((resolve, reject) => {
  928. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/warehouse/mobile/pending?${current}&${size}`, {},
  929. headers)).pipe(
  930. finalize(() => loading.dismiss())
  931. ).subscribe(async data => {
  932. console.log(data)
  933. if (data.data === null || JSON.parse(data.data).data.records == null) {
  934. const toast = await this.toastCtrl.create({
  935. message: '无数据',
  936. duration: 1000,
  937. position: 'top'
  938. });
  939. await toast.present();
  940. resolve([]);
  941. } else {
  942. resolve(JSON.parse(data.data).data.records);
  943. }
  944. }, async err => {
  945. console.log(err);
  946. const toast = await this.toastCtrl.create({
  947. message: '查询失败',
  948. duration: 1000,
  949. position: 'top'
  950. });
  951. await toast.present();
  952. });
  953. });
  954. }
  955. // 备货完成
  956. async prepareGoods(sscId: any, pId: any) {
  957. const token = await this.getToken();
  958. const loading = await this.loadingCtrl.create();
  959. await loading.present();
  960. this.nativeHttp.setDataSerializer('json');
  961. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  962. return new Promise((resolve, reject) => {
  963. from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/warehouse/mobile/prepare?sscId=${sscId}&pId=${pId}`, {},
  964. headers)).pipe(
  965. finalize(() => loading.dismiss())
  966. ).subscribe(async data => {
  967. let message = '';
  968. if (JSON.parse(data.data).code === 0) {
  969. message = `备货完成`;
  970. } else if (JSON.parse(data.data).code === 1) {
  971. message = JSON.parse(data.data).msg;
  972. }
  973. const alert = await this.alertController.create({
  974. // header: 'Confirm!',
  975. message: message,
  976. buttons: [
  977. {
  978. text: '确定',
  979. role: 'cancel',
  980. cssClass: 'secondary',
  981. handler: (blah) => {
  982. }
  983. }
  984. ]
  985. });
  986. await alert.present();
  987. resolve(data.data);
  988. }, async err => {
  989. console.log(err);
  990. const toast = await this.toastCtrl.create({
  991. message: '保存失败',
  992. duration: 1000,
  993. position: 'top'
  994. });
  995. await toast.present();
  996. });
  997. });
  998. }
  999. // 获取QC验货初检报告列表
  1000. async getQCList(current: number, size: number): Promise<any> {
  1001. const token = await this.getToken();
  1002. const loading = await this.loadingCtrl.create();
  1003. await loading.present();
  1004. this.nativeHttp.setDataSerializer('json');
  1005. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  1006. return new Promise((resolve, reject) => {
  1007. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile?${current}&${size}`, {},
  1008. headers)).pipe(
  1009. finalize(() => loading.dismiss())
  1010. ).subscribe(async data => {
  1011. if (data.data === null || JSON.parse(data.data).data.records == null) {
  1012. const toast = await this.toastCtrl.create({
  1013. message: '无数据',
  1014. duration: 1000,
  1015. position: 'top'
  1016. });
  1017. await toast.present();
  1018. resolve([]);
  1019. }
  1020. resolve(JSON.parse(data.data).data.records);
  1021. }, async err => {
  1022. console.log(err);
  1023. const toast = await this.toastCtrl.create({
  1024. message: '查询失败',
  1025. duration: 1000,
  1026. position: 'top'
  1027. });
  1028. await toast.present();
  1029. });
  1030. });
  1031. }
  1032. // 获取QC验货初检报告详情
  1033. async getQCDetail(sscId: number, pId: number): Promise<any> {
  1034. const token = await this.getToken();
  1035. const loading = await this.loadingCtrl.create();
  1036. await loading.present();
  1037. this.nativeHttp.setDataSerializer('json');
  1038. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  1039. return new Promise((resolve, reject) => {
  1040. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/detail?sscId=${sscId}&pId=${pId}`, {},
  1041. headers)).pipe(
  1042. finalize(() => loading.dismiss())
  1043. ).subscribe(async data => {
  1044. let message = '';
  1045. if (JSON.parse(data.data).code == 0) {
  1046. resolve(JSON.parse(data.data).data);
  1047. } else if (JSON.parse(data.data).code == 1) {
  1048. message = JSON.parse(data.data).msg;
  1049. const toast = await this.toastCtrl.create({
  1050. message,
  1051. duration: 1000,
  1052. position: 'top'
  1053. });
  1054. await toast.present();
  1055. }
  1056. }, async err => {
  1057. console.log(err);
  1058. const toast = await this.toastCtrl.create({
  1059. message: '查询失败',
  1060. duration: 1000,
  1061. position: 'top'
  1062. });
  1063. await toast.present();
  1064. });
  1065. });
  1066. }
  1067. // 生成QC验货初检报告
  1068. async createQC(form: any): Promise<any> {
  1069. const token = await this.getToken();
  1070. const loading = await this.loadingCtrl.create();
  1071. await loading.present();
  1072. this.nativeHttp.setDataSerializer('json');
  1073. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  1074. return new Promise((resolve, reject) => {
  1075. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qc/mobile`, form,
  1076. headers)).pipe(
  1077. finalize(() => loading.dismiss())
  1078. ).subscribe(async data => {
  1079. if (JSON.parse(data.data).msg === 'success') {
  1080. const alert = await this.alertController.create({
  1081. // header: 'Confirm!',
  1082. message: `生成成功,初检报告编号${JSON.parse(data.data).data}`,
  1083. buttons: [
  1084. {
  1085. text: '确定',
  1086. role: 'cancel',
  1087. cssClass: 'secondary',
  1088. handler: (blah) => {
  1089. }
  1090. }
  1091. ]
  1092. });
  1093. await alert.present();
  1094. }
  1095. resolve(JSON.parse(data.data));
  1096. }, async err => {
  1097. console.log(err);
  1098. const toast = await this.toastCtrl.create({
  1099. message: '生成失败',
  1100. duration: 1000,
  1101. position: 'top'
  1102. });
  1103. await toast.present();
  1104. });
  1105. });
  1106. }
  1107. // 添加qc日志
  1108. async addQClog(form: any): Promise<any> {
  1109. const token = await this.getToken();
  1110. const loading = await this.loadingCtrl.create();
  1111. await loading.present();
  1112. this.nativeHttp.setDataSerializer('urlencoded');
  1113. const headers = { Authorization: `Bearer ${token}` };
  1114. return new Promise((resolve, reject) => {
  1115. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog`, form,
  1116. headers)).pipe(
  1117. finalize(() => loading.dismiss())
  1118. ).subscribe(async data => {
  1119. let message = '';
  1120. if (JSON.parse(data.data).code == 1) {
  1121. message = JSON.parse(data.data).msg;
  1122. resolve([]);
  1123. } else if (JSON.parse(data.data).code == 0) {
  1124. message = '添加成功';
  1125. resolve(JSON.parse(data.data));
  1126. }
  1127. const toast = await this.toastCtrl.create({
  1128. message,
  1129. duration: 1000,
  1130. position: 'top'
  1131. });
  1132. await toast.present();
  1133. }, async err => {
  1134. console.log(err);
  1135. const toast = await this.toastCtrl.create({
  1136. message: '添加失败',
  1137. duration: 1000,
  1138. position: 'top'
  1139. });
  1140. await toast.present();
  1141. });
  1142. });
  1143. }
  1144. setUsername(username: string): Promise<any> {
  1145. return this.storage.set('username', username);
  1146. }
  1147. getUsername(): Promise<string> {
  1148. return this.storage.get('username').then((value) => {
  1149. return value;
  1150. });
  1151. }
  1152. isLoggedIn(): Promise<boolean> {
  1153. return this.storage.get(this.HAS_LOGGED_IN).then((value) => {
  1154. return value === true;
  1155. });
  1156. }
  1157. // checkHasSeenTutorial(): Promise<string> {
  1158. // return this.storage.get(this.HAS_SEEN_TUTORIAL).then((value) => {
  1159. // return value;
  1160. // });
  1161. // }
  1162. }