index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* eslint-disable no-nested-ternary */
  2. import Dialog from 'tdesign-miniprogram/dialog/index';
  3. import Toast from 'tdesign-miniprogram/toast/index';
  4. import { dispatchSupplementInvoice } from '../../../services/order/orderConfirm';
  5. const invoiceJson = {
  6. info: [
  7. '1.根据当地税务局的要求,开具有效的企业发票需填写税务局登记证号。开具个人发票不需要填写纳税人识别码。 ',
  8. '2.电子普通发票: 电子普通发票是税局认可的有效首付款凭证,其法律效力、基本用途及使用规定同纸质发票,如需纸质发票可自行下载打印。 ',
  9. '3.增值税专用发票: 增值税发票暂时不可开,可查看《开局增值税发票》或致电400-633-6868。',
  10. ],
  11. codeTitle: [
  12. '1.什么是纳税人识别号/统一社会信用代码? 纳税人识别号,一律由15位、17位、18或者20位码(字符型)组成,其中:企业、事业单位等组织机构纳税人,以国家质量监督检验检疫总局编制的9位码(其中区分主码位与校检位之间的“—”符省略不打印)并在其“纳税人识别号”。国家税务总局下达的纳税人代码为15位,其中:1—2位为省、市代码,3—6位为地区代码,7—8位为经济性质代码,9—10位行业代码,11—15位为各地区自设的顺序码。',
  13. '2.入户获取/知晓纳税人识别号/统一社会信用代码? 纳税人识别号是税务登记证上的号码,通常简称为“税号”,每个企业的纳税人识别号都是唯一的。这个属于每个人自己且终身不变的数字代码很可能成为我们的第二张“身份证”。 ',
  14. ],
  15. };
  16. Page({
  17. orderNo: '',
  18. data: {
  19. receiptIndex: 0,
  20. addressTagsIndex: 0,
  21. goodsClassesIndex: 0,
  22. dialogShow: false,
  23. codeShow: false,
  24. receipts: [
  25. { title: '不开发票', id: 0, name: 'receipt' },
  26. { title: '电子发票', id: 1, name: 'receipt' },
  27. ],
  28. addressTags: [
  29. { title: '个人', id: 0, name: 'addressTags', type: 1 },
  30. { title: '公司', id: 1, name: 'addressTags', type: 2 },
  31. ],
  32. goodsClasses: [
  33. { title: '商品明细', id: 0, name: 'goodsClasses' },
  34. { title: '商品类别', id: 1, name: 'goodsClasses' },
  35. ],
  36. name: '',
  37. componentName: '',
  38. code: '',
  39. phone: '',
  40. email: '',
  41. invoiceInfo: invoiceJson,
  42. },
  43. onLoad(query) {
  44. const { orderNo, invoiceData } = query;
  45. const tempData = JSON.parse(invoiceData || '{}');
  46. const invoice = {
  47. receiptIndex: tempData.invoiceType === 5 ? 1 : 0,
  48. name: tempData.buyerName || '',
  49. email: tempData.email || '',
  50. phone: tempData.buyerPhone || '',
  51. addressTagsIndex: tempData.titleType === 2 ? 1 : 0,
  52. goodsClassesIndex: tempData.contentType === 2 ? 1 : 0,
  53. code: tempData.buyerTaxNo || '',
  54. componentName: tempData.titleType === 2 ? tempData.buyerName : '',
  55. };
  56. this.orderNo = orderNo;
  57. this.setData({ ...invoice });
  58. },
  59. onLabels(e) {
  60. const { item } = e.currentTarget.dataset;
  61. const nameIndex = `${item.name}Index`;
  62. this.setData({ [nameIndex]: item.id });
  63. },
  64. onInput(e) {
  65. const { addressTagsIndex } = this.data;
  66. const { item } = e.currentTarget.dataset;
  67. const { value } = e.detail;
  68. const key =
  69. item === 'name'
  70. ? addressTagsIndex === 0
  71. ? 'name'
  72. : 'componentName'
  73. : item === 'code'
  74. ? addressTagsIndex === 0
  75. ? 'phone'
  76. : 'code'
  77. : 'email';
  78. this.setData({ [key]: value });
  79. },
  80. onSure() {
  81. const result = this.checkSure();
  82. if (!result) {
  83. Dialog.alert({
  84. title: '请填写发票信息',
  85. content: '',
  86. confirmBtn: '确认',
  87. });
  88. return;
  89. }
  90. const {
  91. receiptIndex,
  92. addressTagsIndex,
  93. receipts,
  94. addressTags,
  95. name,
  96. componentName,
  97. code,
  98. phone,
  99. email,
  100. goodsClassesIndex,
  101. } = this.data;
  102. const data = {
  103. buyerName: addressTagsIndex === 0 ? name : componentName,
  104. buyerTaxNo: code,
  105. buyerPhone: phone,
  106. email,
  107. titleType: addressTags[addressTagsIndex].type,
  108. contentType: goodsClassesIndex === 0 ? 1 : 2,
  109. invoiceType: receiptIndex === 1 ? 5 : 0,
  110. };
  111. if (this.orderNo) {
  112. if (this.submitting) return;
  113. const params = {
  114. parameter: {
  115. orderNo: this.orderNo,
  116. invoiceVO: data,
  117. },
  118. };
  119. this.submitting = true;
  120. dispatchSupplementInvoice(params)
  121. .then(() => {
  122. Toast({
  123. context: this,
  124. selector: '#t-toast',
  125. message: '保存成功',
  126. duration: 2000,
  127. icon: '',
  128. });
  129. setTimeout(() => {
  130. this.submitting = false;
  131. wx.navigateBack({ delta: 1 });
  132. }, 1000);
  133. })
  134. .catch((err) => {
  135. this.submitting = false;
  136. console.error(err);
  137. });
  138. } else {
  139. Object.assign(data, {
  140. receipts: receipts[receiptIndex],
  141. addressTags: addressTags[addressTagsIndex],
  142. });
  143. wx.setStorageSync('invoiceData', data);
  144. wx.navigateBack({ delta: 1 });
  145. }
  146. },
  147. checkSure() {
  148. const { name, componentName, code, phone, email, addressTagsIndex, receiptIndex } = this.data;
  149. if (receiptIndex === 0) {
  150. return true;
  151. }
  152. if (addressTagsIndex === 0) {
  153. if (!name.length || !phone.length) {
  154. return false;
  155. }
  156. } else if (addressTagsIndex === 1) {
  157. if (!componentName.length || !code.length) {
  158. return false;
  159. }
  160. }
  161. if (!email.length) {
  162. return false;
  163. }
  164. return true;
  165. },
  166. onDialogTap() {
  167. const { dialogShow } = this.data;
  168. this.setData({
  169. dialogShow: !dialogShow,
  170. codeShow: false,
  171. });
  172. },
  173. onKnowCode() {
  174. this.setData({
  175. dialogShow: !this.data.dialogShow,
  176. codeShow: true,
  177. });
  178. },
  179. });