| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- /*******************************************************************************
- * Copyright(c) 2022 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:开具发票
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王英杰 2022-11-22 1.00 新建
- *******************************************************************************/
- const mixins = require('@/mixins/index.js')
- const util = require('@/utils/util.js')
- const Constants = require('@/utils/Constants.js');
- const api = require('@/utils/api.js');
- const config = require('@/config/config.js');
- const app = getApp()
- Page({
- mixins: [mixins],
- /**
- * 页面的初始数据
- */
- data: {
- cardList: ['main', 'other'],
- contentObj: {
- main: [{ //抬头类型
- code: 'headType',
- type: 'str',
- readonly: true,
- title: mixins.$t('headType')
- },
- { //购方名称
- code: 'cpId',
- name: 'cpName',
- title: mixins.$t("buyerName"),
- type: 'choose',
- urlKey: 'invoiceType',
- required: true,
- },
- { //购方税号
- code: 'taxNo',
- type: 'str',
- required: true,
- title: mixins.$t('BuyerTaxNumber')
- },
- { //发票类型
- code: 'receiptType',
- name: 'receiptTypeName',
- title: mixins.$t("invoiceType"),
- type: 'drop',
- dropType: 'receiptType',
- required: true,
- },
- { //接收邮箱
- code: 'cpEmail',
- type: 'email',
- required: true,
- title: mixins.$t('receivingEmail')
- },
- { //备注
- code: 'remarks',
- type: 'str',
- title: mixins.$t('remarks')
- },
- ],
- other: [ //备注
- {
- code: 'receiptContent',
- type: 'textarea',
- title: mixins.$t('invoiceContent')
- },
- {
- code: 'receiptObj',
- type: 'textarea',
- title: mixins.$t('invoicingParty')
- },
- {
- code: 'totalInvoiceAmount',
- type: 'number',
- readonly: true,
- title: mixins.$t('totalInvoiceAmount')
- }
- ],
- },
- buttonSaveList: [
- // {
- // code: 'preview',
- // title: '预览',
- // width: '120rpx',
- // },
- {
- code: 'submit',
- title: '提交',
- width: '120rpx',
- }],
- receiptSetService: app.globalData['receiptSetService'], //发票抬头
- receiptFitService: app.globalData['receiptFitService'], //发票设置
- // 路由
- routeObjName: 'receipt',
- },
- /**
- * @desc : 页面加载数据方法
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- loadInit() {
- let formData = this.data.formData ? JSON.parse(this.data.formData) : {}
- formData.headType = "企业单位"
- formData.totalInvoiceAmount = this.data.item.sum("tradeAmount")
- let tradeList = this.data.item
- this.setData({
- formData: JSON.stringify(formData),
- tradeList: tradeList,
- })
- this.getReceiptFit()
- this.getReceiptSit()
- },
- /**
- * @desc : 获取开票设置
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- getReceiptFit() {
- let that = this
- let params = {}
- params.flgDefault = true
- params.cpId = app.globalData.user.cpId
- that.excute(that.data.receiptFitService, that.data.receiptFitService.selectByCond,params).then(res => {
- if (res.data.code == 200) {
- let formData = JSON.parse(that.data.formData)
- if (res.data.data && res.data.data.length > 0) {
- formData.fitId = res.data.data[0].fitId
- formData.receiptContent = res.data.data[0].receiptContent
- formData.receiptObj = res.data.data[0].receiptObj
- formData.receiptStaff = res.data.data[0].receiptStaff
- formData.taxRateNormal = res.data.data[0].taxRateNormal
- formData.taxRateSpecial = res.data.data[0].taxRateSpecial
- }
- //设置默认值
- that.setData({
- formData: JSON.stringify(formData)
- })
- }
- })
- },
- /**
- * @desc : 获取默认发票抬头
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- getReceiptSit() {
- let that = this
- that.excute(that.data.receiptSetService, that.data.receiptSetService.selectByCond, {
- flgDefault: true
- }).then(res => {
- if (res.data.code == 200) {
- let formData = JSON.parse(that.data.formData)
- if (res.data.data && res.data.data.length > 0) {
- formData.cpId =res.data.data[0].cpId
- formData.cpName =res.data.data[0].cpName
- formData.setId =res.data.data[0].setId
- formData.taxNo = res.data.data[0].taxNo
- formData.cpEmail = res.data.data[0].cpEmail
- }
- //设置默认值
- that.setData({
- formData: JSON.stringify(formData)
- })
- }
- })
- },
- /**
- * @desc : 绑定数据-选择页面返回的逻辑处理
- * @author : 王英杰
- * @date : 2024年3月12日
- */
- chooseData(e) {
- let formData = JSON.parse(this.data.formData)
- let code = e.detail.code
- let data = e.detail.data.data
- if (code == "cpId") { //公司名称
- formData.cpId = data.id
- formData.cpName = data.name
- formData.setId = data.setId
- formData.taxNo = data.taxNo
- formData.cpEmail = data.cpEmail
- }
- if (code == "receiptType") { //发票类型
- formData.receiptType = data.id
- formData.receiptTypeName = data.name
- }
- this.setData({
- formData: JSON.stringify(formData)
- })
- },
- /**
- * @desc : 底部按钮 监听
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- saveButton(e) {
- let name = e.detail.name
- if (name == 'preview') { //预览
- } else if (name == 'submit') { //提交
- this.save({})
- }
- },
- /**
- * @desc : 保存的參數設置
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- setParams(params) {
- params.tradeList = this.data.tradeList
- params.receiptSetId = params.setId //发票设置ID
- params.receiptStatus = "发票状态-申请" //发票状态
- params.receiptType = params.receiptType //发票类型
- params.applyStaff = app.globalData.user.staffName //申请人
- params.applyDate = util.formatDayTime(new Date()) //申请日期
- params.cpId = params.cpId //公司Id
- params.cpName = params.cpName //公司名称
- params.taxNo = params.taxNo //公司税号
- params.cpEmail = params.cpEmail //电子邮箱
- params.receiptAmt = params.totalInvoiceAmount //发票金额
- params.receiptContent = params.receiptContent //发票内容
- params.receiptObj = params.receiptObj //开票方名称
- params.taxRate = params.receiptType == "发票类型-普票" ? params.taxRateNormal : params.taxRateSpecial //税率
- params.remarks = params.remarks //备注
- console.log("params", params);
- return params
- },
- /**
- * @desc : 保存数据服务
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- saveData() {
- let pages = getCurrentPages();
- let prevPage = pages[pages.length - 2];
- prevPage.setData({
- refreshByAdd: true,
- })
-
- let prevPage3 = pages[pages.length - 3];
- prevPage3.setData({
- refreshByAdd: true,
- })
- return this.excute(this.data.service, this.data.service.insert, this.data.params);
- },
- })
|