<commit_before>const district = require('../../utils/address_data.js')
const order = require('../../utils/order.js')
const pay = require('../../utils/pay.js')
var app = getApp()

Page({
  data: {
    refreshAddress: true,
    wantToDeleteItem: '',
    address: null,
    cartItems: [],
    amount: 0,
    accountType: '',
    coupon: null,
    address: {}
  },

  onLoad: function (params) {
  },

  onShow: function (params) {
    var that = this
    // 判断要显示什么类型的价格
    if (app.globalData.currentCustomer) {
      var accountType = app.globalData.currentCustomer.account_type
      this.setData({accountType: accountType})
    }

    var cartItems = wx.getStorageSync("cartItems")
    this.setData({cartItems: cartItems || []})

    this.changeCartAmount()

    if (this.data.refreshAddress) {
      var detailAddress  = wx.getStorageSync('detailAddress')
      var receiverName   = wx.getStorageSync('receiverName')
      var receiverMobile = wx.getStorageSync('receiverMobile')
      var address = {detail_address: detailAddress, customer_name: receiverName, customer_mobile: receiverMobile}

      var districtIndex = wx.getStorageSync('currentDistrict') || [1,0,0]
      address.province = district.provinces()[districtIndex[0]]
      that.setData({address: address, refreshAddress: false})
      district.cities(address.province, function(arrayCity){
        address.city = arrayCity[districtIndex[1]]
        that.setData({address: address})
        district.counties(address.province, address.city, function(arrayCounty){
          address.county = arrayCounty[districtIndex[2]]
          that.setData({address: address})
        })
      })
    }
  },

  bindSelectCoupon: function() {
    var product_ids = this.data.cartItems.map(function(ele){return ele.id})
    var products_order_quantities = this.data.cartItems.map(function(ele){return ele.quantity})
    wx.navigateTo({
      url: `coupon?product_ids=${product_ids}&products_order_quantities=${products_order_quantities}`
    })
  },

  bindChangeQuantity: function (e) {
    if (e.detail.value === "") { return "" }

    var cartItems = this.data.cartItems
    var item = cartItems.filter(function(ele){
      return ele.id === e.currentTarget.dataset.id
    })[0]
    if (e.detail.value >= 1) {
      item.quantity = parseInt(e.detail.value)
    } else {
      item.quantity = 1
    }
    this.setData({ cartItems: cartItems })
    wx.setStorage({
      key: 'cartItems',
      data: cartItems
    })
    this.changeCartAmount()
    return item.quantity.toString()
  },

  // tap on item to delete cart item
  catchTapOnItem: function (e) {
    var that = this
    this.setData({
      wantToDeleteItem: e.currentTarget.dataset.id
    })

    wx.showModal({
      title: '删除商品',
      content: '是否要删除购这件商品？',
      confirmText: '删除',
      cancelText: '别删',
      success: function(res) {
        if (res.confirm) {
          var cartItems = that.data.cartItems
          var index = cartItems.findIndex(function(ele){
            return ele.id === that.data.wantToDeleteItem
          })
          cartItems.splice(index, 1)
          that.setData({ cartItems: cartItems })
          wx.setStorage({
            key: 'cartItems',
            data: cartItems
          })
          that.changeCartAmount()
        }
      }
    })
  },

  bindBilling: function () {
    wx.showToast({
      title: '购买中...',
      icon: 'loading',<commit_msg>delete a word<commit_after>const district = require('../../utils/address_data.js')
const order = require('../../utils/order.js')
const pay = require('../../utils/pay.js')
var app = getApp()

Page({
  data: {
    refreshAddress: true,
    wantToDeleteItem: '',
    address: null,
    cartItems: [],
    amount: 0,
    accountType: '',
    coupon: null,
    address: {}
  },

  onLoad: function (params) {
  },

  onShow: function (params) {
    var that = this
    // 判断要显示什么类型的价格
    if (app.globalData.currentCustomer) {
      var accountType = app.globalData.currentCustomer.account_type
      this.setData({accountType: accountType})
    }

    var cartItems = wx.getStorageSync("cartItems")
    this.setData({cartItems: cartItems || []})

    this.changeCartAmount()

    if (this.data.refreshAddress) {
      var detailAddress  = wx.getStorageSync('detailAddress')
      var receiverName   = wx.getStorageSync('receiverName')
      var receiverMobile = wx.getStorageSync('receiverMobile')
      var address = {detail_address: detailAddress, customer_name: receiverName, customer_mobile: receiverMobile}

      var districtIndex = wx.getStorageSync('currentDistrict') || [1,0,0]
      address.province = district.provinces()[districtIndex[0]]
      that.setData({address: address, refreshAddress: false})
      district.cities(address.province, function(arrayCity){
        address.city = arrayCity[districtIndex[1]]
        that.setData({address: address})
        district.counties(address.province, address.city, function(arrayCounty){
          address.county = arrayCounty[districtIndex[2]]
          that.setData({address: address})
        })
      })
    }
  },

  bindSelectCoupon: function() {
    var product_ids = this.data.cartItems.map(function(ele){return ele.id})
    var products_order_quantities = this.data.cartItems.map(function(ele){return ele.quantity})
    wx.navigateTo({
      url: `coupon?product_ids=${product_ids}&products_order_quantities=${products_order_quantities}`
    })
  },

  bindChangeQuantity: function (e) {
    if (e.detail.value === "") { return "" }

    var cartItems = this.data.cartItems
    var item = cartItems.filter(function(ele){
      return ele.id === e.currentTarget.dataset.id
    })[0]
    if (e.detail.value >= 1) {
      item.quantity = parseInt(e.detail.value)
    } else {
      item.quantity = 1
    }
    this.setData({ cartItems: cartItems })
    wx.setStorage({
      key: 'cartItems',
      data: cartItems
    })
    this.changeCartAmount()
    return item.quantity.toString()
  },

  // tap on item to delete cart item
  catchTapOnItem: function (e) {
    var that = this
    this.setData({
      wantToDeleteItem: e.currentTarget.dataset.id
    })

    wx.showModal({
      title: '删除商品',
      content: '是否要删除这件商品？',
      confirmText: '删除',
      cancelText: '别删',
      success: function(res) {
        if (res.confirm) {
          var cartItems = that.data.cartItems
          var index = cartItems.findIndex(function(ele){
            return ele.id === that.data.wantToDeleteItem
          })
          cartItems.splice(index, 1)
          that.setData({ cartItems: cartItems })
          wx.setStorage({
            key: 'cartItems',
            data: cartItems
          })
          that.changeCartAmount()
        }
      }
    })
  },

  bindBilling: function () {
    wx.showToast({
      title: '购买中...',
      icon: 'loading',
{'fraction_non_alphanumeric': 0.13571742635204456, 'fraction_numerical': 0.0032243880990766526, 'mean_word_length': 2.7228587015821057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '722178', 'n_tokens_mistral': 2146, 'n_tokens_neox': 2130, 'n_words': 391}