123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- // pages/ticketBuy/ticketBuy.js
- const utils = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userInfo: '',
- seller: '',
- proList: [{ //产品列表
- price: '',
- taxRate: '',
- taxRateArr: [], // 税率数组
- taxRateArrIndex: 0, //选中税率下标
- noRatePrice: '', //不含税单价
- noRateTotal: '', //不含税金额
- totalMoney: '', //价税合计
- totalRate: '', //合计税额
- quantity: '',
- spreadFlag: false
- }],
- moneyTotal: 0, //价税合计
- noRateTotal: 0, //合计金额(不含税)
- rateTotal: 0, //合计税额
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getUser()
- },
- //销方信息
- getUser() {
- this.setData({
- userInfo: utils.getInfo(),
- seller:utils.getCurrEntInfo()
- })
- // utils.getCompany().then(res => {
- // this.setData({
- // seller: res.data
- // })
- // })
- },
- //提交开票
- submitData() {
- //产品信息
- let proList = this.data.proList
- let proListSubmit = []
- for (let i = 0; i < proList.length; i++) {
- if (proList[i].totalMoney && proList[i].productName) {
- proListSubmit.push(proList[i])
- }
- }
- let COMMON_FPKJ_XMXX = []
- if (proListSubmit.length <= 0) {
- utils.toast('商品信息不能为空')
- return
- } else {
- for (let i = 0; i < proListSubmit.length; i++) {
- let item = {
- "FPHXZ": 0,
- "SPBM": proListSubmit[i].taxationCateCode,
- "ZXBM": '',
- "YHZCBS": proListSubmit[i].preferentialFlag,
- "LSLBS": proListSubmit[i].zeroRateFlag,
- "ZZSTSGL": proListSubmit[i].preferentialType,
- "XMMC": proListSubmit[i].productName,
- "GGXH": proListSubmit[i].specsModel,
- "DW": proListSubmit[i].unit,
- "XMJE": proListSubmit[i].noRateTotal,
- "SL": proListSubmit[i].taxRate,
- "SE": proListSubmit[i].totalRate
- }
- // 如果数量为存在并且不为0则传递参数
- if (proListSubmit[i].quantity) {
- item.XMSL = proListSubmit[i].quantity
- }
- // 如果不含税单价存在(为0也可以)则传递参数
- if (proListSubmit[i].noRatePrice !== '') {
- item.XMDJ = proListSubmit[i].noRatePrice
- }
- COMMON_FPKJ_XMXX.push(item)
- }
- }
- //要传递的参数
- let params = {
- mobile: this.data.userInfo.mobile,
- reqChannel: 5,
- cmdParam: {
- "REQUEST_COMMON_FPKJ": {
- "KPLX": "0",
- "FPZL": 1,
- "KPF_NSRSBH": this.data.seller.entTaxId,
- "KPF_MC": this.data.seller.entName,
- "KPF_DZ": this.data.seller.entAddress,
- "KPF_DH": this.data.seller.entPhone,
- "KPF_YHZH": this.data.seller.bankAccountNumber,
- "KPF_KHHMC": this.data.seller.bankName,
- "KPR": this.data.seller.entName,
- "SKR": this.data.seller.payees,
- "FHR": this.data.seller.reviewers,
- "JSHJ": this.data.moneyTotal,
- "HJJE": this.data.noRateTotal,
- "HJSE": this.data.rateTotal,
- "TSPZ": "00",
- "COMMON_FPKJ_XMXXS": {
- "COMMON_FPKJ_XMXX": COMMON_FPKJ_XMXX
- }
- }
- }
- }
- utils.axios({
- method: 'post',
- url: '/sys/fapiao/todo/initSave',
- data: params,
- sendBefore() {
- wx.showLoading({
- title: '提交中...',
- mask: true
- })
- },
- complete() {
- wx.hideLoading()
- },
- success: res => {
- wx.navigateTo({
- url: `/pages/ticketBuy/qrcode?recordId=${res.data.recordId}`
- })
- }
- })
- },
- //计算发票总金额、总税额
- calcMoney() {
- console.log("数据");
- console.log(this.data.proList);
- let list = this.data.proList
- let moneyTotal = 0
- let noRateTotal = 0
- let rateTotal = 0
- for (let i = 0; i < list.length; i++) {
- //计算不含税单价、不含税项目金额、价税合计金额
- if (list[i].price !== null && list[i].price !== '' && list[i].quantity) {
- list[i].noRatePrice = parseFloat(list[i].price / (1 + (list[i].taxRate ? list[i].taxRate : 0))).toFixed(6)
- list[i].noRateTotal = parseFloat(list[i].noRatePrice * (list[i].quantity ? list[i].quantity : 0)).toFixed(2)
- list[i].totalMoney = parseFloat(list[i].price * (list[i].quantity ? list[i].quantity : 0)).toFixed(2)
- //税额计算公式:价税合计金额/(1+税率)*税率
- list[i].totalRate = parseFloat(list[i].totalMoney / (1 + (list[i].taxRate ? list[i].taxRate : 0)) * (list[i].taxRate ? list[i].taxRate : 0)).toFixed(2)
- } else {
- list[i].totalMoney = 0
- list[i].noRateTotal = 0
- list[i].totalRate = 0
- }
- //总的相加
- moneyTotal += Number(list[i].totalMoney)
- noRateTotal += Number(list[i].noRateTotal)
- rateTotal += Number(list[i].totalRate)
- }
- this.setData({
- moneyTotal: parseFloat(moneyTotal).toFixed(2),
- noRateTotal: parseFloat(noRateTotal).toFixed(2),
- rateTotal: parseFloat(rateTotal).toFixed(2),
- proList: list
- })
- },
- getTotalMoney(e) {
- let moneyTotal = 0
- let noRateTotal = 0
- let rateTotal = 0
- let list = this.data.proList
- let index = Number(e.currentTarget.dataset.index)
- let totalMoney = e.detail.value
- list[index].totalMoney = parseFloat(Number(totalMoney)).toFixed(2)
- if (list[index].quantity) {
- list[index].price = list[index].totalMoney / list[index].quantity
- list[index].noRatePrice = parseFloat(list[index].price / (1 + (list[index].taxRate ? list[index].taxRate : 0))).toFixed(6)
- } else {
- list[index].price = ''
- list[index].noRatePrice = ''
- }
- for (let i = 0; i < list.length; i++) {
- //计算不含税单价、不含税项目金额、价税合计金额
- if (list[i].totalMoney) {
- list[i].noRateTotal = parseFloat(list[i].totalMoney / (1 + (list[i].taxRate ? list[i].taxRate : 0))).toFixed(2)
- if (i !== index) {
- list[i].totalMoney = parseFloat(list[i].price * (list[i].quantity ? list[i].quantity : 0)).toFixed(2)
- }
- //税额计算公式:价税合计金额/(1+税率)*税率
- list[i].totalRate = parseFloat(list[i].totalMoney / (1 + (list[i].taxRate ? list[i].taxRate : 0)) * (list[i].taxRate ? list[i].taxRate : 0)).toFixed(2)
- }
- //总的相加
- moneyTotal += Number(list[i].totalMoney)
- noRateTotal += Number(list[i].noRateTotal)
- rateTotal += Number(list[i].totalRate)
- }
- this.setData({
- moneyTotal: parseFloat(moneyTotal).toFixed(2),
- noRateTotal: parseFloat(noRateTotal).toFixed(2),
- rateTotal: parseFloat(rateTotal).toFixed(2),
- proList: list
- })
- },
- //查询商品
- toSearchPro(e) {
- let index = e.currentTarget.dataset.index
- wx.navigateTo({
- url: `/pages/searchPro/searchPro?index=${index}`
- })
- },
- //添加商品
- addTicket() {
- let proList = this.data.proList
- proList.push({
- price: '',
- taxRate: '',
- taxRateArr: [],
- taxRateArrIndex: 0,
- noRatePrice: '',
- noRateTotal: '',
- totalMoney: '',
- totalRate: '',
- quantity: '',
- spreadFlag: false
- })
- this.setData({
- proList
- })
- },
- // 获取商品编号税率
- getTaxRate(prevIndex, taxCateCode, taxRate) {
- let params = {
- taxCateCode,
- entTaxId: wx.getStorageSync('entTaxId')
- }
- utils.axios({
- method: 'get',
- url: '/sys/entInfo/rates',
- data: params,
- sendBefore() {},
- complete() {},
- success: res => {
- let index = prevIndex
- let proList = this.data.proList
- let result = res.data
- for (let i = 0; i < result.length; i++) {
- result[i] = Number(result[i])
- if (result[i] === taxRate) {
- proList[prevIndex].taxRateArrIndex = i
- }
- }
- proList[prevIndex].taxRateArr = result
- this.setData({
- proList
- })
- this.calcMoney()
- }
- })
- },
- setRate(e) {
- let index = e.currentTarget.dataset.index
- let proList = this.data.proList
- proList[index].taxRateArrIndex = e.detail.value
- proList[index].taxRate = proList[index].taxRateArr[proList[index].taxRateArrIndex]
- this.setData({
- proList
- })
- this.calcMoney()
- },
- //单个商品展开收起
- spread(e) {
- let index = e.currentTarget.dataset.index
- this.setData({
- [`proList[${index}].spreadFlag`]: !this.data.proList[index].spreadFlag
- })
- },
- delete(e) {
- let index = e.currentTarget.dataset.index
- let proList = this.data.proList
- proList.splice(index, 1)
- this.setData({
- proList
- })
- this.calcMoney()
- },
- //购物车加
- add(e) {
- let proList = this.data.proList
- let index = e.currentTarget.dataset.index
- let curNum = proList[index].quantity
- curNum++
- let str = 'proList[' + index + '].quantity'
- this.setData({
- [str]: curNum
- })
- this.calcMoney()
- },
- //购物车减
- minus(e) {
- let proList = this.data.proList
- let index = e.currentTarget.dataset.index
- let curNum = proList[index].quantity
- curNum--
- if (curNum <= 1) {
- curNum = 1
- }
- let str = 'proList[' + index + '].quantity'
- this.setData({
- [str]: curNum
- })
- this.calcMoney()
- },
- //input输入框
- inputNum(e) {
- let index = e.currentTarget.dataset.index
- let str = 'proList[' + index + '].quantity'
- this.setData({
- [str]: Number(e.detail)
- })
- this.calcMoney()
- },
- getPrice(e) {
- console.log(e);
- let index = e.currentTarget.dataset.index
- let str = 'proList[' + index + '].price'
- this.setData({
- [str]: Number(e.detail.value)
- })
- this.calcMoney()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: '诺信云',
- path: '/pages/index/index'
- }
- }
- })
|