addInvoice.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <!-- 新增发票 -->
  2. <template>
  3. <view class="invoice">
  4. <!-- 导航栏 -->
  5. <u-navbar
  6. title-color="#fff"
  7. :custom-back="customBack"
  8. :border-bottom="false"
  9. back-icon-color="#CCE8FF"
  10. :background="{ background: '#008CFF' }"
  11. title="开发票"
  12. />
  13. <view class="invoice-form">
  14. <u-form :model="form" :rules="rules" ref="uForm" label-width="150" label-align="right">
  15. <u-form-item label="抬头:" required>
  16. <u-radio-group v-model="queryParams.invoHeadType" @change="invoTypeChange">
  17. <u-radio :name="1">企业</u-radio>
  18. <u-radio :name="2">个人</u-radio>
  19. </u-radio-group>
  20. </u-form-item>
  21. <u-form-item label="抬头名称:" prop="invoName" required>
  22. <u-input v-model="form.invoName" placeholder="请选择发票抬头" border disabled />
  23. <u-icon slot="right" name="list-dot" size="40" color="#606266" @click="moreCompany" />
  24. </u-form-item>
  25. <u-form-item label="税号:" prop="invoCode" required v-if="queryParams.invoHeadType === 1">
  26. <u-input v-model="form.invoCode" placeholder="税号自动填充" border disabled />
  27. </u-form-item>
  28. <u-form-item label="更多内容:" prop="moreContentValue">
  29. <u-input v-model="moreContentPop.moreContentValue" placeholder="开户银行、银行账号等" border disabled />
  30. <u-icon slot="right" name="arrow-right" size="36" color="#606266" @click="moreContent" />
  31. </u-form-item>
  32. <u-form-item label="发票金额:"> ¥{{ form.amount }} </u-form-item>
  33. </u-form>
  34. </view>
  35. <view class="invoice-form margin-top">
  36. <u-form :model="form" ref="uForm1" label-width="150" label-align="right">
  37. <u-form-item label="电子邮箱:" prop="invoMail">
  38. <u-input v-model="form.invoMail" placeholder="选填" border />
  39. </u-form-item>
  40. <u-form-item label="手机号码:" prop="invoPhone">
  41. <u-input v-model="form.invoPhone" placeholder="选填" border />
  42. </u-form-item>
  43. </u-form>
  44. </view>
  45. <view class="invoice-submit">
  46. <u-button type="primary" :loading="loading" @click="submitForm">提交</u-button>
  47. </view>
  48. <!-- 公司弹框 -->
  49. <u-popup v-model="companyPop.show" mode="bottom" :closeable="true" height="50vh">
  50. <view class="popup">
  51. <view class="popup-list" v-if="companyPop.list.length">
  52. <u-radio-group class="popup-list-group" v-model="companyPop.form.name" :wrap="true">
  53. <u-radio class="popup-list-item" v-for="(item, index) in companyPop.list" :key="index" :name="item.id" @change="companyRadioClick(item)">
  54. {{ item.invoName }}
  55. </u-radio>
  56. </u-radio-group>
  57. </view>
  58. <view class="popup-list" v-else>
  59. <view class="popup-list-item">暂无抬头,请先添加</view>
  60. </view>
  61. <view class="popup-bottom">
  62. <u-button type="primary" @click="addInvoiceHeader">添加常用发票抬头</u-button>
  63. </view>
  64. </view>
  65. </u-popup>
  66. <!-- 更多内容 -->
  67. <u-popup v-model="moreContentPop.show" mode="center" width="100%" height="100%">
  68. <view class="invoice-more-pop">
  69. <view class="invoice-more-pop-form">
  70. <u-form :model="moreContentPop.form" ref="uForm2" label-width="150" label-align="right">
  71. <u-form-item label="开户银行:" prop="openBank">
  72. <u-input v-model="form.openBank" placeholder="选填" border />
  73. </u-form-item>
  74. <u-form-item label="银行账号:" prop="numBank">
  75. <u-input v-model="form.numBank" placeholder="选填" border />
  76. </u-form-item>
  77. <u-form-item label="企业地址:" prop="mapCom">
  78. <u-input v-model="form.mapCom" placeholder="选填" border />
  79. </u-form-item>
  80. <u-form-item label="企业电话:" prop="phoneCom">
  81. <u-input v-model="form.phoneCom" placeholder="选填" border />
  82. </u-form-item>
  83. </u-form>
  84. </view>
  85. <view class="invoice-more-pop-submit">
  86. <u-button type="primary" @click="moreContentConfirm">确定</u-button>
  87. </view>
  88. </view>
  89. </u-popup>
  90. <!-- 可开票订单 -->
  91. <u-popup v-model="orderPop.show" mode="top" length="100%">
  92. <view class="order-box">
  93. <u-navbar
  94. back-text=""
  95. title="可开票订单"
  96. :background="orderPop.background"
  97. title-color="#fff"
  98. back-icon-color="#fff"
  99. :custom-back="orderCustomBack"
  100. />
  101. <z-paging ref="paging" :fixed="false" v-model="orderPop.list" @query="queryList">
  102. <view class="order-box-list">
  103. <view class="order-box-list-item" v-for="(item, index) in orderPop.list" :key="index" @click="radioClick(item)">
  104. <view class="left">
  105. <view class="left-radio small-radio">
  106. <radio value="true" :checked="orderPop.currentIds.includes(item.id)" />
  107. </view>
  108. <view class="left-content">
  109. <view class="left-content-item money">¥{{ item.amount }}</view>
  110. <view class="left-content-item">{{ item.name }}</view>
  111. <view class="left-content-item time">{{ $u.timeFormat(new Date(item.payTime), 'yyyy-mm-dd hh:MM:ss') }}</view>
  112. </view>
  113. </view>
  114. <view class="right">{{ item.vehicleNo }}</view>
  115. </view>
  116. </view>
  117. <view class="order-box-bottom" slot="bottom">
  118. <view class="order-box-bottom-radio small-radio">
  119. <radio value="true" :checked="orderPop.checkedAll" :disabled="this.orderPop.list.length === 0" @click="checkedChange" />本页全选
  120. </view>
  121. <view class="order-box-bottom-next">
  122. <u-button type="primary" size="medium" :disabled="!orderPop.currentIds.length" @click="nextStep">下一步</u-button>
  123. </view>
  124. </view>
  125. </z-paging>
  126. </view>
  127. </u-popup>
  128. <u-toast ref="uToast" />
  129. </view>
  130. </template>
  131. <script>
  132. export default {
  133. data() {
  134. return {
  135. form: {
  136. invoName: '',
  137. invoCode: '',
  138. invoHeadId: '',
  139. invoMail: '',
  140. invoPhone: '',
  141. invoType: 1,
  142. phoneCom: '',
  143. mapCom: '',
  144. openBank: '',
  145. numBank: '',
  146. amount: '',
  147. orderIds: []
  148. },
  149. rules: {
  150. invoType: [{ required: true, message: '请选择发票类型', trigger: 'change' }],
  151. invoName: [{ required: true, message: '请输入抬头名称', trigger: 'blur' }],
  152. invoCode: [{ required: true, message: '请输入税号', trigger: 'blur' }]
  153. },
  154. companyPop: {
  155. show: false,
  156. form: {
  157. name: ''
  158. },
  159. list: []
  160. },
  161. loading: false,
  162. queryParams: {
  163. invoHeadType: 1
  164. },
  165. moreContentPop: {
  166. show: false,
  167. moreContentValue: ''
  168. },
  169. orderPop: {
  170. show: true,
  171. background: {
  172. backgroundColor: '#008CFF'
  173. },
  174. checkedAll: false,
  175. queryParams: {
  176. pageNum: 1,
  177. pageSize: 10,
  178. invoType: 1
  179. },
  180. list: [],
  181. currentIds: [],
  182. currentList: []
  183. }
  184. };
  185. },
  186. watch: {
  187. 'orderPop.currentIds'(val) {
  188. this.orderPop.checkedAll = val.length === this.orderPop.list.length && val.length !== 0;
  189. },
  190. 'orderPop.list'(val) {
  191. this.orderPop.checkedAll = val.length === this.orderPop.currentIds.length && val.length !== 0;
  192. }
  193. },
  194. onLoad(options) {
  195. const { invoType } = options;
  196. this.form.invoType = invoType;
  197. this.orderPop.queryParams.invoType = invoType;
  198. },
  199. onShow() {
  200. this.getInvoiceHeaderSelect();
  201. },
  202. onReady() {
  203. this.$refs.uForm.setRules(this.rules);
  204. },
  205. methods: {
  206. /**
  207. * @description: 订单关闭
  208. * @return {*}
  209. */
  210. orderCustomBack() {
  211. uni.navigateBack();
  212. },
  213. /**
  214. * @description: 分页触发
  215. * @param {*} pageNo
  216. * @param {*} pageSize
  217. * @return {*}
  218. */
  219. queryList(pageNo, pageSize) {
  220. this.orderPop.queryParams.pageNum = pageNo;
  221. this.orderPop.queryParams.pageSize = pageSize;
  222. this.getList();
  223. },
  224. /**
  225. * @description: 获取列表
  226. * @return {*}
  227. */
  228. async getList() {
  229. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceOrderListApi({ ...this.orderPop.queryParams });
  230. if (code === 200) {
  231. this.$refs.paging.complete(data?.pageInfo?.rows || []);
  232. }
  233. },
  234. /**
  235. * @description: 单项条目点击
  236. * @param {*} item
  237. * @return {*}
  238. */
  239. radioClick(item) {
  240. if (this.orderPop.currentIds.includes(item.id)) {
  241. const index = this.orderPop.currentIds.indexOf(item.id);
  242. this.orderPop.currentIds.splice(index, 1);
  243. this.orderPop.currentList.splice(index, 1);
  244. } else {
  245. this.orderPop.currentIds.push(item.id);
  246. this.orderPop.currentList.push(item);
  247. }
  248. },
  249. /**
  250. * @description: 全选
  251. * @return {*}
  252. */
  253. checkedChange() {
  254. this.orderPop.checkedAll = !this.orderPop.checkedAll;
  255. this.orderPop.currentIds = this.orderPop.checkedAll ? this.orderPop.list.map((item) => item.id) : [];
  256. this.orderPop.currentList = this.orderPop.checkedAll
  257. ? this.orderPop.list.map((item) => {
  258. return { ...item };
  259. })
  260. : [];
  261. },
  262. /**
  263. * @description: 下一步
  264. * @return {*}
  265. */
  266. nextStep() {
  267. if (this.orderPop.currentIds.length) {
  268. this.form.amount = this.countSum(this.orderPop.currentList);
  269. this.form.orderIds = this.orderPop.currentIds;
  270. this.orderPop.show = false;
  271. } else {
  272. this.$refs.uToast.show({
  273. title: '请先选择订单',
  274. type: 'warning'
  275. });
  276. }
  277. },
  278. /**
  279. * @description: 计算累加精度丢失问题
  280. * @param {*} arr
  281. * @return {*}
  282. */
  283. countSum(arr) {
  284. if (!arr.length) return 0;
  285. arr = arr.map((v) => {
  286. if (v.amount && !Number.isNaN(Number(v.amount))) return Math.round(v.amount.toFixed(2) * 100);
  287. return 0;
  288. });
  289. const result = arr.reduce((prev, curr) => {
  290. return prev + curr;
  291. }, 0);
  292. return result / 100;
  293. },
  294. /**
  295. * @description: 选择企业
  296. * @return {*}
  297. */
  298. moreCompany() {
  299. this.companyPop.show = true;
  300. },
  301. customBack() {
  302. this.orderPop.show = true;
  303. // uni.navigateBack();
  304. },
  305. moreContent() {
  306. this.moreContentPop.show = true;
  307. },
  308. /**
  309. * @description: 获取发票抬头下拉
  310. * @return {*}
  311. */
  312. async getInvoiceHeaderSelect() {
  313. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceHeadSelectApi({ ...this.queryParams });
  314. if (code === 200) {
  315. this.companyPop.list = data;
  316. const { invoName, invoCode, id, invoMail, invoPhone, invoStatus } = data[0] || {};
  317. const isEmpty = invoStatus !== 1;
  318. this.form.invoName = isEmpty ? '' : invoName;
  319. this.form.invoCode = isEmpty ? '' : invoCode;
  320. this.form.invoHeadId = isEmpty ? '' : id;
  321. this.form.invoMail = isEmpty ? '' : invoMail;
  322. this.form.invoPhone = isEmpty ? '' : invoPhone;
  323. this.companyPop.form.name = isEmpty ? '' : id;
  324. }
  325. },
  326. /**
  327. * @description: 选择抬头
  328. * @param {*} item
  329. * @return {*}
  330. */
  331. companyRadioClick(item) {
  332. this.companyPop.show = false;
  333. this.form.invoName = item.invoName;
  334. this.form.invoCode = item.invoCode;
  335. this.form.invoHeadId = item.id;
  336. this.form.invoMail = item.invoMail;
  337. this.form.invoPhone = item.invoPhone;
  338. this.companyPop.form.name = item.id;
  339. },
  340. addInvoiceHeader() {
  341. this.companyPop.show = false;
  342. this.$u.route({
  343. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList',
  344. params: {
  345. invoType: this.form.invoType
  346. }
  347. });
  348. },
  349. /**
  350. * @description: 抬头类型切换
  351. * @param {*} val
  352. * @return {*}
  353. */
  354. invoTypeChange(val) {
  355. this.queryParams.invoHeadType = val;
  356. this.getInvoiceHeaderSelect();
  357. },
  358. /**
  359. * @description: 更多内容弹框确认
  360. * @return {*}
  361. */
  362. moreContentConfirm() {
  363. this.moreContentPop.show = false;
  364. const { openBank, numBank, mapCom, phoneCom } = this.form;
  365. const moreContentTotal = [openBank, numBank, mapCom, phoneCom].filter(Boolean).length;
  366. this.moreContentPop.moreContentValue = moreContentTotal ? `共4项 已填写${moreContentTotal}项` : '';
  367. },
  368. submitForm() {
  369. this.$refs.uForm.validate(async (valid) => {
  370. if (!valid) return;
  371. try {
  372. this.loading = true;
  373. uni.showLoading({
  374. title: '提交中...'
  375. });
  376. const { invoHeadId, invoName, invoCode, invoMail, invoPhone, invoType, phoneCom, mapCom, openBank, numBank, orderIds } = this.form;
  377. const { code } = await this.$u.api.invoiceModuleApi.addInvoiceApi({
  378. invoHeadId,
  379. invoName,
  380. invoCode,
  381. invoMail,
  382. invoPhone,
  383. invoType,
  384. phoneCom,
  385. mapCom,
  386. openBank,
  387. numBank,
  388. orderIds
  389. });
  390. if (code === 200) {
  391. this.$refs.uToast.show({
  392. title: '添加成功!',
  393. type: 'success',
  394. duration: 1000
  395. });
  396. setTimeout(() => {
  397. uni.redirectTo({
  398. url: `/pages/invoiceModule/invoiceSuccess/invoiceSuccess`
  399. });
  400. uni.hideLoading();
  401. this.loading = false;
  402. }, 1000);
  403. }
  404. } catch (error) {
  405. uni.hideLoading();
  406. this.loading = false;
  407. }
  408. });
  409. }
  410. }
  411. };
  412. </script>
  413. <style lang="scss" scoped>
  414. @import './addInvoice.scss';
  415. </style>