123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- import tool from "../../utils/tool"
- import {
- get,
- post
- } from '../../utils/http.js'
- // 移动动画
- let animation = wx.createAnimation({});
- Page({
- data: {
- codeList: [], //手机
- qrCodeList: [], //耳机
- userName: '',
- remarks: '',
- nowCode: '',
- type: '',
- popupShow: false,
- againDelete: false,
- deleteOverData: false
- },
- onLoad: function () {
- },
- onShow() {
- this.donghua()
- },
- donghua() {
- var that = this;
- // 控制向上还是向下移动
- let m = true
- setInterval(function () {
- if (m) {
- animation.translateY(230).step({
- duration: 3000
- })
- m = !m;
- } else {
- animation.translateY(0).step({
- duration: 3000
- })
- m = !m;
- }
- that.setData({
- animation: animation.export()
- })
- }.bind(this), 3000)
- },
- /**
- * 扫码,延时器
- */
- scancode: tool.debounce(function (e) {
- // 校验扫描结果,并处理
- let code = e[0].detail.result
- // 提示音
- let innerAudioContext = wx.createInnerAudioContext()
- innerAudioContext.src = '/audio/scanCode.mp3'
- innerAudioContext.play()
- console.log(e[0].detail);
- if (this.data.codeList.length == 0 && this.data.qrCodeList.length == 0) {
- this.setData({
- type: e[0].detail.type
- })
- } else {
- if (e[0].detail.type != this.data.type) {
- wx.showToast({
- title: '同一批次只能入库相同的设备',
- icon: 'none'
- })
- return
- }
- }
- console.log('code',code);
- if (e[0].detail.type == "barcode") {
- console.log('code2',code);
- var result = this.data.codeList.some(item => item.imei == code)
- if (!result) {
- console.log('code1',code);
- post('get_phone_info', {
- imei: code
- }, res => {
- console.log(res,'resres');
- if (res.code == 200) {
- let arr = this.data.codeList
- arr.unshift(res.data)
- this.setData({
- codeList: arr
- })
- }else{
- console.log('tanchuang ');
- wx.showToast({
- title: '没有找到该设备',
- icon: 'none'
- })
- }
- })
- } else {
- wx.showToast({
- title: '重复扫码。',
- icon: 'error'
- })
- }
- } else {
- if (JSON.stringify(this.data.qrCodeList).indexOf(code) == -1) {
- let arr = this.data.qrCodeList
- arr.unshift(code)
- this.setData({
- qrCodeList: arr
- })
- } else {
- wx.showToast({
- title: '重复扫码。',
- icon: 'error'
- })
- }
- }
- }, 500),
- warehousing() {
- this.setData({
- popupShow: true
- })
- },
- onOpenShow() {
- this.setData({
- popupShow: true
- })
- },
- /**
- * 入库
- */
- onAddCode() {
- if (this.data.userName.length == 0) {
- wx.showToast({
- title: '请输入客户名',
- icon: 'error'
- })
- return
- }
- let imeiList = []
- this.data.codeList.forEach(item => {
- imeiList.push(item.imei)
- })
- wx.showLoading({
- title: '入库中...',
- })
- let that = this
- post('save_box_info', {
- ids: this.data.type == 'barcode' ? imeiList : this.data.qrCodeList,
- name: this.data.userName,
- comment: this.data.remarks,
- type:this.data.type
- }, res => {
- if (res.code == 200) {
- setTimeout(function () {
- wx.hideLoading()
- wx.showToast({
- title: `成功入库${res.cnt}台设备`,
- icon: 'error'
- })
- that.setData({
- popupShow:false
- })
- that.clearData()
- }, 2000)
- }
- })
- },
- onCloseShow() {
- this.setData({
- popupShow: false,
- codeInfo: ''
- })
- },
- onDelete(e) {
- this.setData({
- nowCode: e.currentTarget.dataset.index,
- againDelete: true
- })
- },
- /**
- * 删除单条录入数据
- * @param {} e
- */
- onDeleteCode(e) {
- let index, _codeList
- index = this.data.nowCode
- if (this.data.type == 'barcode') {
- _codeList = this.data.codeList
- _codeList.splice(index, 1)
- this.setData({
- codeList: _codeList,
- againDelete: false
- })
- } else {
- _codeList = this.data.qrCodeList
- _codeList.splice(index, 1)
- this.setData({
- qrCodeList: _codeList,
- againDelete: false
- })
- }
- },
- clearData() {
- this.setData({
- codeList: [], //手机
- qrCodeList: [], //耳机
- userName: '',
- remarks: '',
- nowCode: '',
- type: '',
- })
- },
- /**
- * 清空数据
- */
- onCodeInput() {
- this.setData({
- deleteOverData: true
- })
- },
- onDeleteOverData() {
- this.clearData()
- this.setData({
- deleteOverData: false
- })
- }
- })
|