addInvoice.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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="抬头:">
  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">
  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" 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="openBank">
  38. <u-input v-model="form.openBank" placeholder="选填" border />
  39. </u-form-item>
  40. <u-form-item label="银行账号:" prop="numBank">
  41. <u-input v-model="form.numBank" placeholder="选填" border />
  42. </u-form-item>
  43. <u-form-item label="企业地址:" prop="mapCom">
  44. <u-input v-model="form.mapCom" placeholder="选填" border />
  45. </u-form-item>
  46. <u-form-item label="企业电话:" prop="phoneCom">
  47. <u-input v-model="form.phoneCom" placeholder="选填" border />
  48. </u-form-item> -->
  49. <u-form-item label="电子邮箱:" prop="invoMail">
  50. <u-input v-model="form.invoMail" placeholder="选填" border />
  51. </u-form-item>
  52. <u-form-item label="手机号码:" prop="invoPhone">
  53. <u-input v-model="form.invoPhone" placeholder="选填" border />
  54. </u-form-item>
  55. </u-form>
  56. </view>
  57. <view class="invoice-submit">
  58. <u-button type="primary" :loading="loading" @click="submitForm">提交</u-button>
  59. </view>
  60. <!-- 公司弹框 -->
  61. <u-popup v-model="companyPop.show" mode="bottom" :closeable="true" height="50vh">
  62. <view class="popup">
  63. <view class="popup-list" v-if="companyPop.list.length">
  64. <u-radio-group class="popup-list-group" v-model="companyPop.form.name" :wrap="true">
  65. <u-radio class="popup-list-item" v-for="(item, index) in companyPop.list" :key="index" :name="item.id" @change="companyRadioClick(item)">
  66. {{ item.invoName }}
  67. </u-radio>
  68. </u-radio-group>
  69. </view>
  70. <view class="popup-list" v-else>
  71. <view class="popup-list-item">暂无抬头,请先添加</view>
  72. </view>
  73. <view class="popup-bottom">
  74. <u-button type="info" @click="addInvoiceHeader">添加常用发票抬头</u-button>
  75. </view>
  76. </view>
  77. </u-popup>
  78. <!-- 更多内容 -->
  79. <u-popup v-model="moreContentPop.show" mode="center" width="100%" height="100%">
  80. <view class="invoice-more-pop">
  81. <view class="invoice-more-pop-form">
  82. <u-form :model="moreContentPop.form" ref="uForm2" label-width="150" label-align="right">
  83. <u-form-item label="开户银行:" prop="openBank">
  84. <u-input v-model="form.openBank" placeholder="选填" border />
  85. </u-form-item>
  86. <u-form-item label="银行账号:" prop="numBank">
  87. <u-input v-model="form.numBank" placeholder="选填" border />
  88. </u-form-item>
  89. <u-form-item label="企业地址:" prop="mapCom">
  90. <u-input v-model="form.mapCom" placeholder="选填" border />
  91. </u-form-item>
  92. <u-form-item label="企业电话:" prop="phoneCom">
  93. <u-input v-model="form.phoneCom" placeholder="选填" border />
  94. </u-form-item>
  95. </u-form>
  96. </view>
  97. <view class="invoice-more-pop-submit">
  98. <u-button type="primary" @click="moreContentConfirm">确定</u-button>
  99. </view>
  100. </view>
  101. </u-popup>
  102. <u-toast ref="uToast" />
  103. </view>
  104. </template>
  105. <script>
  106. export default {
  107. data() {
  108. return {
  109. form: {
  110. invoName: '',
  111. invoCode: '',
  112. invoHeadId: '',
  113. invoMail: '',
  114. invoPhone: '',
  115. invoType: 1,
  116. phoneCom: '',
  117. mapCom: '',
  118. openBank: '',
  119. numBank: '',
  120. amount: '',
  121. orderIds: []
  122. },
  123. rules: {
  124. invoType: [{ required: true, message: '请选择发票类型', trigger: 'change' }],
  125. invoName: [{ required: true, message: '请输入抬头名称', trigger: 'blur' }],
  126. invoCode: [{ required: true, message: '请输入税号', trigger: 'blur' }]
  127. },
  128. companyPop: {
  129. show: false,
  130. form: {
  131. name: ''
  132. },
  133. list: []
  134. },
  135. loading: false,
  136. queryParams: {
  137. invoHeadType: 1
  138. },
  139. moreContentPop: {
  140. show: false,
  141. moreContentValue: ''
  142. }
  143. };
  144. },
  145. onLoad(options) {
  146. uni.getStorage({
  147. key: 'availableOrderKey',
  148. success: (res) => {
  149. const { total, ids, invoType } = JSON.parse(res.data);
  150. this.form.amount = total;
  151. this.form.orderIds = ids;
  152. this.form.invoType = invoType;
  153. }
  154. });
  155. },
  156. onShow() {
  157. this.getInvoiceHeaderSelect();
  158. },
  159. onReady() {
  160. this.$refs.uForm.setRules(this.rules);
  161. },
  162. methods: {
  163. /**
  164. * @description: 选择企业
  165. * @return {*}
  166. */
  167. moreCompany() {
  168. this.companyPop.show = true;
  169. },
  170. customBack() {
  171. uni.navigateBack();
  172. },
  173. moreContent() {
  174. this.moreContentPop.show = true;
  175. },
  176. /**
  177. * @description: 获取发票抬头下拉
  178. * @return {*}
  179. */
  180. async getInvoiceHeaderSelect() {
  181. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceHeadSelectApi({ ...this.queryParams });
  182. if (code === 200) {
  183. this.companyPop.list = data;
  184. const { invoName, invoCode, id, invoMail, invoPhone, invoStatus } = data[0] || {};
  185. const isEmpty = invoStatus !== 1;
  186. this.form.invoName = isEmpty ? '' : invoName;
  187. this.form.invoCode = isEmpty ? '' : invoCode;
  188. this.form.invoHeadId = isEmpty ? '' : id;
  189. this.form.invoMail = isEmpty ? '' : invoMail;
  190. this.form.invoPhone = isEmpty ? '' : invoPhone;
  191. this.companyPop.form.name = isEmpty ? '' : id;
  192. }
  193. },
  194. /**
  195. * @description: 选择抬头
  196. * @param {*} item
  197. * @return {*}
  198. */
  199. companyRadioClick(item) {
  200. this.companyPop.show = false;
  201. this.form.invoName = item.invoName;
  202. this.form.invoCode = item.invoCode;
  203. this.form.invoHeadId = item.id;
  204. this.form.invoMail = item.invoMail;
  205. this.form.invoPhone = item.invoPhone;
  206. this.companyPop.form.name = item.id;
  207. },
  208. addInvoiceHeader() {
  209. this.companyPop.show = false;
  210. this.$u.route({
  211. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
  212. });
  213. },
  214. /**
  215. * @description: 抬头类型切换
  216. * @param {*} val
  217. * @return {*}
  218. */
  219. invoTypeChange(val) {
  220. this.queryParams.invoHeadType = val;
  221. this.getInvoiceHeaderSelect();
  222. },
  223. moreContentConfirm() {
  224. this.moreContentPop.show = false;
  225. let moreContentTotal = 0;
  226. if (this.form.openBank) {
  227. moreContentTotal += 1;
  228. }
  229. if (this.form.numBank) {
  230. moreContentTotal += 1;
  231. }
  232. if (this.form.mapCom) {
  233. moreContentTotal += 1;
  234. }
  235. if (this.form.phoneCom) {
  236. moreContentTotal += 1;
  237. }
  238. if (moreContentTotal > 0) {
  239. this.moreContentPop.moreContentValue = `共4项 已填写${moreContentTotal}项`;
  240. } else {
  241. this.moreContentPop.moreContentValue = '';
  242. }
  243. },
  244. submitForm() {
  245. this.$refs.uForm.validate(async (valid) => {
  246. if (valid) {
  247. try {
  248. this.loading = true;
  249. const { invoHeadId, invoName, invoCode, invoMail, invoPhone, invoType, phoneCom, mapCom, openBank, numBank, orderIds } = this.form;
  250. const { code } = await this.$u.api.invoiceModuleApi.addInvoiceApi({
  251. invoHeadId,
  252. invoName,
  253. invoCode,
  254. invoMail,
  255. invoPhone,
  256. invoType,
  257. phoneCom,
  258. mapCom,
  259. openBank,
  260. numBank,
  261. orderIds
  262. });
  263. if (code === 200) {
  264. this.loading = false;
  265. this.$refs.uToast.show({
  266. title: '添加成功!',
  267. type: 'success',
  268. duration: 2000,
  269. url: '/pages/invoiceModule/invoiceSuccess/invoiceSuccess'
  270. });
  271. }
  272. } catch (error) {
  273. this.loading = false;
  274. }
  275. }
  276. });
  277. }
  278. }
  279. };
  280. </script>
  281. <style lang="scss" scoped>
  282. @import './addInvoice.scss';
  283. </style>