1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210 |
- 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';
- @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.get(`${environment.APP_SERVE_URL}/production/sample/factory/pCode`,
- data,
- 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([]);
- } 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(() => 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).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();
- 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;
- // });
- // }
- }
|