user-data.ts 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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.prod';
  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.post(`${environment.APP_SERVE_URL}/production/sample/factory/pCode`,
  174. data,
  175. headers)).pipe(
  176. finalize(() => { })
  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(() => { })
  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. // let loading = await this.loadingCtrl.create();
  341. // await loading.present();
  342. this.nativeHttp.setDataSerializer('json');
  343. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  344. return new Promise((resolve, reject) => {
  345. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/samples/mobile/qalog/${sdpId}`, {},
  346. headers)).pipe(
  347. finalize(() => { })
  348. ).subscribe(async data => {
  349. resolve(data.data);
  350. }, async err => {
  351. console.log(err);
  352. const toast = await this.toastCtrl.create({
  353. message: '查询失败',
  354. duration: 1000,
  355. position: 'top'
  356. });
  357. await toast.present();
  358. });
  359. });
  360. }
  361. // 样品单保存(添加QA日志)
  362. async saveSampleDetail(form: any): Promise<any> {
  363. const token = await this.getToken();
  364. const loading = await this.loadingCtrl.create();
  365. await loading.present();
  366. this.nativeHttp.setDataSerializer('urlencoded');
  367. // let headers = new Headers({
  368. // 'Authorization': `Bearer ${token}`,
  369. // 'enctype': 'multipart/form-data; boundary=----WebKitFormBoundaryuL67FWkv1CA'
  370. // })
  371. const header = { Authorization: `Bearer ${token}` };
  372. return new Promise((resolve, reject) => {
  373. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/samples/mobile/qalog`, form,
  374. header)).pipe(
  375. finalize(() => loading.dismiss())
  376. ).subscribe(async data => {
  377. let message = '';
  378. if (JSON.parse(data.data).code == 1) {
  379. message = JSON.parse(data.data).msg;
  380. resolve([]);
  381. } else if (JSON.parse(data.data).code == 0) {
  382. message = '保存成功';
  383. resolve(data.data);
  384. }
  385. const toast = await this.toastCtrl.create({
  386. message: message,
  387. duration: 1000,
  388. position: 'top'
  389. });
  390. await toast.present();
  391. }, async err => {
  392. console.log(err);
  393. const toast = await this.toastCtrl.create({
  394. message: '保存失败',
  395. duration: 1000,
  396. position: 'top'
  397. });
  398. await toast.present();
  399. });
  400. });
  401. }
  402. // 删除qa日志
  403. async deleteSampleQa(id: any): Promise<any> {
  404. const token = await this.getToken();
  405. const loading = await this.loadingCtrl.create();
  406. await loading.present();
  407. const header = { Authorization: `Bearer ${token}` };
  408. return new Promise((resolve, reject) => {
  409. from(this.nativeHttp.delete(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog/${id}`, {},
  410. header)).pipe(
  411. finalize(() => loading.dismiss())
  412. ).subscribe(async data => {
  413. if (JSON.parse(data.data).code == 1) {
  414. const toast = await this.toastCtrl.create({
  415. message: JSON.parse(data.data).msg,
  416. duration: 1000,
  417. position: 'top'
  418. });
  419. await toast.present();
  420. }
  421. }, async err => {
  422. console.log(err);
  423. const toast = await this.toastCtrl.create({
  424. message: '操作失败',
  425. duration: 1000,
  426. position: 'top'
  427. });
  428. await toast.present();
  429. });
  430. });
  431. }
  432. // 删除qc日志
  433. async deleteSampleQc(id: any): Promise<any> {
  434. const token = await this.getToken();
  435. const loading = await this.loadingCtrl.create();
  436. await loading.present();
  437. const header = { Authorization: `Bearer ${token}` };
  438. return new Promise((resolve, reject) => {
  439. from(this.nativeHttp.delete(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog/${id}`, {},
  440. header)).pipe(
  441. finalize(() => loading.dismiss())
  442. ).subscribe(async data => {
  443. if (JSON.parse(data.data).code == 1) {
  444. const toast = await this.toastCtrl.create({
  445. message: JSON.parse(data.data).msg,
  446. duration: 1000,
  447. position: 'top'
  448. });
  449. await toast.present();
  450. }
  451. }, async err => {
  452. console.log(err);
  453. const toast = await this.toastCtrl.create({
  454. message: '操作失败',
  455. duration: 1000,
  456. position: 'top'
  457. });
  458. await toast.present();
  459. });
  460. });
  461. }
  462. // 获取采购合同详情
  463. async getContractDetail(sscId: Number): Promise<any> {
  464. const token = await this.getToken();
  465. const loading = await this.loadingCtrl.create();
  466. await loading.present();
  467. this.nativeHttp.setDataSerializer('json');
  468. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  469. return new Promise((resolve, reject) => {
  470. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/purchase/mobile/${sscId}`, {},
  471. headers)).pipe(
  472. finalize(() => loading.dismiss())
  473. ).subscribe(async data => {
  474. resolve(data.data);
  475. }, async err => {
  476. console.log(err);
  477. const toast = await this.toastCtrl.create({
  478. message: '查询失败',
  479. duration: 1000,
  480. position: 'top'
  481. });
  482. await toast.present();
  483. });
  484. });
  485. }
  486. // 保存采购合同qa日志
  487. async contractQAlog(form: any): Promise<any> {
  488. const token = await this.getToken();
  489. const loading = await this.loadingCtrl.create();
  490. await loading.present();
  491. this.nativeHttp.setDataSerializer('urlencoded');
  492. const headers = { Authorization: `Bearer ${token}` };
  493. return new Promise((resolve, reject) => {
  494. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog`, form,
  495. headers)).pipe(
  496. finalize(() => loading.dismiss())
  497. ).subscribe(async data => {
  498. let message = '';
  499. if (JSON.parse(data.data).code == 1) {
  500. message = JSON.parse(data.data).msg;
  501. resolve([]);
  502. } else if (JSON.parse(data.data).code == 0) {
  503. message = '保存成功';
  504. resolve(data.data);
  505. }
  506. const toast = await this.toastCtrl.create({
  507. message,
  508. duration: 1000,
  509. position: 'top'
  510. });
  511. await toast.present();
  512. }, async err => {
  513. console.log(err);
  514. const toast = await this.toastCtrl.create({
  515. message: '保存失败',
  516. duration: 1000,
  517. position: 'top'
  518. });
  519. await toast.present();
  520. });
  521. });
  522. }
  523. // 获取采购合同QA日志
  524. async getQAlog(sscId: any, pId: any): Promise<any> {
  525. const token = await this.getToken();
  526. this.nativeHttp.setDataSerializer('json');
  527. const headers = { Authorization: `Bearer ${token}` };
  528. return new Promise((resolve, reject) => {
  529. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog/${sscId}/${pId}`, {},
  530. headers)).pipe(
  531. finalize(() => { })
  532. ).subscribe(async data => {
  533. resolve(data.data);
  534. }, async err => {
  535. console.log(err);
  536. const toast = await this.toastCtrl.create({
  537. message: '查询失败',
  538. duration: 1000,
  539. position: 'top'
  540. });
  541. await toast.present();
  542. });
  543. });
  544. }
  545. // 获取采购合同QC日志
  546. async getQClog(sscId: any, pId: any): Promise<any> {
  547. const token = await this.getToken();
  548. const headers = { Authorization: `Bearer ${token}` };
  549. return new Promise((resolve, reject) => {
  550. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog/${sscId}/${pId}`, {},
  551. headers)).pipe(
  552. finalize(() => { })
  553. ).subscribe(async data => {
  554. resolve(data.data);
  555. }, async err => {
  556. console.log(err);
  557. const toast = await this.toastCtrl.create({
  558. message: '查询失败',
  559. duration: 1000,
  560. position: 'top'
  561. });
  562. await toast.present();
  563. });
  564. });
  565. }
  566. // 获取入库详情
  567. async getStoreDetail(sscId: number, pId: number): Promise<any> {
  568. const token = await this.getToken();
  569. const loading = await this.loadingCtrl.create();
  570. await loading.present();
  571. this.nativeHttp.setDataSerializer('json');
  572. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  573. return new Promise((resolve, reject) => {
  574. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/enterStore/mobile/detail?sscId=${sscId}&pId=${pId}`, {},
  575. headers)).pipe(
  576. finalize(() => loading.dismiss())
  577. ).subscribe(async data => {
  578. if (data.data === null) {
  579. const toast = await this.toastCtrl.create({
  580. message: '无数据',
  581. duration: 1000,
  582. position: 'top'
  583. });
  584. await toast.present();
  585. resolve([]);
  586. }
  587. resolve(data.data);
  588. }, async err => {
  589. console.log(err);
  590. const toast = await this.toastCtrl.create({
  591. message: '查询失败',
  592. duration: 1000,
  593. position: 'top'
  594. });
  595. await toast.present();
  596. });
  597. });
  598. }
  599. // 获取仓库样品
  600. async getStoreSampleDetail(code: string): Promise<any> {
  601. const token = await this.getToken();
  602. const loading = await this.loadingCtrl.create();
  603. await loading.present();
  604. this.nativeHttp.setDataSerializer('json');
  605. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  606. return new Promise((resolve, reject) => {
  607. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/code?code=${code}`, {},
  608. headers)).pipe(
  609. finalize(() => loading.dismiss())
  610. ).subscribe(async data => {
  611. if (JSON.parse(data.data).code === 1) {
  612. const toast = await this.toastCtrl.create({
  613. message: JSON.parse(data.data).msg,
  614. duration: 1000,
  615. position: 'top'
  616. });
  617. await toast.present();
  618. resolve([]);
  619. }
  620. resolve(data.data);
  621. }, async err => {
  622. console.log(err);
  623. const toast = await this.toastCtrl.create({
  624. message: '查询失败',
  625. duration: 1000,
  626. position: 'top'
  627. });
  628. await toast.present();
  629. });
  630. });
  631. }
  632. // 生成入库单
  633. async saveStoreDetail(list: Array<[]>): Promise<any> {
  634. const token = await this.getToken();
  635. const loading = await this.loadingCtrl.create();
  636. await loading.present();
  637. this.nativeHttp.setDataSerializer('json');
  638. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  639. return new Promise((resolve, reject) => {
  640. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/enterStore/mobile/`, list,
  641. headers)).pipe(
  642. finalize(() => loading.dismiss())
  643. ).subscribe(async data => {
  644. let message = '';
  645. if (JSON.parse(data.data).code === 0) {
  646. message = `保存成功,入库单号为${JSON.parse(data.data).data}`;
  647. } else if (JSON.parse(data.data).code === 1) {
  648. message = JSON.parse(data.data).msg;
  649. }
  650. const alert = await this.alertController.create({
  651. // header: 'Confirm!',
  652. message,
  653. buttons: [
  654. {
  655. text: '确定',
  656. role: 'cancel',
  657. cssClass: 'secondary',
  658. handler: (blah) => {
  659. }
  660. }
  661. ]
  662. });
  663. await alert.present();
  664. resolve(data.data);
  665. }, async err => {
  666. console.log(err);
  667. const toast = await this.toastCtrl.create({
  668. message: '保存失败',
  669. duration: 1000,
  670. position: 'top'
  671. });
  672. await toast.present();
  673. });
  674. });
  675. }
  676. // 获取货架列表
  677. async getStoreSampleList(current: number, size: number): Promise<any> {
  678. const token = await this.getToken();
  679. const loading = await this.loadingCtrl.create();
  680. await loading.present();
  681. this.nativeHttp.setDataSerializer('json');
  682. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  683. return new Promise((resolve, reject) => {
  684. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile?${current}&${size}`, {},
  685. headers)).pipe(
  686. finalize(() => loading.dismiss())
  687. ).subscribe(async data => {
  688. if (data.data === null || JSON.parse(data.data).data.records == null) {
  689. const toast = await this.toastCtrl.create({
  690. message: '无数据',
  691. duration: 1000,
  692. position: 'top'
  693. });
  694. await toast.present();
  695. resolve([]);
  696. }
  697. resolve(JSON.parse(data.data).data.records);
  698. }, async err => {
  699. console.log(err);
  700. const toast = await this.toastCtrl.create({
  701. message: '查询失败',
  702. duration: 1000,
  703. position: 'top'
  704. });
  705. await toast.present();
  706. });
  707. });
  708. }
  709. // 货架借出销毁
  710. async changeShelf(list: object): Promise<any> {
  711. const token = await this.getToken();
  712. const loading = await this.loadingCtrl.create();
  713. await loading.present();
  714. this.nativeHttp.setDataSerializer('json');
  715. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  716. return new Promise((resolve, reject) => {
  717. from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/shelf/mobile`, list,
  718. headers)).pipe(
  719. finalize(() => loading.dismiss())
  720. ).subscribe(async data => {
  721. let message = '';
  722. if (JSON.parse(data.data).code == 0) {
  723. message = '操作成功';
  724. } else if (JSON.parse(data.data).code == 1) {
  725. message = JSON.parse(data.data).msg;
  726. }
  727. const alert = await this.alertController.create({
  728. // header: 'Confirm!',
  729. message,
  730. buttons: [
  731. {
  732. text: '确定',
  733. role: 'cancel',
  734. cssClass: 'secondary',
  735. handler: (blah) => {
  736. }
  737. }
  738. ]
  739. });
  740. await alert.present();
  741. resolve(data.data);
  742. }, async err => {
  743. console.log(err);
  744. const toast = await this.toastCtrl.create({
  745. message: '查询失败',
  746. duration: 1000,
  747. position: 'top'
  748. });
  749. await toast.present();
  750. });
  751. });
  752. }
  753. // 货架借出
  754. async changeShelfLend(code: string): Promise<any> {
  755. const token = await this.getToken();
  756. const loading = await this.loadingCtrl.create();
  757. await loading.present();
  758. const headers = { Authorization: `Bearer ${token}` };
  759. return new Promise((resolve, reject) => {
  760. from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/lend?code=${code}`, {},
  761. headers)).pipe(
  762. finalize(() => loading.dismiss())
  763. ).subscribe(async data => {
  764. console.log(data)
  765. let message = '';
  766. if (JSON.parse(data.data).code == 0) {
  767. message = '操作成功';
  768. } else if (JSON.parse(data.data).code == 1) {
  769. message = JSON.parse(data.data).msg;
  770. }
  771. const alert = await this.alertController.create({
  772. // header: 'Confirm!',
  773. message,
  774. buttons: [
  775. {
  776. text: '确定',
  777. role: 'cancel',
  778. cssClass: 'secondary',
  779. handler: (blah) => {
  780. }
  781. }
  782. ]
  783. });
  784. await alert.present();
  785. resolve(data.data);
  786. }, async err => {
  787. console.log(err);
  788. const toast = await this.toastCtrl.create({
  789. message: '查询失败',
  790. duration: 1000,
  791. position: 'top'
  792. });
  793. await toast.present();
  794. });
  795. });
  796. }
  797. // 生成条形码
  798. async createBarCode(code: string): Promise<any> {
  799. const token = await this.getToken();
  800. const loading = await this.loadingCtrl.create();
  801. await loading.present();
  802. this.nativeHttp.setDataSerializer('json');
  803. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  804. return new Promise((resolve, reject) => {
  805. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/12`, {},
  806. headers)).pipe(
  807. finalize(() => loading.dismiss())
  808. ).subscribe(async data => {
  809. resolve(data);
  810. }, async err => {
  811. const toast = await this.toastCtrl.create({
  812. message: '查询失败',
  813. duration: 1000,
  814. position: 'top'
  815. });
  816. await toast.present();
  817. });
  818. });
  819. }
  820. // 货架货号绑定
  821. async shelveBinding(list: Object): Promise<any> {
  822. const token = await this.getToken();
  823. const loading = await this.loadingCtrl.create();
  824. await loading.present();
  825. this.nativeHttp.setDataSerializer('json');
  826. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  827. return new Promise((resolve, reject) => {
  828. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/bind/sample`, list,
  829. headers)).pipe(
  830. finalize(() => loading.dismiss())
  831. ).subscribe(async data => {
  832. let message = '';
  833. if (JSON.parse(data.data).code == 0) {
  834. message = '绑定成功';
  835. } else if (JSON.parse(data.data).code == 1) {
  836. message = JSON.parse(data.data).msg;
  837. }
  838. const toast = await this.toastCtrl.create({
  839. message,
  840. duration: 1000,
  841. position: 'top'
  842. });
  843. await toast.present();
  844. resolve(data);
  845. }, async err => {
  846. console.log(err);
  847. const toast = await this.toastCtrl.create({
  848. message: '绑定失败',
  849. duration: 1000,
  850. position: 'top'
  851. });
  852. await toast.present();
  853. });
  854. });
  855. }
  856. // 获取待验货物列表
  857. async getStorePendingList(current: number, size: number): Promise<any> {
  858. const token = await this.getToken();
  859. const loading = await this.loadingCtrl.create();
  860. await loading.present();
  861. this.nativeHttp.setDataSerializer('json');
  862. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  863. return new Promise((resolve, reject) => {
  864. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/Pending?${current}&${size}`, {},
  865. headers)).pipe(
  866. finalize(() => loading.dismiss())
  867. ).subscribe(async data => {
  868. if (data.data === null || JSON.parse(data.data).data.records == null) {
  869. const toast = await this.toastCtrl.create({
  870. message: '无数据',
  871. duration: 1000,
  872. position: 'top'
  873. });
  874. await toast.present();
  875. resolve([]);
  876. }
  877. resolve(JSON.parse(data.data).data.records);
  878. }, async err => {
  879. console.log(err);
  880. const toast = await this.toastCtrl.create({
  881. message: '查询失败',
  882. duration: 1000,
  883. position: 'top'
  884. });
  885. await toast.present();
  886. });
  887. });
  888. }
  889. // 获取待备样列表
  890. async getStoreSamplePendingList(current: number, size: number): Promise<any> {
  891. const token = await this.getToken();
  892. const loading = await this.loadingCtrl.create();
  893. await loading.present();
  894. this.nativeHttp.setDataSerializer('json');
  895. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  896. return new Promise((resolve, reject) => {
  897. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/pending?${current}&${size}`, {},
  898. headers)).pipe(
  899. finalize(() => loading.dismiss())
  900. ).subscribe(async data => {
  901. if (data.data === null || JSON.parse(data.data).data.records == null) {
  902. const toast = await this.toastCtrl.create({
  903. message: '无数据',
  904. duration: 1000,
  905. position: 'top'
  906. });
  907. await toast.present();
  908. resolve([]);
  909. }
  910. resolve(JSON.parse(data.data).data.records);
  911. }, async err => {
  912. console.log(err);
  913. const toast = await this.toastCtrl.create({
  914. message: '查询失败',
  915. duration: 1000,
  916. position: 'top'
  917. });
  918. await toast.present();
  919. });
  920. });
  921. }
  922. // 获取待备货列表
  923. async getWarehouseManagePendingList(current: number, size: number): Promise<any> {
  924. const token = await this.getToken();
  925. const loading = await this.loadingCtrl.create();
  926. await loading.present();
  927. this.nativeHttp.setDataSerializer('json');
  928. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  929. return new Promise((resolve, reject) => {
  930. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/warehouse/mobile/pending?${current}&${size}`, {},
  931. headers)).pipe(
  932. finalize(() => loading.dismiss())
  933. ).subscribe(async data => {
  934. console.log(data)
  935. if (data.data === null || JSON.parse(data.data).data.records == null) {
  936. const toast = await this.toastCtrl.create({
  937. message: '无数据',
  938. duration: 1000,
  939. position: 'top'
  940. });
  941. await toast.present();
  942. resolve([]);
  943. } else {
  944. resolve(JSON.parse(data.data).data.records);
  945. }
  946. }, async err => {
  947. console.log(err);
  948. const toast = await this.toastCtrl.create({
  949. message: '查询失败',
  950. duration: 1000,
  951. position: 'top'
  952. });
  953. await toast.present();
  954. });
  955. });
  956. }
  957. // 备货完成
  958. async prepareGoods(sscId: any, pId: any) {
  959. const token = await this.getToken();
  960. const loading = await this.loadingCtrl.create();
  961. await loading.present();
  962. this.nativeHttp.setDataSerializer('json');
  963. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  964. return new Promise((resolve, reject) => {
  965. from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/warehouse/mobile/prepare?sscId=${sscId}&pId=${pId}`, {},
  966. headers)).pipe(
  967. finalize(() => loading.dismiss())
  968. ).subscribe(async data => {
  969. let message = '';
  970. if (JSON.parse(data.data).code === 0) {
  971. message = `备货完成`;
  972. } else if (JSON.parse(data.data).code === 1) {
  973. message = JSON.parse(data.data).msg;
  974. }
  975. const alert = await this.alertController.create({
  976. // header: 'Confirm!',
  977. message: message,
  978. buttons: [
  979. {
  980. text: '确定',
  981. role: 'cancel',
  982. cssClass: 'secondary',
  983. handler: (blah) => {
  984. }
  985. }
  986. ]
  987. });
  988. await alert.present();
  989. resolve(data.data);
  990. }, async err => {
  991. console.log(err);
  992. const toast = await this.toastCtrl.create({
  993. message: '保存失败',
  994. duration: 1000,
  995. position: 'top'
  996. });
  997. await toast.present();
  998. });
  999. });
  1000. }
  1001. // 获取QC验货初检报告列表
  1002. async getQCList(current: number, size: number): Promise<any> {
  1003. const token = await this.getToken();
  1004. const loading = await this.loadingCtrl.create();
  1005. await loading.present();
  1006. this.nativeHttp.setDataSerializer('json');
  1007. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  1008. return new Promise((resolve, reject) => {
  1009. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile?${current}&${size}`, {},
  1010. headers)).pipe(
  1011. finalize(() => loading.dismiss())
  1012. ).subscribe(async data => {
  1013. if (data.data === null || JSON.parse(data.data).data.records == null) {
  1014. const toast = await this.toastCtrl.create({
  1015. message: '无数据',
  1016. duration: 1000,
  1017. position: 'top'
  1018. });
  1019. await toast.present();
  1020. resolve([]);
  1021. }
  1022. resolve(JSON.parse(data.data).data.records);
  1023. }, async err => {
  1024. console.log(err);
  1025. const toast = await this.toastCtrl.create({
  1026. message: '查询失败',
  1027. duration: 1000,
  1028. position: 'top'
  1029. });
  1030. await toast.present();
  1031. });
  1032. });
  1033. }
  1034. // 获取QC验货初检报告详情
  1035. async getQCDetail(sscId: number, pId: number): Promise<any> {
  1036. const token = await this.getToken();
  1037. const loading = await this.loadingCtrl.create();
  1038. await loading.present();
  1039. this.nativeHttp.setDataSerializer('json');
  1040. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  1041. return new Promise((resolve, reject) => {
  1042. from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/detail?sscId=${sscId}&pId=${pId}`, {},
  1043. headers)).pipe(
  1044. finalize(() => loading.dismiss())
  1045. ).subscribe(async data => {
  1046. let message = '';
  1047. if (JSON.parse(data.data).code == 0) {
  1048. resolve(JSON.parse(data.data).data);
  1049. } else if (JSON.parse(data.data).code == 1) {
  1050. message = JSON.parse(data.data).msg;
  1051. const toast = await this.toastCtrl.create({
  1052. message,
  1053. duration: 1000,
  1054. position: 'top'
  1055. });
  1056. await toast.present();
  1057. }
  1058. }, async err => {
  1059. console.log(err);
  1060. const toast = await this.toastCtrl.create({
  1061. message: '查询失败',
  1062. duration: 1000,
  1063. position: 'top'
  1064. });
  1065. await toast.present();
  1066. });
  1067. });
  1068. }
  1069. // 生成QC验货初检报告
  1070. async createQC(form: any): Promise<any> {
  1071. const token = await this.getToken();
  1072. const loading = await this.loadingCtrl.create();
  1073. await loading.present();
  1074. this.nativeHttp.setDataSerializer('json');
  1075. const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
  1076. return new Promise((resolve, reject) => {
  1077. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qc/mobile`, form,
  1078. headers)).pipe(
  1079. finalize(() => loading.dismiss())
  1080. ).subscribe(async data => {
  1081. if (JSON.parse(data.data).msg === 'success') {
  1082. const alert = await this.alertController.create({
  1083. // header: 'Confirm!',
  1084. message: `生成成功,初检报告编号${JSON.parse(data.data).data}`,
  1085. buttons: [
  1086. {
  1087. text: '确定',
  1088. role: 'cancel',
  1089. cssClass: 'secondary',
  1090. handler: (blah) => {
  1091. }
  1092. }
  1093. ]
  1094. });
  1095. await alert.present();
  1096. }
  1097. resolve(JSON.parse(data.data));
  1098. }, async err => {
  1099. console.log(err);
  1100. const toast = await this.toastCtrl.create({
  1101. message: '生成失败',
  1102. duration: 1000,
  1103. position: 'top'
  1104. });
  1105. await toast.present();
  1106. });
  1107. });
  1108. }
  1109. // 添加qc日志
  1110. async addQClog(form: any): Promise<any> {
  1111. const token = await this.getToken();
  1112. const loading = await this.loadingCtrl.create();
  1113. await loading.present();
  1114. this.nativeHttp.setDataSerializer('urlencoded');
  1115. const headers = { Authorization: `Bearer ${token}` };
  1116. return new Promise((resolve, reject) => {
  1117. from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog`, form,
  1118. headers)).pipe(
  1119. finalize(() => loading.dismiss())
  1120. ).subscribe(async data => {
  1121. let message = '';
  1122. if (JSON.parse(data.data).code == 1) {
  1123. message = JSON.parse(data.data).msg;
  1124. resolve([]);
  1125. } else if (JSON.parse(data.data).code == 0) {
  1126. message = '添加成功';
  1127. resolve(JSON.parse(data.data));
  1128. }
  1129. const toast = await this.toastCtrl.create({
  1130. message,
  1131. duration: 1000,
  1132. position: 'top'
  1133. });
  1134. await toast.present();
  1135. }, async err => {
  1136. console.log(err);
  1137. const toast = await this.toastCtrl.create({
  1138. message: '添加失败',
  1139. duration: 1000,
  1140. position: 'top'
  1141. });
  1142. await toast.present();
  1143. });
  1144. });
  1145. }
  1146. setUsername(username: string): Promise<any> {
  1147. return this.storage.set('username', username);
  1148. }
  1149. getUsername(): Promise<string> {
  1150. return this.storage.get('username').then((value) => {
  1151. return value;
  1152. });
  1153. }
  1154. isLoggedIn(): Promise<boolean> {
  1155. return this.storage.get(this.HAS_LOGGED_IN).then((value) => {
  1156. return value === true;
  1157. });
  1158. }
  1159. // checkHasSeenTutorial(): Promise<string> {
  1160. // return this.storage.get(this.HAS_SEEN_TUTORIAL).then((value) => {
  1161. // return value;
  1162. // });
  1163. // }
  1164. }