orderdetail.js 8.0 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
// pages/orderdetail/orderdetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalmoney: 0,
    orderlist: [],
    morenaddress: '',
    customer_id: '',
    order_id: [],
    amount: [],
    prepage:'',
    que:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
   
  },

  //获取订单列表
  getorderlist() {
    let that = this;
    let url = 'index/getOrderList';

    app.post(url, '', 'get').then((res) => {
      console.log(res);

      that.setData({
        orderlist: res.data,
        totalmoney: res.total_price.toFixed("2")
      })

      let neworderlist = that.data.orderlist;
      let orderid = [];
      let goodnum = [];

      for (var obj of neworderlist) {
        orderid.push(obj.id);
        goodnum.push(obj.amount)
      }

      that.setData({
        order_id: orderid,
        amount: goodnum
      })

    }).catch((err) => {


    })
  },

  //进入客户列表页面
  gokehu(){
    wx.navigateTo({
      url: '/pages/mykehu/mykehu',
    })
  },

  //获取默认地址
  getmorenaddress() {
    let that = this;
    let url = 'user/getCustomerList';
    let param = {
      page: 1,
      is_default: 1
    }

    app.post(url, param, 'get').then((res) => {
      console.log(res);

      that.setData({
        morenaddress: res[0],
        customer_id: res[0].id
      })



    }).catch((err) => {


    })
  },

  //输入折扣率
  enterzhekou(e) {
    if (e.detail.value > 1) {
      wx.showToast({
        title: '请输入0-1之间的数字',
        icon: 'none'
      })


    } else {
      let totalqian=0;
      let id = e.currentTarget.dataset.id;
      let neworderlist = this.data.orderlist;
      for (var obj of neworderlist) {
        if (obj.goods_id == id) {
          obj.discount = e.detail.value;
          //let dis_price = Number(obj.price) *Number(obj.amount)* Number(e.detail.value);
          let dis_price = Number(obj.price)*Number(e.detail.value);
          obj.dis_price = dis_price.toFixed("2"); 
        }
        totalqian = totalqian + Number(obj.dis_price)*Number(obj.amount);
      }

      
      totalqian = totalqian.toFixed("2")

      this.setData({
        orderlist: neworderlist,
        totalmoney: totalqian
      })

      wx.setStorageSync("orderarr", neworderlist)
    }

  },

  //输入折扣价格
  enterzhekouprice(e) {
    let id = e.currentTarget.dataset.id;
    let neworderlist = this.data.orderlist;
    let totalqian = 0;
    for (var obj of neworderlist) {
      if (obj.goods_id == id) {
        obj.dis_price = e.detail.value;
        let zhekou=Number(e.detail.value)/Number(obj.price);
        zhekou=zhekou.toFixed("2");
        obj.discount=zhekou;
      }

      totalqian = totalqian + Number(obj.dis_price)*Number(obj.amount);
    }

    this.setData({
      orderlist: neworderlist,
      totalmoney: totalqian
    })

    wx.setStorageSync("orderarr", neworderlist)

    console.log(this.data.orderlist)
  },
  //输入开发票名称
  enterfaname(e) {
    let id = e.currentTarget.dataset.id;
    let neworderlist = this.data.orderlist;
    for (var obj of neworderlist) {
      if (obj.goods_id== id) {
        obj.invoice_name = e.detail.value
      }
    }

    this.setData({
      orderlist: neworderlist
    })
    wx.setStorageSync("orderarr", neworderlist) 
  },

  //输入备注
  entermark(e) {
    let id = e.currentTarget.dataset.id;
    let neworderlist = this.data.orderlist;
    for (var obj of neworderlist) {
      if (obj.goods_id == id) {
        obj.mark = e.detail.value
      }
    }

    this.setData({
      orderlist: neworderlist
    })
    wx.setStorageSync("orderarr", neworderlist)
  },

  //确定提交订单
  quedingti() {
    let that=this;

    console.log(that.data.customer_id)

    if (that.data.customer_id==''){
      wx.showToast({
        title: '请选择地址',
        icon:'none'
      })

      return false
    }
    let neworderlist = this.data.orderlist;
    for (var obj of neworderlist) {
      if (obj.discount == '') {
        wx.showToast({
          title: '请把折扣率填写完整',
          icon: 'none'
        })

        return false
      } else if (obj.dis_price == '') {
        wx.showToast({
          title: '请把折扣率填写完整',
          icon: 'none'
        })

        return false
      } else if (obj.invoice_name==''){
        wx.showToast({
          title: '请把开发票品名填写完整',
          icon: 'none'
        })
        return false

      } 
      
      
      

       

     
    }

    that.setData({
      que:""
    })


    let newdiscount = [];
    let newdis_price = [];
    let newinvoice_name = [];
    let newmark = [];
    for (var obj of neworderlist) {
      console.log(obj.mark)
      newdiscount.push(obj.discount);
      newdis_price.push(obj.dis_price);
      newinvoice_name.push(obj.invoice_name);
      newmark.push(obj.mark)
    }

    if (newmark.length==0){
      newmark=''
    }else{
      for(var i=0;i<newmark.length;i++){
        if (newmark[i]==''){
          newmark[i]=0
          }
      }
    }

    console.log(newmark)

    

    let url = 'index/confirmOrder';
    let param = {
      customer_id: that.data.customer_id,
      goods_id: that.data.order_id.join(","),
      amount: that.data.amount.join(","),
      discount: newdiscount.join(","),
      dis_price: newdis_price.join(","),
      invoice_name: newinvoice_name.join(","),
      mark: newmark.join(",")

    }

    console.log(param)

    app.post(url, param, 'post').then((res) => {
      console.log(res);

      // wx.showToast({
      //   title: '提交成功',
      //   icon: "none"
      // })
      wx.setStorageSync('orderarr', '');
      wx.setStorageSync('total_price', '');

      // wx.clearStorage("orderarr");
      // wx.clearStorage("total_price");
      that.clearcart()


      setTimeout(function(){
          wx.navigateTo({
            url: '/pages/myorder/myorder',
          })
      },200)

    }).catch((err) => {

      console.log(err)
    })


  },

  //提交订单清除购物车
  clearcart() {
    let that = this;
    let newcartidarr = this.data.order_id;

    let url = 'index/delCar';
    let param = {
      goods_id: newcartidarr.join(","),

    }

    app.post(url, param, 'get').then((res) => {
      console.log(res);

    }).catch((err) => {

    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that=this;

    let xinorderlist=wx.getStorageSync("orderlist");
    console.log('000888', xinorderlist)
    // if (xinorderlist!=''){
    //   this.setData({
    //     orderlist:xinorderlist
    //   })
    // }

    let neworderlist = wx.getStorageSync("orderarr");
    let newtotal_price = wx.getStorageSync("total_price")
    console.log(neworderlist)
    let orderid = [];
    let goodnum = [];

    for (var obj of neworderlist) {
      console.log('00099978', typeof(obj.dis_price));
      obj.dis_price = Number(obj.dis_price)
      obj.dis_price=obj.dis_price.toFixed("2")
      orderid.push(obj.goods_id);
      goodnum.push(obj.amount)
    }

    that.setData({
      orderlist:neworderlist,
      totalmoney: newtotal_price,
      order_id: orderid,
      amount: goodnum
    })

    let pages = getCurrentPages();

    let currPage = pages[pages.length - 1]; //当前页面

    if (currPage.data.prepage==1){
      this.setData({
        morenaddress: currPage.data.morenaddress,
        customer_id: currPage.data.morenaddress.id
      })
    }else{
      this.getmorenaddress();
    }

   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})