addInvoice.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!-- 新增发票 -->
  2. <template>
  3. <view class="invoice">
  4. <view class="invoice-form">
  5. <u-form :model="form" :rules="rules" ref="uForm" label-width="150" label-align="right">
  6. <u-form-item label="抬头:">
  7. <u-radio-group v-model="form.invoType" prop="invoType" @change="invoTypeChange">
  8. <u-radio :name="1">企业</u-radio>
  9. <u-radio :name="2">个人</u-radio>
  10. </u-radio-group>
  11. </u-form-item>
  12. <u-form-item label="抬头名称:" prop="invoName">
  13. <u-input v-model="form.invoName" placeholder="请输入抬头名称" border />
  14. <u-icon slot="right" name="list-dot" size="40" color="#606266" @click="moreCompany" />
  15. </u-form-item>
  16. <u-form-item label="税号:" prop="invoCode" v-if="form.invoType === 1">
  17. <u-input v-model="form.invoCode" placeholder="请输入税号" border />
  18. </u-form-item>
  19. <u-form-item label="发票金额:"> ¥{{ form.amount }} </u-form-item>
  20. </u-form>
  21. </view>
  22. <view class="invoice-form margin-top">
  23. <u-form :model="form" ref="uForm1" label-width="150" label-align="right">
  24. <u-form-item label="开户银行:" prop="openBank">
  25. <u-input v-model="form.openBank" placeholder="选填" border />
  26. </u-form-item>
  27. <u-form-item label="银行账号:" prop="numBank">
  28. <u-input v-model="form.numBank" placeholder="选填" border />
  29. </u-form-item>
  30. <u-form-item label="企业地址:" prop="mapCom">
  31. <u-input v-model="form.mapCom" placeholder="选填" border />
  32. </u-form-item>
  33. <u-form-item label="企业电话:" prop="phoneCom">
  34. <u-input v-model="form.phoneCom" placeholder="选填" border />
  35. </u-form-item>
  36. <u-form-item label="电子邮箱:" prop="invoMail">
  37. <u-input v-model="form.invoMail" placeholder="选填" border />
  38. </u-form-item>
  39. <u-form-item label="手机号码:" prop="invoPhone">
  40. <u-input v-model="form.invoPhone" placeholder="选填" border />
  41. </u-form-item>
  42. </u-form>
  43. </view>
  44. <view class="invoice-submit">
  45. <u-button type="primary" :loading="loading" @click="submitForm">提交</u-button>
  46. </view>
  47. <!-- 公司弹框 -->
  48. <u-popup v-model="companyPop.show" mode="bottom" :closeable="true" height="50vh">
  49. <view class="popup">
  50. <view class="popup-list" v-if="companyPop.list.length">
  51. <u-radio-group class="popup-list-group" v-model="form.companyName" :wrap="true">
  52. <u-radio
  53. class="popup-list-item"
  54. v-for="(item, index) in companyPop.list"
  55. :key="index"
  56. :name="item.invoName"
  57. @change="companyRadioClick(item)"
  58. >
  59. {{ item.invoName }}
  60. </u-radio>
  61. </u-radio-group>
  62. </view>
  63. <view class="popup-list" v-else>
  64. <view class="popup-list-item">暂未添加发票开头</view>
  65. </view>
  66. <view class="popup-bottom">
  67. <u-button type="info" @click="addInvoiceHeader">添加常用发票开头</u-button>
  68. </view>
  69. </view>
  70. </u-popup>
  71. <u-toast ref="uToast" />
  72. </view>
  73. </template>
  74. <script>
  75. export default {
  76. data() {
  77. return {
  78. form: {
  79. invoName: '',
  80. invoCode: '',
  81. invoHeadId: '',
  82. invoMail: '',
  83. invoPhone: '',
  84. invoType: 1,
  85. phoneCom: '',
  86. mapCom: '',
  87. openBank: '',
  88. numBank: '',
  89. amount: '',
  90. orderIds: []
  91. },
  92. rules: {
  93. invoType: [{ required: true, message: '请选择发票类型', trigger: 'change' }],
  94. invoName: [{ required: true, message: '请输入抬头名称', trigger: 'blur' }],
  95. invoCode: [{ required: true, message: '请输入税号', trigger: 'blur' }]
  96. },
  97. companyPop: {
  98. show: false,
  99. list: []
  100. },
  101. loading: false,
  102. queryParams: {
  103. invoHeadType: 1
  104. }
  105. };
  106. },
  107. onLoad(options) {
  108. this.getInvoiceHeaderSelect();
  109. uni.getStorage({
  110. key: 'availableOrderKey',
  111. success: (res) => {
  112. const { total, ids } = JSON.parse(res.data);
  113. this.form.amount = total;
  114. this.form.orderIds = ids;
  115. }
  116. });
  117. },
  118. onReady() {
  119. this.$refs.uForm.setRules(this.rules);
  120. },
  121. methods: {
  122. /**
  123. * @description: 选择企业
  124. * @return {*}
  125. */
  126. moreCompany() {
  127. this.companyPop.show = true;
  128. },
  129. /**
  130. * @description: 获取发票抬头下拉
  131. * @return {*}
  132. */
  133. async getInvoiceHeaderSelect() {
  134. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceHeadSelectApi({ ...this.queryParams });
  135. if (code === 200) {
  136. this.companyPop.list = data;
  137. if (data[0].invoStatus === 1) {
  138. this.form.invoName = data[0].invoName;
  139. this.form.invoCode = data[0].invoCode;
  140. this.form.invoHeadId = data[0].id;
  141. }
  142. }
  143. },
  144. /**
  145. * @description: 选择抬头
  146. * @param {*} item
  147. * @return {*}
  148. */
  149. companyRadioClick(item) {
  150. this.companyPop.show = false;
  151. this.form.invoName = item.invoName;
  152. this.form.invoCode = item.invoCode;
  153. this.form.invoHeadId = item.id;
  154. },
  155. addInvoiceHeader() {
  156. this.companyPop.show = false;
  157. this.$u.route({
  158. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
  159. });
  160. },
  161. /**
  162. * @description: 抬头类型切换
  163. * @param {*} val
  164. * @return {*}
  165. */
  166. invoTypeChange(val) {
  167. this.queryParams.invoHeadType = val;
  168. this.getInvoiceHeaderSelect();
  169. },
  170. submitForm() {
  171. this.$refs.uForm.validate(async (valid) => {
  172. if (valid) {
  173. try {
  174. this.loading = true;
  175. const { invoHeadId, invoName, invoCode, invoMail, invoPhone, invoType, phoneCom, mapCom, openBank, numBank, orderIds } = this.form;
  176. const { code } = await this.$u.api.invoiceModuleApi.addInvoiceApi({
  177. invoHeadId,
  178. invoName,
  179. invoCode,
  180. invoMail,
  181. invoPhone,
  182. invoType,
  183. phoneCom,
  184. mapCom,
  185. openBank,
  186. numBank,
  187. orderIds
  188. });
  189. if (code === 200) {
  190. this.loading = false;
  191. this.$refs.uToast.show({
  192. title: '添加成功!',
  193. type: 'success',
  194. duration: 2000,
  195. url: '/pages/invoiceModule/invoiceSuccess/invoiceSuccess'
  196. });
  197. }
  198. } catch (error) {
  199. this.loading = false;
  200. }
  201. }
  202. });
  203. }
  204. }
  205. };
  206. </script>
  207. <style lang="scss" scoped>
  208. @import './addInvoice.scss';
  209. </style>