parkingApplication.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. const app = {};
  2. import arrowIcon from '../../static/images/arrows.png';
  3. import { mapState } from 'vuex';
  4. import uni from '@/utils/uniHooks';
  5. import { getUrlParams } from '@/utils/index.js';
  6. import { Toast } from 'vant';
  7. import { invoicesDetail, submitInvoice, invoiceEmails, invoicesOrders } from '@/api/parking';
  8. export default {
  9. data() {
  10. return {
  11. picUrl: this.$picUrl,
  12. globalData: app.globalData,
  13. arrowIcon: arrowIcon,
  14. isShow: false,
  15. isDefaultEMail: false,
  16. ids: [],
  17. condition: {
  18. invoiceType: 'GVATE', // 发票类型:gvat-增值税普通发票svat-增值税专⽤发票gvate-增值税电⼦普票发票svate-增值税电⼦专⽤发票
  19. remark: '',
  20. invoiceTitle: {}, // long|发票抬头id
  21. parkOrderList: [], // 被选中的缴费记录id
  22. email: '',
  23. id: '',
  24. emailAsDefault: true,
  25. },
  26. headerInfo: {},
  27. // 总金额,单位分
  28. invoiceAmount: 0,
  29. orderInfo: {},
  30. type: '', // 当前是活动还是停车
  31. isSubmitFlag: true, // 发票提交申请的flag,
  32. pageOptions: null,
  33. preUrl: '',
  34. orderQuantity: 0,
  35. parkingOrder: null,
  36. pagesize: 10,
  37. page: 0,
  38. parkingDetailList: [],
  39. };
  40. },
  41. created() {
  42. // 埋点本地化
  43. this.preUrl = uni.getStorageSync('previousUrl');
  44. uni.setStorageSync('previousUrl', '/pages/parkingFee/parkingReceipt/parkingApplication.vue');
  45. },
  46. mounted() {
  47. setTimeout(() => {
  48. uni.setNavigationBarTitle({
  49. title: '发票申请',
  50. });
  51. }, 300);
  52. setTimeout(() => {
  53. window?.toWXSendMsg({
  54. type: 'uni_func',
  55. funcName: 'setNavigationBarColor',
  56. options: {
  57. frontColor: '#000000',
  58. backgroundColor: '#FBFCFF',
  59. },
  60. });
  61. }, 500)
  62. this.getEmail();
  63. const query = getUrlParams();
  64. this.pageOptions = query;
  65. if (this.pageOptions) {
  66. const options = this.pageOptions;
  67. if (this.pageOptions.againInvoiceFlag) {
  68. this.getInvoicesOrders(options.invoiceId);
  69. } else {
  70. this.invoiceAmount = Number(options.money).toFixed(2);
  71. this.$store.commit('setTempParkingOrder', options.invoiceDetailList);
  72. this.$store.commit('setTempParkingMoney', this.invoiceAmount);
  73. this.parkingDetailList = JSON.parse(options.invoiceDetailList);
  74. }
  75. if (options.ids) {
  76. const ids = options.ids;
  77. if (ids.indexOf(',') > -1) {
  78. this.ids = ids.split(',');
  79. } else {
  80. this.ids = typeof ids === 'string' ? (ids.indexOf('[') > -1 ? JSON.parse(ids) : [ids]) : ids;
  81. }
  82. this.orderQuantity = this.ids.length;
  83. this.getParkOrderInfo();
  84. }
  85. if (options.header) {
  86. if (typeof options.header == 'string') {
  87. this.headerInfo = JSON.parse(options.header);
  88. } else if (typeof options.header == 'object') {
  89. this.headerInfo = options.header;
  90. }
  91. } else {
  92. this.getInvoiceTitle();
  93. }
  94. }
  95. },
  96. computed: {
  97. ...mapState({
  98. custTypeId: (state) => state.custTypeId,
  99. groupId: (state) => state.groupId,
  100. openid: (state) => state.openid,
  101. mallId: (state) => state.mallId,
  102. kipUserId: (state) => state.kipUserId,
  103. userInfo: (state) => state.userInfo,
  104. storeEmail: (state) => state.invoice.email,
  105. storeOldEmail: (state) => state.invoice.oldEmail,
  106. storeEmailAsDefault: (state) => state.invoice.emailAsDefault,
  107. storeRemark: (state) => state.invoice.remark,
  108. storeOldRemark: (state) => state.invoice.oldrRemark,
  109. source: (state) => state.source, // 来源
  110. }),
  111. },
  112. methods: {
  113. getInvoicesOrders: async function (id) {
  114. try {
  115. const res = await invoicesOrders(id);
  116. this.invoiceAmount = res.invoiceTotalAmount;
  117. this.orderQuantity = res.invoicedOrders.length;
  118. this.parkingOrder = res.invoicedOrders;
  119. this.$store.commit('setTempParkingOrder', JSON.stringify(res.invoicedOrders));
  120. this.$store.commit('setTempParkingMoney', res.invoiceTotalAmount);
  121. this.ids = res.invoicedOrders.map((item) => {
  122. return item.id;
  123. });
  124. } catch {
  125. uni.showToast({
  126. title: '服务器开小差了呢,请您稍后再试',
  127. icon: 'none',
  128. });
  129. }
  130. },
  131. getEmail: async function () {
  132. try {
  133. const res = await invoiceEmails();
  134. this.condition.emailAsDefault = res.emailAsDefault || this.storeEmailAsDefault;
  135. if (res.email === this.storeOldEmail) {
  136. this.condition.email = this.storeEmail;
  137. } else {
  138. this.condition.email = res.email;
  139. this.$store.commit('invoice/set_email', res.email);
  140. this.$store.commit('invoice/set_old_email', res.email);
  141. }
  142. if (res.remark === this.storeOldRemark) {
  143. this.condition.remark = this.storeRemark;
  144. } else {
  145. this.condition.remark = res.remark;
  146. this.$store.commit('invoice/set_remark', res.remark);
  147. this.$store.commit('invoice/set_old_remark', res.remark);
  148. }
  149. } catch {
  150. uni.showToast({
  151. title: '服务器开小差了呢,请您稍后再试',
  152. icon: 'none',
  153. });
  154. }
  155. },
  156. changeShowMore() {
  157. this.isShow = !this.isShow;
  158. },
  159. changeDefaultEMail() {
  160. this.emailAsDefault = !this.emailAsDefault;
  161. },
  162. changeHeader() {
  163. this.$router.push({
  164. path: 'parkingChooseHeader',
  165. query: {
  166. ids: this.ids,
  167. invoiceDetailList: JSON.stringify(this.invoiceDetailList),
  168. money: this.invoiceAmount,
  169. invoiceId: this.pageOptions?.invoiceId,
  170. },
  171. });
  172. },
  173. gotoDetail() {
  174. this.$router.push({
  175. path: 'parkingOrderDetail?useParkingOrderCache=true',
  176. query: {
  177. invoiceDetailList: this.pageOptions.againInvoiceFlag ? JSON.stringify(this.parkingOrder) : this.pageOptions.invoiceDetailList,
  178. money: this.invoiceAmount,
  179. },
  180. });
  181. },
  182. // 查询全部抬头列表信息
  183. getInvoiceTitle: async function () {
  184. const self = this;
  185. const params = {
  186. page: this.page,
  187. size: this.pagesize,
  188. };
  189. self.$md(params);
  190. try {
  191. const res = await invoicesDetail(params);
  192. if (res) {
  193. const list = res.content;
  194. let currentIndex = 0;
  195. list.map((item, index) => {
  196. if (item.defaultOrNot) currentIndex = index;
  197. });
  198. self.headerInfo = list[currentIndex] || {};
  199. }
  200. } catch (err) {
  201. uni.showToast({
  202. title: err.langMessage,
  203. icon: 'none',
  204. });
  205. }
  206. },
  207. // 根据选中的停车缴费记录id获取详情信息
  208. getParkOrderInfo() {
  209. // 如果当前是活动开票的话,则不差详情
  210. if (this.type) return;
  211. this.parkingOrder = this.pageOptions.invoiceDetailList;
  212. },
  213. submit: async function () {
  214. const self = this;
  215. if (!self.condition.email) {
  216. Toast({
  217. message: '请输入电子邮箱地址',
  218. });
  219. return false;
  220. }
  221. const params = self.condition;
  222. params.parkOrderList = self.ids.map((item) => {
  223. return (item = {
  224. id: item,
  225. });
  226. });
  227. params.invoiceTitle.id = this.headerInfo.id;
  228. params.totalAmount = Number(this.invoiceAmount);
  229. if (this.pageOptions.invoiceId) {
  230. params.id = this.pageOptions.invoiceId;
  231. }
  232. if (self.isSubmitFlag) {
  233. self.isSubmitFlag = false;
  234. try {
  235. const res = await submitInvoice(params);
  236. if (res) {
  237. Toast({
  238. message: '开票成功',
  239. });
  240. // vue.router router.replace点两次返回问题及解决方案: https://blog.csdn.net/william_jzy/article/details/85760660
  241. this.$router.replace({
  242. path: 'parkingReceipt',
  243. });
  244. this.$router.go(-1)
  245. }
  246. } catch (err) {
  247. console.log(111, err);
  248. }
  249. }
  250. },
  251. mailboxChange() {
  252. if (this.storeOldEmail !== this.condition.email) {
  253. this.$store.commit('invoice/set_email', this.condition.email);
  254. }
  255. },
  256. emailAsDefaultChange() {
  257. this.$store.commit('invoice/set_emailAsDefault', this.condition.emailAsDefault);
  258. },
  259. storeRemarkChange() {
  260. this.$store.commit('invoice/set_remark', this.condition.remark);
  261. },
  262. submitTest(type) {
  263. if(type === 'H5') {
  264. this.$router.replace({
  265. path: 'parkingReceipt',
  266. });
  267. this.$router.go(-1)
  268. return
  269. }
  270. if(type === '小程序1') {
  271. this.$router.replace({
  272. path: 'parkingReceipt',
  273. });
  274. setTimeout(() => {
  275. this.$router.go(-1)
  276. },200)
  277. return
  278. }
  279. if(type === '小程序2') {
  280. this.$router.replace({
  281. path: 'parkingReceipt',
  282. });
  283. this.$router.back()
  284. return
  285. }
  286. if(type === '小程序3') {
  287. this.$router.replace({
  288. path: 'parkingReceipt',
  289. });
  290. setTimeout(() => {
  291. this.$router.back()
  292. },200)
  293. return
  294. }
  295. }
  296. },
  297. };