addInvoice.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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="info" @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. <u-toast ref="uToast" />
  91. </view>
  92. </template>
  93. <script>
  94. export default {
  95. data() {
  96. return {
  97. form: {
  98. invoName: '',
  99. invoCode: '',
  100. invoHeadId: '',
  101. invoMail: '',
  102. invoPhone: '',
  103. invoType: 1,
  104. phoneCom: '',
  105. mapCom: '',
  106. openBank: '',
  107. numBank: '',
  108. amount: '',
  109. orderIds: []
  110. },
  111. rules: {
  112. invoType: [{ required: true, message: '请选择发票类型', trigger: 'change' }],
  113. invoName: [{ required: true, message: '请输入抬头名称', trigger: 'blur' }],
  114. invoCode: [{ required: true, message: '请输入税号', trigger: 'blur' }]
  115. },
  116. companyPop: {
  117. show: false,
  118. form: {
  119. name: ''
  120. },
  121. list: []
  122. },
  123. loading: false,
  124. queryParams: {
  125. invoHeadType: 1
  126. },
  127. moreContentPop: {
  128. show: false,
  129. moreContentValue: ''
  130. }
  131. };
  132. },
  133. onLoad(options) {
  134. uni.getStorage({
  135. key: 'availableOrderKey',
  136. success: (res) => {
  137. const { total, ids, invoType } = JSON.parse(res.data);
  138. this.form.amount = total;
  139. this.form.orderIds = ids;
  140. this.form.invoType = invoType;
  141. }
  142. });
  143. },
  144. onShow() {
  145. this.getInvoiceHeaderSelect();
  146. },
  147. onReady() {
  148. this.$refs.uForm.setRules(this.rules);
  149. },
  150. methods: {
  151. /**
  152. * @description: 选择企业
  153. * @return {*}
  154. */
  155. moreCompany() {
  156. this.companyPop.show = true;
  157. },
  158. customBack() {
  159. uni.navigateBack();
  160. },
  161. moreContent() {
  162. this.moreContentPop.show = true;
  163. },
  164. /**
  165. * @description: 获取发票抬头下拉
  166. * @return {*}
  167. */
  168. async getInvoiceHeaderSelect() {
  169. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceHeadSelectApi({ ...this.queryParams });
  170. if (code === 200) {
  171. this.companyPop.list = data;
  172. const { invoName, invoCode, id, invoMail, invoPhone, invoStatus } = data[0] || {};
  173. const isEmpty = invoStatus !== 1;
  174. this.form.invoName = isEmpty ? '' : invoName;
  175. this.form.invoCode = isEmpty ? '' : invoCode;
  176. this.form.invoHeadId = isEmpty ? '' : id;
  177. this.form.invoMail = isEmpty ? '' : invoMail;
  178. this.form.invoPhone = isEmpty ? '' : invoPhone;
  179. this.companyPop.form.name = isEmpty ? '' : id;
  180. }
  181. },
  182. /**
  183. * @description: 选择抬头
  184. * @param {*} item
  185. * @return {*}
  186. */
  187. companyRadioClick(item) {
  188. this.companyPop.show = false;
  189. this.form.invoName = item.invoName;
  190. this.form.invoCode = item.invoCode;
  191. this.form.invoHeadId = item.id;
  192. this.form.invoMail = item.invoMail;
  193. this.form.invoPhone = item.invoPhone;
  194. this.companyPop.form.name = item.id;
  195. },
  196. addInvoiceHeader() {
  197. this.companyPop.show = false;
  198. this.$u.route({
  199. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
  200. });
  201. },
  202. /**
  203. * @description: 抬头类型切换
  204. * @param {*} val
  205. * @return {*}
  206. */
  207. invoTypeChange(val) {
  208. this.queryParams.invoHeadType = val;
  209. this.getInvoiceHeaderSelect();
  210. },
  211. /**
  212. * @description: 更多内容弹框确认
  213. * @return {*}
  214. */
  215. moreContentConfirm() {
  216. this.moreContentPop.show = false;
  217. const { openBank, numBank, mapCom, phoneCom } = this.form;
  218. const moreContentTotal = [openBank, numBank, mapCom, phoneCom].filter(Boolean).length;
  219. this.moreContentPop.moreContentValue = moreContentTotal ? `共4项 已填写${moreContentTotal}项` : '';
  220. },
  221. submitForm() {
  222. this.$refs.uForm.validate(async (valid) => {
  223. if (!valid) return;
  224. try {
  225. this.loading = true;
  226. uni.showLoading({
  227. title: '提交中...'
  228. });
  229. const { invoHeadId, invoName, invoCode, invoMail, invoPhone, invoType, phoneCom, mapCom, openBank, numBank, orderIds } = this.form;
  230. const { code } = await this.$u.api.invoiceModuleApi.addInvoiceApi({
  231. invoHeadId,
  232. invoName,
  233. invoCode,
  234. invoMail,
  235. invoPhone,
  236. invoType,
  237. phoneCom,
  238. mapCom,
  239. openBank,
  240. numBank,
  241. orderIds
  242. });
  243. if (code === 200) {
  244. this.$refs.uToast.show({
  245. title: '添加成功!',
  246. type: 'success',
  247. duration: 1000,
  248. url: '/pages/invoiceModule/invoiceSuccess/invoiceSuccess'
  249. });
  250. }
  251. } catch (error) {
  252. console.error(error);
  253. } finally {
  254. uni.hideLoading();
  255. this.loading = false;
  256. }
  257. });
  258. }
  259. }
  260. };
  261. </script>
  262. <style lang="scss" scoped>
  263. @import './addInvoice.scss';
  264. </style>