add.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:开具发票
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王英杰 2022-11-22 1.00 新建
  9. *******************************************************************************/
  10. const mixins = require('@/mixins/index.js')
  11. const util = require('@/utils/util.js')
  12. const Constants = require('@/utils/Constants.js');
  13. const api = require('@/utils/api.js');
  14. const config = require('@/config/config.js');
  15. const app = getApp()
  16. Page({
  17. mixins: [mixins],
  18. /**
  19. * 页面的初始数据
  20. */
  21. data: {
  22. cardList: ['main', 'other'],
  23. contentObj: {
  24. main: [{ //抬头类型
  25. code: 'headType',
  26. type: 'str',
  27. readonly: true,
  28. title: mixins.$t('headType')
  29. },
  30. { //购方名称
  31. code: 'cpId',
  32. name: 'cpName',
  33. title: mixins.$t("buyerName"),
  34. type: 'choose',
  35. urlKey: 'invoiceType',
  36. required: true,
  37. },
  38. { //购方税号
  39. code: 'taxNo',
  40. type: 'str',
  41. required: true,
  42. title: mixins.$t('BuyerTaxNumber')
  43. },
  44. { //发票类型
  45. code: 'receiptType',
  46. name: 'receiptTypeName',
  47. title: mixins.$t("invoiceType"),
  48. type: 'drop',
  49. dropType: 'receiptType',
  50. required: true,
  51. },
  52. { //接收邮箱
  53. code: 'cpEmail',
  54. type: 'email',
  55. required: true,
  56. title: mixins.$t('receivingEmail')
  57. },
  58. { //备注
  59. code: 'remarks',
  60. type: 'str',
  61. title: mixins.$t('remarks')
  62. },
  63. ],
  64. other: [ //备注
  65. {
  66. code: 'receiptContent',
  67. type: 'textarea',
  68. title: mixins.$t('invoiceContent')
  69. },
  70. {
  71. code: 'receiptObj',
  72. type: 'textarea',
  73. title: mixins.$t('invoicingParty')
  74. },
  75. {
  76. code: 'totalInvoiceAmount',
  77. type: 'number',
  78. readonly: true,
  79. title: mixins.$t('totalInvoiceAmount')
  80. }
  81. ],
  82. },
  83. buttonSaveList: [
  84. // {
  85. // code: 'preview',
  86. // title: '预览',
  87. // width: '120rpx',
  88. // },
  89. {
  90. code: 'submit',
  91. title: '提交',
  92. width: '120rpx',
  93. }],
  94. receiptSetService: app.globalData['receiptSetService'], //发票抬头
  95. receiptFitService: app.globalData['receiptFitService'], //发票设置
  96. // 路由
  97. routeObjName: 'receipt',
  98. },
  99. /**
  100. * @desc : 页面加载数据方法
  101. * @date : 2024/2/1 15:49
  102. * @author : 王英杰
  103. */
  104. loadInit() {
  105. let formData = this.data.formData ? JSON.parse(this.data.formData) : {}
  106. formData.headType = "企业单位"
  107. formData.totalInvoiceAmount = this.data.item.sum("tradeAmount")
  108. let tradeList = this.data.item
  109. this.setData({
  110. formData: JSON.stringify(formData),
  111. tradeList: tradeList,
  112. })
  113. this.getReceiptFit()
  114. this.getReceiptSit()
  115. },
  116. /**
  117. * @desc : 获取开票设置
  118. * @date : 2024/2/1 15:49
  119. * @author : 王英杰
  120. */
  121. getReceiptFit() {
  122. let that = this
  123. let params = {}
  124. params.flgDefault = true
  125. params.cpId = app.globalData.user.cpId
  126. that.excute(that.data.receiptFitService, that.data.receiptFitService.selectByCond,params).then(res => {
  127. if (res.data.code == 200) {
  128. let formData = JSON.parse(that.data.formData)
  129. if (res.data.data && res.data.data.length > 0) {
  130. formData.fitId = res.data.data[0].fitId
  131. formData.receiptContent = res.data.data[0].receiptContent
  132. formData.receiptObj = res.data.data[0].receiptObj
  133. formData.receiptStaff = res.data.data[0].receiptStaff
  134. formData.taxRateNormal = res.data.data[0].taxRateNormal
  135. formData.taxRateSpecial = res.data.data[0].taxRateSpecial
  136. }
  137. //设置默认值
  138. that.setData({
  139. formData: JSON.stringify(formData)
  140. })
  141. }
  142. })
  143. },
  144. /**
  145. * @desc : 获取默认发票抬头
  146. * @date : 2024/2/1 15:49
  147. * @author : 王英杰
  148. */
  149. getReceiptSit() {
  150. let that = this
  151. that.excute(that.data.receiptSetService, that.data.receiptSetService.selectByCond, {
  152. flgDefault: true
  153. }).then(res => {
  154. if (res.data.code == 200) {
  155. let formData = JSON.parse(that.data.formData)
  156. if (res.data.data && res.data.data.length > 0) {
  157. formData.cpId =res.data.data[0].cpId
  158. formData.cpName =res.data.data[0].cpName
  159. formData.setId =res.data.data[0].setId
  160. formData.taxNo = res.data.data[0].taxNo
  161. formData.cpEmail = res.data.data[0].cpEmail
  162. }
  163. //设置默认值
  164. that.setData({
  165. formData: JSON.stringify(formData)
  166. })
  167. }
  168. })
  169. },
  170. /**
  171. * @desc : 绑定数据-选择页面返回的逻辑处理
  172. * @author : 王英杰
  173. * @date : 2024年3月12日
  174. */
  175. chooseData(e) {
  176. let formData = JSON.parse(this.data.formData)
  177. let code = e.detail.code
  178. let data = e.detail.data.data
  179. if (code == "cpId") { //公司名称
  180. formData.cpId = data.id
  181. formData.cpName = data.name
  182. formData.setId = data.setId
  183. formData.taxNo = data.taxNo
  184. formData.cpEmail = data.cpEmail
  185. }
  186. if (code == "receiptType") { //发票类型
  187. formData.receiptType = data.id
  188. formData.receiptTypeName = data.name
  189. }
  190. this.setData({
  191. formData: JSON.stringify(formData)
  192. })
  193. },
  194. /**
  195. * @desc : 底部按钮 监听
  196. * @date : 2024/2/1 15:49
  197. * @author : 王英杰
  198. */
  199. saveButton(e) {
  200. let name = e.detail.name
  201. if (name == 'preview') { //预览
  202. } else if (name == 'submit') { //提交
  203. this.save({})
  204. }
  205. },
  206. /**
  207. * @desc : 保存的參數設置
  208. * @date : 2024/2/1 15:49
  209. * @author : 王英杰
  210. */
  211. setParams(params) {
  212. params.tradeList = this.data.tradeList
  213. params.receiptSetId = params.setId //发票设置ID
  214. params.receiptStatus = "发票状态-申请" //发票状态
  215. params.receiptType = params.receiptType //发票类型
  216. params.applyStaff = app.globalData.user.staffName //申请人
  217. params.applyDate = util.formatDayTime(new Date()) //申请日期
  218. params.cpId = params.cpId //公司Id
  219. params.cpName = params.cpName //公司名称
  220. params.taxNo = params.taxNo //公司税号
  221. params.cpEmail = params.cpEmail //电子邮箱
  222. params.receiptAmt = params.totalInvoiceAmount //发票金额
  223. params.receiptContent = params.receiptContent //发票内容
  224. params.receiptObj = params.receiptObj //开票方名称
  225. params.taxRate = params.receiptType == "发票类型-普票" ? params.taxRateNormal : params.taxRateSpecial //税率
  226. params.remarks = params.remarks //备注
  227. console.log("params", params);
  228. return params
  229. },
  230. /**
  231. * @desc : 保存数据服务
  232. * @date : 2024/2/1 15:49
  233. * @author : 王英杰
  234. */
  235. saveData() {
  236. let pages = getCurrentPages();
  237. let prevPage = pages[pages.length - 2];
  238. prevPage.setData({
  239. refreshByAdd: true,
  240. })
  241. let prevPage3 = pages[pages.length - 3];
  242. prevPage3.setData({
  243. refreshByAdd: true,
  244. })
  245. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  246. },
  247. })