123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212 |
- import { Injectable } from '@angular/core';
- import { Events, LoadingController, ToastController } from '@ionic/angular';
- import { Storage } from '@ionic/storage';
- import { HTTP } from '@ionic-native/http/ngx';
- import { from } from 'rxjs';
- import { Router } from '@angular/router';
- import { AlertController } from '@ionic/angular';
- import { finalize } from 'rxjs/operators';
- import { queryForm } from './query';
- import { environment } from '../environments/environment.prod';
- @Injectable({
- providedIn: 'root'
- })
- export class UserData {
- // tslint:disable-next-line:variable-name
- _favorites: string[] = [];
- HAS_LOGGED_IN = 'hasLoggedIn';
- HAS_SEEN_TUTORIAL = 'hasSeenTutorial';
- constructor(
- public events: Events,
- private nativeHttp: HTTP,
- private loadingCtrl: LoadingController,
- public alertController: AlertController,
- public storage: Storage,
- public queryForm: queryForm,
- private router: Router,
- private toastCtrl: ToastController
- ) {
- // this.nativeHttp.setDataSerializer('json')
- }
- // hasFavorite(sessionName: string): boolean {
- // return (this._favorites.indexOf(sessionName) > -1);
- // }
- // addFavorite(sessionName: string): void {
- // this._favorites.push(sessionName);
- // }
- // removeFavorite(sessionName: string): void {
- // const index = this._favorites.indexOf(sessionName);
- // if (index > -1) {
- // this._favorites.splice(index, 1);
- // }
- // }
- // 登录
- login(account: string, password: string): Promise<any> {
- return this.storage.set(this.HAS_LOGGED_IN, false).then(async () => {
- const loading = await this.loadingCtrl.create();
- await loading.present();
- // Returns a promise, need to convert with of() to Observable (if want)!
- // this.nativeHttp.setDataSerializer('json')
- // tslint:disable-next-line:max-line-length
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/auth/oauth/token?username=${account}&password=${encodeURIComponent(password)}&grant_type=password&scope=server`,
- {},
- { Authorization: 'Basic cGlnOnBpZw==', TENANT_ID: '1', isToken: 'false', })).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).code == 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- } else {
- this.storage.set('access_token', JSON.parse(data.data).access_token);
- this.storage.set('username', JSON.parse(data.data).username);
- this.storage.set('user_id', JSON.parse(data.data).user_id);
- this.storage.set(this.HAS_LOGGED_IN, true);
- this.router.navigateByUrl('/home');
- return this.events.publish('user:login');
- }
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: err.error + err.url,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- return;
- });
- }
- // signup(username: string): Promise<any> {
- // return this.storage.set(this.HAS_LOGGED_IN, true).then(() => {
- // this.setUsername(username);
- // return this.events.publish('user:signup');
- // });
- // }
- getToken(): Promise<any> {
- return this.storage.get('access_token').then((val) => {
- return val;
- });
- }
- // 获取App menu
- async getAppMenu(): Promise<any> {
- const token = await this.getToken();
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/admin/menu/app`,
- {},
- { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' })).pipe(
- finalize(() => { })
- ).subscribe(async data => {
- // console.log(JSON.parse(data.data))
- resolve(JSON.parse(data.data).data)
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询目录失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- return;
- })
- }
- async logout(): Promise<any> {
- const alert = await this.alertController.create({
- header: '安全退出',
- message: '确定要登出吗',
- buttons: [
- {
- text: '确定',
- role: 'cancel',
- cssClass: 'secondary',
- handler: () => {
- this.router.navigateByUrl('/login');
- return this.storage.remove(this.HAS_LOGGED_IN).then(async () => {
- }).then(() => {
- this.events.publish('user:logout');
- });
- }
- }, {
- text: '取消'
- }
- ]
- });
- await alert.present();
- return this.storage.clear();
- }
- // 开单号扫描
- async ssfCodeScan(data: object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/sample/factory/`,
- data,
- headers)).pipe(
- finalize(() => { })
- ).subscribe(data => {
- this.storage.set('ssfId', JSON.parse(data.data).data.ssfId)
- }, async err => {
- console.log(err)
- let toast = await this.toastCtrl.create({
- message: '获取数据失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- return;
- }
- // 货号扫描
- async pCodeScan(data: object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/sample/factory/pCode`,
- data,
- headers)).pipe(
- finalize(() => { })
- ).subscribe(async data => {
- if (JSON.parse(data.data).code == 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- } else if (JSON.parse(data.data).code == 0) {
- resolve(JSON.parse(data.data).data)
- }
- }, async err => {
- console.log(err)
- let toast = await this.toastCtrl.create({
- message: '获取数据失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- })
- }
- // 新增样品工厂详细
- async saveFactoryDetails(data: object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/sample/factory/details/`,
- data,
- headers)).pipe(
- finalize(() => { })
- ).subscribe(async data => {
- let message = ''
- if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg
- resolve([]);
- } else if (JSON.parse(data.data).code == 0) {
- message = '保存成功'
- resolve(JSON.parse(data.data).data)
- }
- const toast = await this.toastCtrl.create({
- message: message,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }, async err => {
- console.log(err)
- let toast = await this.toastCtrl.create({
- message: '保存失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- })
- }
- // 获取样品单列表
- async getSampleTableData(form: object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/search/samples/mobile/page`,
- form,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).code == 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- reject()
- } else if (JSON.parse(data.data).code == 0) {
- resolve(JSON.parse(data.data))
- }
- // this.storage.set('sample-table-data', data.data);
- // this.router.navigateByUrl('/sample-table');
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- return;
- })
- }
- // 获得采购合同列表
- async getContractTableData(form: object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/search/supplier/contract/mobile/page`,
- form,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).code == 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- reject()
- } else if (JSON.parse(data.data).code == 0) {
- resolve(JSON.parse(data.data))
- }
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- return;
- })
- }
- // 获取样品单详情
- // tslint:disable-next-line:ban-types
- async getSampleDetail(sdId: Number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/samples/mobile/${sdId}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取样品单QA详情
- async getSampleQAlog(sdpId: Number): Promise<any> {
- const token = await this.getToken();
- // let loading = await this.loadingCtrl.create();
- // await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/samples/mobile/qalog/${sdpId}`, {},
- headers)).pipe(
- finalize(() => { })
- ).subscribe(async data => {
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 样品单保存(添加QA日志)
- async saveSampleDetail(form: any): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('urlencoded');
- // let headers = new Headers({
- // 'Authorization': `Bearer ${token}`,
- // 'enctype': 'multipart/form-data; boundary=----WebKitFormBoundaryuL67FWkv1CA'
- // })
- const header = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/production/samples/mobile/qalog`, form,
- header)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- resolve([]);
- } else if (JSON.parse(data.data).code == 0) {
- message = '保存成功';
- resolve(data.data);
- }
- const toast = await this.toastCtrl.create({
- message: message,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '保存失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 删除qa日志
- async deleteSampleQa(id: any): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- const header = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.delete(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog/${id}`, {},
- header)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).code == 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '操作失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 删除qc日志
- async deleteSampleQc(id: any): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- const header = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.delete(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog/${id}`, {},
- header)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).code == 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '操作失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取采购合同详情
- async getContractDetail(sscId: Number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/production/purchase/mobile/${sscId}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 保存采购合同qa日志
- async contractQAlog(form: any): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('urlencoded');
- const headers = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog`, form,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- resolve([]);
- } else if (JSON.parse(data.data).code == 0) {
- message = '保存成功';
- resolve(data.data);
- }
- const toast = await this.toastCtrl.create({
- message,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '保存失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取采购合同QA日志
- async getQAlog(sscId: any, pId: any): Promise<any> {
- const token = await this.getToken();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qa/mobile/qalog/${sscId}/${pId}`, {},
- headers)).pipe(
- finalize(() => { })
- ).subscribe(async data => {
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取采购合同QC日志
- async getQClog(sscId: any, pId: any): Promise<any> {
- const token = await this.getToken();
- const headers = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog/${sscId}/${pId}`, {},
- headers)).pipe(
- finalize(() => { })
- ).subscribe(async data => {
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取入库详情
- async getStoreDetail(sscId: number, pId: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/enterStore/mobile/detail?sscId=${sscId}&pId=${pId}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (data.data === null) {
- const toast = await this.toastCtrl.create({
- message: '无数据',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- }
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取仓库样品
- async getStoreSampleDetail(code: string): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/code?code=${code}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).code === 1) {
- const toast = await this.toastCtrl.create({
- message: JSON.parse(data.data).msg,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- }
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 生成入库单
- async saveStoreDetail(list: Array<[]>): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/enterStore/mobile/`, list,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code === 0) {
- message = `保存成功,入库单号为${JSON.parse(data.data).data}`;
- } else if (JSON.parse(data.data).code === 1) {
- message = JSON.parse(data.data).msg;
- }
- const alert = await this.alertController.create({
- // header: 'Confirm!',
- message,
- buttons: [
- {
- text: '确定',
- role: 'cancel',
- cssClass: 'secondary',
- handler: (blah) => {
- }
- }
- ]
- });
- await alert.present();
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '保存失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取货架列表
- async getStoreSampleList(current: number, size: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile?${current}&${size}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (data.data === null || JSON.parse(data.data).data.records == null) {
- const toast = await this.toastCtrl.create({
- message: '无数据',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- }
- resolve(JSON.parse(data.data).data.records);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 货架借出销毁
- async changeShelf(list: object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/shelf/mobile`, list,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code == 0) {
- message = '操作成功';
- } else if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- }
- const alert = await this.alertController.create({
- // header: 'Confirm!',
- message,
- buttons: [
- {
- text: '确定',
- role: 'cancel',
- cssClass: 'secondary',
- handler: (blah) => {
- }
- }
- ]
- });
- await alert.present();
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 货架借出
- async changeShelfLend(code: string): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- const headers = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/lend?code=${code}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- console.log(data)
- let message = '';
- if (JSON.parse(data.data).code == 0) {
- message = '操作成功';
- } else if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- }
- const alert = await this.alertController.create({
- // header: 'Confirm!',
- message,
- buttons: [
- {
- text: '确定',
- role: 'cancel',
- cssClass: 'secondary',
- handler: (blah) => {
- }
- }
- ]
- });
- await alert.present();
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 生成条形码
- async createBarCode(code: string): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/12`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- resolve(data);
- }, async err => {
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 货架货号绑定
- async shelveBinding(list: Object): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/bind/sample`, list,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code == 0) {
- message = '绑定成功';
- } else if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- }
- const toast = await this.toastCtrl.create({
- message,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve(data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '绑定失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取待验货物列表
- async getStorePendingList(current: number, size: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/Pending?${current}&${size}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (data.data === null || JSON.parse(data.data).data.records == null) {
- const toast = await this.toastCtrl.create({
- message: '无数据',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- }
- resolve(JSON.parse(data.data).data.records);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取待备样列表
- async getStoreSamplePendingList(current: number, size: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/shelf/mobile/pending?${current}&${size}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (data.data === null || JSON.parse(data.data).data.records == null) {
- const toast = await this.toastCtrl.create({
- message: '无数据',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- }
- resolve(JSON.parse(data.data).data.records);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取待备货列表
- async getWarehouseManagePendingList(current: number, size: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/warehouse/mobile/pending?${current}&${size}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- console.log(data)
- if (data.data === null || JSON.parse(data.data).data.records == null) {
- const toast = await this.toastCtrl.create({
- message: '无数据',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- } else {
- resolve(JSON.parse(data.data).data.records);
- }
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 备货完成
- async prepareGoods(sscId: any, pId: any) {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.put(`${environment.APP_SERVE_URL}/inventory/warehouse/mobile/prepare?sscId=${sscId}&pId=${pId}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code === 0) {
- message = `备货完成`;
- } else if (JSON.parse(data.data).code === 1) {
- message = JSON.parse(data.data).msg;
- }
- const alert = await this.alertController.create({
- // header: 'Confirm!',
- message: message,
- buttons: [
- {
- text: '确定',
- role: 'cancel',
- cssClass: 'secondary',
- handler: (blah) => {
- }
- }
- ]
- });
- await alert.present();
- resolve(data.data);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '保存失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取QC验货初检报告列表
- async getQCList(current: number, size: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile?${current}&${size}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (data.data === null || JSON.parse(data.data).data.records == null) {
- const toast = await this.toastCtrl.create({
- message: '无数据',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- resolve([]);
- }
- resolve(JSON.parse(data.data).data.records);
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 获取QC验货初检报告详情
- async getQCDetail(sscId: number, pId: number): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.get(`${environment.APP_SERVE_URL}/inventory/qc/mobile/detail?sscId=${sscId}&pId=${pId}`, {},
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code == 0) {
- resolve(JSON.parse(data.data).data);
- } else if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- const toast = await this.toastCtrl.create({
- message,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '查询失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 生成QC验货初检报告
- async createQC(form: any): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('json');
- const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json;charset=UTF-8' };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qc/mobile`, form,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- if (JSON.parse(data.data).msg === 'success') {
- const alert = await this.alertController.create({
- // header: 'Confirm!',
- message: `生成成功,初检报告编号${JSON.parse(data.data).data}`,
- buttons: [
- {
- text: '确定',
- role: 'cancel',
- cssClass: 'secondary',
- handler: (blah) => {
- }
- }
- ]
- });
- await alert.present();
- }
- resolve(JSON.parse(data.data));
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '生成失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- // 添加qc日志
- async addQClog(form: any): Promise<any> {
- const token = await this.getToken();
- const loading = await this.loadingCtrl.create();
- await loading.present();
- this.nativeHttp.setDataSerializer('urlencoded');
- const headers = { Authorization: `Bearer ${token}` };
- return new Promise((resolve, reject) => {
- from(this.nativeHttp.post(`${environment.APP_SERVE_URL}/inventory/qc/mobile/qclog`, form,
- headers)).pipe(
- finalize(() => loading.dismiss())
- ).subscribe(async data => {
- let message = '';
- if (JSON.parse(data.data).code == 1) {
- message = JSON.parse(data.data).msg;
- resolve([]);
- } else if (JSON.parse(data.data).code == 0) {
- message = '添加成功';
- resolve(JSON.parse(data.data));
- }
- const toast = await this.toastCtrl.create({
- message,
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- }, async err => {
- console.log(err);
- const toast = await this.toastCtrl.create({
- message: '添加失败',
- duration: 1000,
- position: 'top'
- });
- await toast.present();
- });
- });
- }
- setUsername(username: string): Promise<any> {
- return this.storage.set('username', username);
- }
- getUsername(): Promise<string> {
- return this.storage.get('username').then((value) => {
- return value;
- });
- }
- isLoggedIn(): Promise<boolean> {
- return this.storage.get(this.HAS_LOGGED_IN).then((value) => {
- return value === true;
- });
- }
- // checkHasSeenTutorial(): Promise<string> {
- // return this.storage.get(this.HAS_SEEN_TUTORIAL).then((value) => {
- // return value;
- // });
- // }
- }
|