const app = getApp(); const take = '/static/take.png'; const takeAll = '/static/takeAll.png'; const takeBack = '/static/return.png'; const check = '/static/check.png'; const del = '/static/delete.png'; const sell = '/static/sell.png'; const api = require('../../../utils/api'); const cloudApi = require('../../../utils/cloudApi') Page({ data: { page: 'pages/tabBar/firstPage/firstPage', statusBarHeight: '', cardList1: [ { icon: take, title: '常规取用', type: 1 }, { icon: takeAll, title: '用尽取用', type: 5 }, { icon: takeBack, title: '归还', type: 2 }, { icon: check, title: '用尽登记', type: 3 }, { icon: del, title: '扫码作废', type: 4 } ], cardList2: [ { icon: sell, title: '销售', type: 1 }, { icon: del, title: '扫码作废', type: 4 } ], showModal: false, modalTitle: '取用', hazmat: {}, product: {}, hazmatBack: { id: null, remaining: '' }, user: {}, tabNum: 1, blockText: '危化品', blockStyle: { transform: 'translateX(0px)' } }, onLoad() { // 获取手机状态栏高度 this.setData({ statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'] }); wx.hideTabBar(); this.getUserInfo(); }, onShow() { }, // 输入框实现双向绑定 onFormInput(e) { const field = e.currentTarget.dataset.field; // 获取字段名 this.setData({ [field]: e.detail.value // 动态更新对应字段 }); }, getUserInfo() { // 云开发 // const companyId = wx.getStorageSync('user').companyId // cloudApi.queryPost('userInfoList',{company_id: companyId}).then(res=>{ // if(res.data.length>0){ // this.setData({ // user: cloudApi.changeKey(res.data)[0] // }); // wx.setStorageSync('userSet', cloudApi.changeKey(res.data)[0]) // } // }) // api api.getUserInfo().then(res => { if(res.code == 200) { this.setData({ user: res.data }); wx.setStorageSync('userSet', res.data); } else { wx.showToast({ title: res.message, icon: 'none' }); } }); }, closeModal(){ this.setData({ showModal: false, hazmat: {}, product: {} }); }, scanCode(e) { const title = e.currentTarget.dataset.title; const t = this; t.setData({ modalTitle: title }); wx.scanCode({ autoZoom: false, scanType: ['qrCode'], success(res) { if(res && res.result) { if(res.result.indexOf('SJ') == -1 && res.result.indexOf('CP') == -1) { wx.showToast({ title: '没有识别到正确的编码,请重新扫码', icon: 'error', duration: 2000 }); return; } if(t.data.tabNum == 1) { // 云开发请求 // wx.cloud.callFunction({ // name: 'getHazmatInfo', // data: { // code: 'SJ08202502250003' // } // }).then(res=>{ // if(res.result && Array.isArray(res.result.list) && res.result.list.length>0){ // t.setData({ // hazmat: cloudApi.changeKey(res.result.list[0]), // showModal: true // }) // }else{ // wx.showToast({ // title: '无条码信息', // icon: 'error', // duration: 2000 // }); // } // }) // api请求 api.getHazmatByCode({code: res.result}).then((re) => { if(re.code == 200) { t.setData({ hazmat: re.data, showModal: true }); } else { wx.showToast({ title: re.message, icon: 'error', duration: 2000 }); } }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); } else { // 云开发请求 // wx.cloud.callFunction({ // name: 'getProductInfo', // data: { // code: res.result // } // }).then(res=>{ // if(res.result && Array.isArray(res.result.list) && res.result.list.length>0){ // t.setData({ // product: cloudApi.changeKey(res.result.list[0]), // showModal: true // }) // }else{ // wx.showToast({ // title: '无条码信息', // icon: 'error', // duration: 2000 // }); // } // }) // api请求 api.getProductByCode({code: res.result}).then((re) => { if(re.code == 200) { t.setData({ product: re.data, showModal: true }); } else { wx.showToast({ title: re.message, icon: 'error', duration: 2000 }); } }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); } } else { wx.showToast({ title: '该二维码已失效或不包含条码信息', icon: 'error', duration: 2000 }); } } }); }, confirmTake1() { const t = this; // 云服务请求 // wx.cloud.callFunction({ // name: 'hazmatUsing', // data: { // warehouseId: t.data.hazmat.warehouseId, // basicId: t.data.hazmat.basicId, // companyId: t.data.hazmat.companyId, // cupboardId: t.data.hazmat.cupboardId, // hazmatId: t.data.hazmat.id, // uid: wx.getStorageSync('user').id, // id: t.data.hazmat.Id, // remaining: t.data.hazmat.remaining, // status: 0 // } // }).then(res=>{ // if(res.result.code == 200){ // wx.showToast({ // title: '取用成功', // icon: 'success', // duration: 2000 // }); // } // }) // api请求 api.postHazmatUse(t.data.hazmat.id, 0).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); t.closeModal(); }, confirmTake2() { const t = this; // 云服务请求 // wx.cloud.callFunction({ // name: 'hazmatUsing', // data: { // warehouseId: t.data.hazmat.warehouseId, // basicId: t.data.hazmat.basicId, // companyId: t.data.hazmat.companyId, // cupboardId: t.data.hazmat.cupboardId, // hazmatId: t.data.hazmat.id, // uid: wx.getStorageSync('user').id, // id: t.data.hazmat.Id, // remaining: t.data.hazmat.remaining, // status: 1 // } // }).then(res=>{ // if(res.result.code == 200){ // wx.showToast({ // title: '取用成功', // icon: 'success', // duration: 2000 // }); // } // }) // api请求 api.postHazmatUse(t.data.hazmat.id, 1).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); t.closeModal(); }, confirmBack() { const t = this; if (!t.data.hazmatBack.remaining) { wx.showToast({ title: '归还剩余量不可为空', icon: 'none' }); return; } t.setData({ 'hazmatBack.id': t.data.hazmat.id, }); api.postHazmatReturn(t.data.hazmatBack).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); t.closeModal(); }, confirmCheck() { const t = this; api.postHazmatUsed(t.data.hazmat.id).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); t.closeModal(); }, confirmSell() { const t = this; api.postProductSold(t.data.product.id).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); t.closeModal(); }, confirmCancle() { const t = this; if(t.data.tabNum == 1) { api.postHazmatDiscard(t.data.hazmat.id).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); } else { api.postProductDiscard(t.data.product.id).then((r) => { wx.showToast({ title: r.message, icon: 'none' }); }).catch(err => { wx.showToast({ title: err, duration: 2000 }); }); } t.closeModal(); }, closeModal() { this.setData({ hazmat: {}, product: {}, hazmatBack: { id: null, remaining: '' }, showModal: false }); }, changeTab(e) { const num = e.currentTarget.dataset.num; if(num == 1) { this.setData({ tabNum: 1, blockStyle: { transform: 'translateX(0px)' }, blockText: '危化品' }); } else { this.setData({ tabNum: 2, blockStyle: { transform: 'translateX(calc(100% - 2px))' }, blockText: '成品' }); } }, toStudy(e) { const item = e.currentTarget.dataset.item; wx.setStorageSync("prevPage", '/pages/tabBar/firstPage/firstPage'); wx.navigateTo({ url: `/pages/tabBar/current/detail?bank=` + encodeURIComponent(JSON.stringify(item)) }); }, toCourses() { wx.switchTab({ url: '/pages/tabBar/current/current' }); } });