微信小程序 扫二维码/条形码 标准倒计时

在这里插入图片描述

// pages/orderDetail/orderDetail.js
var utiltime = require('../../../../utils/time.js')
var utilsign = require('../../../../utils/getsign.js')
var httpclient = require('../../../../utils/httpclient.js')

var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wlArray:null,
    sellerId:'0',
    aaa:false,
    groupBox:false,   //拼团
    imgUrl: app.globalData.imgUrl,  //图片地址
    codeInfo1: true, //编辑编码信息
    codeInfo2: false,  //保存编码信息
    codeInfo3:false,
    codeInfo4:true,   //请填写串号/编码信息
    codeInfo6: true, //判断串号边框和编码边框隐藏,扫描,不可修改
    detailInfo:[],//录入手机串号编码
    isSmHide:true,
    dataArr:[],//模糊搜索数据
    eNumInputIndex:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    var that=this;
    if(options.id){
      that.setData({ 
        id:options.id,
        god: options.god,
        status: options.status
      })
    }
    if (options.wlArray) {
      var bean = JSON.parse(options.wlArray);
      that.setData({
        wlArray: bean
      })
      // console.log(bean)
    }
    that.setData({
      userinfo: wx.getStorageSync('userinfo')
    })
  },


  //分享
  onShareAppMessage: function () {
  
    let that = this;
    // console.log(that.data)
    return {
      title: '【仅剩' + that.data.shortCount + '个名额】最低' + that.data.groupData.product_price / 100 + '元,囤了不吃亏 ,' + that.data.userinfo.nickName + ' 邀您参与 ' + that.data.groupData.gb_activity_name + '团购的拼团', // 分享标题
      desc: '',
      path: '/pages/collageDetail/collageDetail?collageId='+that.data.groupData.activity_id + '&&group_booking_group_id=' + that.data.groupData.group_booking_group_id + '&&id=' + that.data.groupData.gb_main_product_id + '&&spid=' + that.data.groupData.gb_product_id + '&&fromType=' + 2 + '&&orderid=' + that.data.orderid,
      imageUrl: that.data.groupData.gb_activity_logoUrl
    }
  },


  //倒计时自动取消
  changeStatus2: function (id) {
    var that = this
    var user = wx.getStorageSync("userinfo");
    var userId = wx.getStorageSync('wxuserid')
    var _sign = '';
    var _time = utiltime.getTimems();
    var userInfo = wx.getStorageSync('userinfo')
    var arys = {
      'userId': userId,
      'orderId': id,
      'status': 'c010110',
      'openId': user.littleAppOpenId,
      // 'refereesId':'',
      'sellerId': that.data.sellerId,
      'memberFlag': userInfo.memberFlag,
      'model_type': '0'
    };
    var jsonstr = httpclient.objKeySort(arys); //函数执行
    _sign = utilsign.getSign(_time, jsonstr);

    var datajson = '"{';
    datajson += '\'userId\':\'' + userId + '\',';
    datajson += '\'orderId\':\'' + id + '\',';
    datajson += '\'status\':\'' + 'c010110' + '\',';
    datajson += '\'openId\':\'' + user.littleAppOpenId + '\',';
    datajson += '\'model_type\':\'0\',';
    // datajson += '\'refereesId\':\'\',';
    datajson += '\'sellerId\':\'' + that.data.sellerId+'\',';
    datajson += '\'memberFlag\':\'' + userInfo.memberFlag+'\',';
    datajson = datajson.substring(0, datajson.length - 1);
    datajson += '}"';

    httpclient.doRequest('/svc/api/order/changeStatus', { paramJson: '{"data":' + datajson + ',"sign":"' + _sign + '","source":"weipro","timeStamp":' + _time + '}' }, function (res) {
      if (res.status == "SUCCESS") {
        that.data.data.status = 'c010110';
        that.data.data.label='已取消'
        delete that.data.data.create_date;
        clearInterval(that.data.timer)
        that.orderDetail()
        // that.setData({ data:that.data.data})
      } 
      // else {
      //   wx.showToast({
      //     title: res.msg,
      //     icon: 'none'
      //   })
      // }
    }, null, null)
  },
  nowTime: function () {
    var that = this;
    var intDiff = that.data.data.create_date;//返回得时间
    var currentTime = new Date().getTime();//当前时间
    var time15 = 15 * 60 * 1000;//十五分钟
    var oldTime = intDiff + time15;//过期时间
    var time = (oldTime - currentTime) / 1000;//剩余得时间

    var minute = 0, second = 0;
    if (time > 0) {//转换时间
      minute = Math.floor(time / 60);
      second = Math.floor(time % 60);
      if (minute <= 9) minute = '0' + minute;
      if (second <= 9) second = '0' + second;
      time--;
      var str = minute + '分' + second + '秒';
      that.data.data.str = str;
      // console.log(str)    
    }else{
      //如果倒数计时到了
      if (that.data.data.status == 'c010101') {
        that.changeStatus2(that.data.data.id)
      }
    }
    that.setData({
      data: that.data.data
    })
  },
  //判断待付款订单是否可以付款
  payOrderCheck:function(){
    var that=this;
    wx.showLoading({
      title: '',
      mask:true
    })
    var userId = wx.getStorageSync('wxuserid')
    var unpickService = {
      orderId: that.data.data.id,
      userId: userId
    }
    var user = wx.getStorageSync("userinfo");
    var openId = user.littleAppOpenId;
    httpclient.doRequestService('/svc/api/order/payOrderCheck', unpickService, function (res) {
      if (res.status == "SUCCESS") {
        // console.log(res)

        var wxAddOrderMap = {
          openid: openId,
          bodyContent: "迪信通商品购买",
          out_trade_no: that.data.data.id,
          total_fee: res.data.goodsSum,
          // total_fee: 1,
          ip: "127.0.0.1",
          attach: res.data.payInfoId
        }
        httpclient.doRequestService('/svc/api/weixinPay/addOrder', wxAddOrderMap, function (res1) {
          if (res1.status == "SUCCESS") {
            // console.log(res1);
            var payMap = res1.data.jspData;
            wx.hideLoading()
            wx.requestPayment(
              {
                'timeStamp': payMap.timeStamp,
                'nonceStr': payMap.nonceStr,
                'package': payMap.package1,
                'signType': 'MD5',
                'paySign': payMap.paySign,
                'success': function (res) {
                  wx.showToast({
                    title: '支付成功',
                    icon: 'none',
                    duration: 1500,
                  })
                  // that.delte()
                  wx.redirectTo({
                    url: '../../cartInfo/orderSuccess/orderSuccess?orderid=' + that.data.orderid + '&status=success' + '&ispickup=' + that.data.ispickup
                  })
                  console.log(that.data.ispickup)
                },
                'fail': function (res) {
                  // that.payOrderCheck(orderId)
                  that.setData({
                    orderSure: true,  //确认支付按钮
                    orderQx: false //继续支付按钮
                  })
                  // that.delte()
                },
                'complete': function (res) {

                }
              });

          }
          // console.log("返回数据" + res);
        }, null, null);

      }
    }, null, null);
  },

  wlxq: function (e) {
    // console.log(e)
    var that = this
    var wlArray = e.currentTarget.dataset.aaa
    wx.setStorageSync('wlArray', wlArray) 
    wx.navigateTo({
      url: '../wuliuInfo/wuliuInfo'
    })
  },
  //删除订单
  changeVisible: function (e) {
    var that = this;
    var userId = wx.getStorageSync('wxuserid')
    wx.showModal({
      title: '提示',
      content: '确定要删除吗?',
      success: function (sm) {
        if (sm.confirm) {
          var _sign = '';
          var _time = utiltime.getTimems();
          var arys = {
            'userId': userId,
            'orderId': that.data.id,
            'visible': '1'
          };
          var jsonstr = httpclient.objKeySort(arys); //函数执行
          _sign = utilsign.getSign(_time, jsonstr);

          var datajson = '"{';
          datajson += '\'userId\':\'' + userId + '\',';
          datajson += '\'orderId\':\'' + that.data.id + '\',';
          datajson += '\'visible\':\'1\',';
          datajson = datajson.substring(0, datajson.length - 1);
          datajson += '}"';

          httpclient.doRequest('/svc/api/order/changeVisible', { paramJson: '{"data":' + datajson + ',"sign":"' + _sign + '","source":"weipro","timeStamp":' + _time + '}' }, function (res) {
            if (res.status == "SUCCESS") {
              wx.showToast({
                title: '删除成功',
                icon: 'success',
                success: function () {
                  setTimeout(function () {
                    wx.navigateBack({

                    })
                  }, 1500)
                }
              })
            } else {
              wx.showToast({
                title: res.msg,
                icon: 'none'
              })
            }
          }, null, null) 
        } else if (sm.cancel) {
          // console.log('用户点击取消')
        }
      }
    })
    
  },
  
  //确认收货、取消订单
  changeStatus: function (e) {
    var that = this
    var userId = wx.getStorageSync('wxuserid'),
      id = e.currentTarget.dataset.id,
      status = e.currentTarget.dataset.status,
      user = wx.getStorageSync("userinfo");
      
    var _sign = '';
    var _time = utiltime.getTimems();
    var userInfo = wx.getStorageSync('userinfo')
    var arys = {
      'userId': userId,
      'orderId': id,
      'status': status,
      'openId': user.openId,
      // 'refereesId':'',
      'sellerId': that.data.sellerId,
      'memberFlag': userInfo.memberFlag,
      'model_type': '0'
    };
    var jsonstr = httpclient.objKeySort(arys); //函数执行
    _sign = utilsign.getSign(_time, jsonstr);

    var datajson = '"{';
    datajson += '\'userId\':\'' + userId + '\',';
    datajson += '\'orderId\':\'' + id + '\',';
    datajson += '\'status\':\'' + status + '\',';
    datajson += '\'openId\':\'' + user.openId + '\',';
    datajson += '\'model_type\':\'0\',';
    // datajson += '\'refereesId\':\'\',';
    datajson += '\'sellerId\':\'' + that.data.sellerId + '\',';
    datajson += '\'memberFlag\':\'' + userInfo.memberFlag + '\',';
    datajson = datajson.substring(0, datajson.length - 1);
    datajson += '}"';
    if (status == 'c010110') {
      wx.showModal({
        title: '提示',
        content: '是否要取消订单',
        success: function (res) {
          if (res.confirm) {
            that.setData({
              aaa:true
            })
            request(datajson)
          } else if (res.cancel) {
            // console.log('用户点击取消')
          }
        }
      })
    } else if (status == 'c010104') {
      wx.showModal({
        title: '提示',
        content: '您确定收到商品?',
        success: function (res) {
          if (res.confirm) {
            request(datajson)
          } else if (res.cancel) {
            // console.log('用户点击取消')
          }
        }
      })
    }
    function request(datajson) {
      httpclient.doRequest('/svc/api/order/changeStatus', { paramJson: '{"data":' + datajson + ',"sign":"' + _sign + '","source":"weipro","timeStamp":' + _time + '}' }, function (res) {
        if (res.status == "SUCCESS") {
          wx.showToast({
            title: '成功',
            icon: 'success',
            success: function () {
              if (status == 'c010110') {
                that.data.data.label = '已取消';
              } else if (status == 'c010104') {
                that.data.data.label = '已完成';
              }
              that.data.data.status = status;
              that.setData({
                data: that.data.data
              })
            }
          })
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      }, null, null)
    }

  },
  //评价晒单
  goEvaluateOrder: function (e) {
    wx.setStorageSync('orderDetails', e.currentTarget.dataset.item)
    wx.navigateTo({
      url: '../evaluateOrder/evaluateOrder',
    })
  },
  //申请售后
  goShProcedure:function(e){
    var that=this,
      id=e.currentTarget.dataset.id;
      console.log(id)
    wx.navigateTo({
      url: '../shProcedure/shProcedure?id='+id,
    })
  },

  //售后详情
  goShProcess:function(e) {
    var that = this,
    id = e.currentTarget.dataset.id; 
    // console.log(id)
    wx.navigateTo({
      url: '../shProcess/shProcess?id=' + id,
    })
  },

  //跳转到退款中售后详情
  refunding: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../refunding/refunding?id=' + id,
    })
  },

  // 商品信息跳转商品详情页
  spDetail:function(e) {
    var that = this
    console.log(e)
    var obj = {
      image_urls: [e.currentTarget.dataset.img],
      full_name: e.currentTarget.dataset.name,
      groupPrice: e.currentTarget.dataset.member,
      market_price: e.currentTarget.dataset.market,
      selling_point: e.currentTarget.dataset.selling,
    }
    var spid = e.currentTarget.dataset.id
    var id = e.currentTarget.dataset.goodid
    // console.log(id)
    wx.navigateTo({
      url: '/pages/detail/detail?spid=' + id + '&id=' + spid + '&obj=' + JSON.stringify(obj)
    })
    // that.setData({
    //   productype: e.currentTarget.dataset.productype   //判断商品类型
    // })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  orderDetail:function(){
    var that = this;
    var _sign = '';
    var _time = utiltime.getTimems();
    var userId = wx.getStorageSync('wxuserid')
    var arys = {
      'userId': userId,
      'orderId': that.data.id,
    };
    var jsonstr = httpclient.objKeySort(arys); //函数执行
    _sign = utilsign.getSign(_time, jsonstr);

    var datajson = '"{';
    datajson += '\'userId\':\'' + userId + '\',';
    datajson += '\'orderId\':\'' + that.data.id + '\',';
    datajson = datajson.substring(0, datajson.length - 1);
    datajson += '}"';

    httpclient.doRequest('/svc/api/order/getOrderDeatil', { paramJson: '{"data":' + datajson + ',"sign":"' + _sign + '","source":"weipro","timeStamp":' + _time + '}' }, function (res) {
      if (res.status == "SUCCESS") {
        that.setData({
          data: res.data,
          orderid: res.data.id,
          ispickup: res.data.is_pick_up,
          productType: res.data.productType,
          selfsupport: res.data.self_support,
          agent_num: res.data.agent_num
        })
        wx.hideLoading()
      }
    }, null, null)

    
  },
  //查询当前团购所缺人数
  getGroupNumAndShortCount:function(){
    var that=this;
    var arys = {
      'orderId': that.data.data.id,
      'Product_id': that.data.data.detail[0].id
    };
    httpclient.doRequestService('/svc/api/group/getGroupNumAndShortCount', arys, function (res) {
      if (res.status == "SUCCESS") {
        that.setData({
          groupBox: true
        })
        if (that.data.data.status == 'c010101' || that.data.data.status == 'c010110') {
          that.setData({
            groupBox: false
          })
        }else{
          // console.log(res)
          that.getGroupMembersByOrderId()
          var userInfo = wx.getStorageSync('userinfo');
          that.setData({
            activityId: res.activityId,
            groupNum: res.groupNum,
            shortCount: res.shortCount,
            groupData: res.data,
            userInfo: userInfo
          })
        }
      }
    }, null, null)
  },
  // 查看已付款的团购成员
  getGroupMembersByOrderId:function(){
    var that = this;
    var arys = {
      'orderId': that.data.data.id,
      'product_id': that.data.data.detail[0].id
    };
    httpclient.doRequestService('/svc/api/group/getGroupMembersByOrderId', arys, function (res) {
      if (res.status == "SUCCESS") {
        // console.log(res)
        that.setData({
          groupMembersByOrderIdData:res.data,
          millis: that.countTime(res.millis),
          milli:res.millis
        })
        if (that.data.shortCount == "0" || (that.data.shortCount > 0 && that.data.millis == "拼团已结束")) {
          that.setData({
            groupEnd: true
          })
        }
        var millis = res.millis;
        if (that.data.data.status == 'c01010201'){
          var timer = setInterval(function(){
            millis--;
            that.setData({
              millis: that.countTime(millis),
               
            })
          },1000)
          that.setData({
            timer: timer
          })
        }
      }
    }, null, null)
  },
  //转换时分秒
  countTime: function (leftTime){
    var that=this;
    if (that.data.data.status == 'c01010202'){
      return '拼团成功'
    }
    var d, h, m, s, ms;
    if (leftTime >= 0) {
      h = Math.floor(leftTime / 60 / 60 % 24);
      m = Math.floor(leftTime / 60 % 60);
      s = Math.floor(leftTime % 60);
      if (s < 10) {
        s = "0" + s;
      }
      if (m < 10) {
        m = "0" + m;
      }
      if (h < 10) {
        h = "0" + h;
      }
    } else {
      return '拼团已结束'
    }
    return '剩余 '+h+':'+m+':'+s;
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      var that = this;
      var _sign = '';
      var _time = utiltime.getTimems();
      var userId = wx.getStorageSync('wxuserid')
      var arys = {
        'userId': userId,
        'orderId': that.data.id,
      };
      var jsonstr = httpclient.objKeySort(arys); //函数执行
      _sign = utilsign.getSign(_time, jsonstr);

      var datajson = '"{';
      datajson += '\'userId\':\'' + userId + '\',';
      datajson += '\'orderId\':\'' + that.data.id + '\',';
      datajson = datajson.substring(0, datajson.length - 1);
      datajson += '}"';

      httpclient.doRequest('/svc/api/order/getOrderDeatil', { paramJson: '{"data":' + datajson + ',"sign":"' + _sign + '","source":"weipro","timeStamp":' + _time + '}' }, function (res) {
        if (res.status == "SUCCESS") {
          // console.log(res);
          if (that.data.isSmHide){
            that.setData({
              data: res.data,
              orderid: res.data.id,
              ispickup: res.data.is_pick_up,
              productType: res.data.productType,
              selfsupport: res.data.self_support,
              agent_num: res.data.agent_num
            })

            // 默认提交保存自提数据
            for (var i = 0; i < that.data.data.detail.length; i++) {
              that.data.data.detail[i].detailInfo = []
              for (var j = 0; j < that.data.data.detail[i].goods_num; j++) {
                if (that.data.data.detail[i].enum){
                  var enumArr = that.data.data.detail[i].enum.split(',');
                  if (that.data.data.detail[i].productType == 'e3b2a8aed3414ec98a140ee8fbde25f1'){
                    if (enumArr.length < that.data.data.detail[i].goods_num) {
                      var obj = { detailId: that.data.data.detail[i].id, eNum: enumArr[0], phoneCode: '' };
                    } else {
                      var obj = { detailId: that.data.data.detail[i].id, eNum: enumArr[j], phoneCode: '' };
                    }
                  }else{
                    var obj = { detailId: that.data.data.detail[i].id, eNum: enumArr[j], phoneCode: '' }; 
                    
                  }
                  
                  var phoneCodeArr=[];
                  if (that.data.data.detail[i].phone_code){
                    phoneCodeArr = that.data.data.detail[i].phone_code.split(',');
                    if (phoneCodeArr[j]!=''){
                       obj.phoneCode = phoneCodeArr[j]
                       obj.showSpecific = true
                    }
                  }
                  if (obj.eNum){
                    that.data.data.detail[i].detailInfo.push(obj)
                  }
                  that.setData({
                    codeInfo3:true,
                    codeInfo6:false,
                    codeInfo4:false,
                    codeInfo1:false
                  })
                }else{
                  that.data.data.detail[i].detailInfo.push({ detailId: that.data.data.detail[i].id, eNum: '', phoneCode: '' })
                }
                
              }
            }
            that.setData({
              data: that.data.data
            })

            console.log(that.data.data)
            that.nowTime();
            var timer = setInterval(function () { that.nowTime(); }, 1000);
            that.setData({ timer: timer })

            if (res.data.model_type == '1') {
              that.getGroupNumAndShortCount()
            }
          }
          that.setData({
            isSmHide: true,
          })
        }
      }, null, null) 
      
    },
    onHide:function(){
      var that=this;
      clearInterval(that.data.timer)
    },


    // 自提编码
  codeInfo:function(e) {
    var that = this
    var productype = e.currentTarget.dataset.productype
    console.log(productype)
    that.setData({
      codeInfo1:false,
      codeInfo2:true,
      codeInfo3: true,
      codeInfo4:false,
      codeInfo5:false,
      productype: productype
    })
  },

  // 手机串号输入事件
  phoneCodeInput:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var idx = e.currentTarget.dataset.idx;
    var value = e.detail.value;
    that.data.data.detail[index].detailInfo[idx].phoneCode = value;
    if(value.length == 14 || value.length == 15){
      that.smCodeSuccess(value, index, idx)
    } else if (value.length == 0){
      that.data.data.detail[index].detailInfo[idx].eNum = '';
      that.setData({
        data:that.data.data
      })
    }
  },

  // 商品编码输入事件
  eNumInput:function(e){
    var that=this;
    var index=e.currentTarget.dataset.index;
    var idx = e.currentTarget.dataset.idx;
    that.setData({
      eNumInputIndex:idx
    })
    var value = e.detail.value;
    that.data.data.detail[index].detailInfo[idx].eNum=value;
    if(value.length > 3){
      var arys = {
        'productSerial': '',
        'productEnum': value,
        'agentNum': that.data.agent_num
      };
      httpclient.doRequestService('/svc/api/esale/getProductEnumInfo', arys, function (res) {
        if (res.status == "SUCCESS") {
          console.log(res)
          console.log(JSON.parse(res.data))
          var resData = res;
          var resInfo = JSON.parse(resData.data)
          if (resInfo.length>0){
            that.setData({
              dataArr: resInfo
            })
          } 
        }
      }, null, null)
    }
    
    that.setData({
      data: that.data.data
    })
  },
  phoneCodeInput2:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var idx = e.currentTarget.dataset.idx;
    var value = e.detail.value;
    that.data.data.detail[index].detailInfo[idx].phoneCode = value;
    that.setData({
      data: that.data.data
    })
    
  },

  vagueTap:function(e){
    var that=this;
    var content=e.currentTarget.dataset.con;
    var pIndex = e.currentTarget.dataset.index;
    var sIndex = e.currentTarget.dataset.idx;
    var num = e.currentTarget.dataset.num;
    var specific = e.currentTarget.dataset.specific;
    if (num <= 0){
      wx.showToast({
        title: '库存不足',
        icon:'none'
      })
      return
    }
    that.data.data.detail[pIndex].detailInfo[sIndex].eNum = content;
    if (specific == 14 || specific == 15 || specific == 18){
      that.data.data.detail[pIndex].detailInfo[sIndex].showSpecific = true;
    }
    
    that.setData({
      data: that.data.data,
      dataArr:[]
    })
  },
  // 点击保存提交
  codeInfoSummit:function () {
    var that = this
    var detailInfo=[];
    var showSpecificNum = 0, showSpecificNum2 = 0, showSpecificNum3=0;
    var spbm = true  //判断商品编码至少一个不是空
    for(var i=0;i<that.data.data.detail.length;i++){
      // detailInfo = detailInfo.concat(that.data.data.detail[i].detailInfo)detailId
      detailInfo.push({ detailId: that.data.data.detail[i].id, eNum: '', phoneCode: '' })
      if (that.data.data.detail[i].productType == 'e3b2a8aed3414ec98a140ee8fbde25f1'){
        for (var j=0;j<that.data.data.detail[i].detailInfo.length;j++){
          // if (detailInfo[i].phoneCode.indexOf(that.data.data.detail[i].detailInfo[j].phoneCode) == -1) {
            detailInfo[i].phoneCode = detailInfo[i].phoneCode + that.data.data.detail[i].detailInfo[j].phoneCode+','
          // }
          // if (detailInfo[i].eNum.indexOf(that.data.data.detail[i].detailInfo[j].eNum) == -1) {
            detailInfo[i].eNum = detailInfo[i].eNum + that.data.data.detail[i].detailInfo[j].eNum + ','
          // }

          if (that.data.data.detail[i].detailInfo[j].phoneCode == '') {
            wx.showToast({
              title: '手机串号不能为空',
              icon: 'none'
            })
            return
          }
          if (that.data.data.detail[i].detailInfo[j].eNum == '') {
            wx.showToast({
              title: '请补全手机串号信息',
              icon: 'none'
            })
            return
          }
          if (that.data.data.detail[i].detailInfo[j].eNum == '查询不到所对应的商品编码') {
            wx.showToast({
              title: '您输入的手机串号不正确',
              icon: 'none'
            })
            return
          }
        }
      }else{
        for (var j = 0; j < that.data.data.detail[i].detailInfo.length; j++) {
          if (that.data.data.detail[i].detailInfo[j].showSpecific) {
            showSpecificNum++;
          }
        }
        for (var j = 0; j < that.data.data.detail[i].detailInfo.length; j++) {
          // if (detailInfo[i].eNum.indexOf(that.data.data.detail[i].detailInfo[j].eNum) == -1) {
          detailInfo[i].eNum = detailInfo[i].eNum + that.data.data.detail[i].detailInfo[j].eNum + ','
          detailInfo[i].phoneCode = detailInfo[i].phoneCode + that.data.data.detail[i].detailInfo[j].phoneCode + ','
          // }
          if (that.data.data.detail[i].detailInfo[j].showSpecific){
            if (that.data.data.detail[i].detailInfo[j].phoneCode == ''){
              wx.showToast({
                title:'商品串号不能为空',
                icon:'none'
              })
              return
            }
            var arys = {
              'productSerial': that.data.data.detail[i].detailInfo[j].phoneCode,
              'productEnum': that.data.data.detail[i].detailInfo[j].eNum,
              'agentNum': that.data.agent_num
            };
            httpclient.doRequestService('/svc/api/esale/getProductEnumInfo', arys, function (res) {
              if (res.status == "SUCCESS") {
                var resData = res;
                var resInfo = JSON.parse(resData.data)
                if (resInfo.length > 0) {
                  showSpecificNum3++;
                  
                }
              }
            }, null, function () { showSpecificNum2++;})
          }
          
        } 
        for (var j = 0; j < that.data.data.detail[i].detailInfo.length; j++) {
          if (that.data.data.detail[i].detailInfo[j].eNum != '') {
            spbm = true;
            break
          } else {
            spbm = false
          }
        } 
      }
      detailInfo[i].eNum = detailInfo[i].eNum.replace(/,$/,'')
      detailInfo[i].phoneCode = detailInfo[i].phoneCode.replace(/,$/, '')
    }  
    var timer=setInterval(function(){
      if (showSpecificNum === showSpecificNum2) {
        clearInterval(timer)
        if (showSpecificNum !== showSpecificNum3) {
          wx.showToast({
            title: '商品编码和商品串号不对应',
            icon: 'none'
          })
          return
        } else {
          if (!spbm) {
            wx.showToast({
              title: '商品编码不能为空',
              icon: 'none'
            })
            return
          } else {
            var arys = {
              'detailInfo': detailInfo,
              'agentNum': that.data.agent_num
            };
            httpclient.doRequestService('/svc/api/esale/updateEnumSerial', arys, function (res) {
              if (res.status == "SUCCESS") {
                console.log(res)
                wx.showToast({
                  title: '保存成功',
                  icon: 'success'
                })
              }
            }, null, null)
          }
          // 删除空的商品编码
          for (var i = 0; i < that.data.data.detail.length; i++) {
            for (var j = 0; j < that.data.data.detail[i].detailInfo.length; j++) {
              if (that.data.data.detail[i].detailInfo[j].eNum == '') {
                that.data.data.detail[i].detailInfo.splice(j, 1);
                j = j - 1;
              }
            }
          }
          that.setData({
            codeInfo1: false,
            codeInfo2: false,
            codeInfo6: false,
            data: that.data.data
          })
        }

      }
    },50)
    
    

  },
  //扫描成功 手机
  smCodeSuccess:function(code,pIndex,sIndex){
    var that = this;
    var arys = {
      'productSerial': code,
      'productEnum':'',
      'agentNum': that.data.agent_num
    };
    httpclient.doRequestService('/svc/api/esale/getProductEnum', arys, function (res) {
      if (res.status == "SUCCESS") {
        console.log(res)
        console.log(JSON.parse(res.data))
        var resData = res;
        var resInfo = JSON.parse(resData.data)
        if (resInfo.length <= 0) {      
          that.data.data.detail[pIndex].detailInfo[sIndex].eNum = '查询不到所对应的商品编码';
          that.data.data.detail[pIndex].detailInfo[sIndex].phoneCode = code;
          that.setData({
            data: that.data.data
          })
        } else { 
          that.data.data.detail[pIndex].detailInfo[sIndex].eNum = resInfo[0];
          that.data.data.detail[pIndex].detailInfo[sIndex].phoneCode = code;
          that.setData({
            data: that.data.data
          })
        }

      }
    }, null, null)
  },
  // 扫描二维码 手机
  smCode:function(e){
    var that=this;
    var index=e.currentTarget.dataset.index;
    var idx = e.currentTarget.dataset.idx;
    that.setData({
      isSmHide:false
    })
    console.log(index)
    wx.scanCode({
      success(res) {
        console.log(res)
        that.smCodeSuccess(res.result,index,idx)
      }
    })
  },
  //扫描成功 商品
  smCodeSuccess2: function (code, pIndex, sIndex) {
    var that = this;
    var arys = {
      'productSerial': code,
      'productEnum': '',
      'agentNum': that.data.agent_num
    };
    httpclient.doRequestService('/svc/api/esale/getProductEnumInfo', arys, function (res) {
      if (res.status == "SUCCESS") {
        console.log(res)
        console.log(JSON.parse(res.data))
        var resData = res;
        var resInfo = JSON.parse(resData.data)
        that.data.data.detail[pIndex].detailInfo[sIndex].phoneCode = code;
        that.setData({
          data: that.data.data
        })

      }
    }, null, null)
  },
  // 扫描二维码 商品
  smCode2: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var idx = e.currentTarget.dataset.idx;
    that.setData({
      isSmHide: false
    })
    console.log(index)
    wx.scanCode({
      success(res) {
        console.log(res)
        that.data.data.detail[index].detailInfo[idx].phoneCode = res.result;
        that.setData({
          data: that.data.data
        })
      }
    })
  },

  // 分享
  onShareAppMessage: function () {
    return app.onShare()
  }
})
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值