addInvoiceHeader.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!-- 新增发票抬头 -->
  2. <template>
  3. <view class="invoice-header u-skeleton">
  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="navigationBarTitle"
  12. class="invoice-navbar"
  13. >
  14. <!-- <view slot="right" class="invoice-header-right" v-if="form.id">
  15. <u-icon name="trash-fill" size="40" color="#fa3534" @click="handleDelete"></u-icon>
  16. </view> -->
  17. </u-navbar>
  18. <view class="invoice-header-form">
  19. <u-form :model="form" ref="uForm" label-width="220" label-align="right">
  20. <u-form-item label="抬 头:" prop="invoHeadType" required class="u-skeleton-fillet">
  21. <u-radio-group v-model="form.invoHeadType" :disabled="!!form.id">
  22. <u-radio :name="1">企业</u-radio>
  23. <u-radio :name="2">个人</u-radio>
  24. </u-radio-group>
  25. </u-form-item>
  26. <u-form-item label="发票抬头:" prop="invoName" required class="u-skeleton-fillet">
  27. <u-input v-model="form.invoName" placeholder="请输入发票抬头" />
  28. </u-form-item>
  29. <u-form-item label="税 号:" prop="invoCode" required class="u-skeleton-fillet" v-if="form.invoHeadType === 1">
  30. <u-input v-model="form.invoCode" placeholder="请输入税号" />
  31. </u-form-item>
  32. </u-form>
  33. </view>
  34. <view class="invoice-header-default">
  35. <u-form :model="form" ref="uForm1" label-width="220" label-align="right">
  36. <u-form-item label="电子邮箱(选填):" prop="invoMail" class="u-skeleton-fillet">
  37. <u-input v-model="form.invoMail" placeholder="请输入电子邮箱" />
  38. </u-form-item>
  39. <u-form-item label="手机号码(选填):" prop="invoPhone" class="u-skeleton-fillet">
  40. <u-input v-model="form.invoPhone" placeholder="请输入手机号码" />
  41. </u-form-item>
  42. <u-form-item label="默认抬头:" prop="invoStatus" class="u-skeleton-fillet">
  43. <view class="invoice-header-default-item">
  44. <text class="tips">每次开票默认抬头信息</text>
  45. <u-switch v-model="form.invoStatus" size="40" />
  46. </view>
  47. </u-form-item>
  48. </u-form>
  49. </view>
  50. <view class="invoice-header-bottom">
  51. <u-button type="primary" @click="submitForm" :loading="loading">保存</u-button>
  52. </view>
  53. <!--引用组件-->
  54. <u-skeleton :loading="skeletonLoading" :animation="true" bgColor="#FFF"></u-skeleton>
  55. <u-toast ref="uToast" />
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. invoType: 1,
  63. form: {
  64. invoHeadType: 1,
  65. invoName: '',
  66. invoCode: '',
  67. invoPhone: '',
  68. invoMail: '',
  69. invoStatus: false,
  70. id: undefined
  71. },
  72. rules: {
  73. invoName: [{ required: true, message: '请输入发票抬头', trigger: ['blur', 'change'] }],
  74. invoCode: [{ required: true, message: '请输入税号', trigger: ['blur', 'change'] }]
  75. },
  76. loading: false,
  77. skeletonLoading: false,
  78. navigationBarTitle: '新增抬头'
  79. };
  80. },
  81. onLoad(options) {
  82. const { id, invoType } = options;
  83. this.invoType = invoType;
  84. this.navigationBarTitle = '新增抬头';
  85. if (id) {
  86. this.navigationBarTitle = '编辑抬头';
  87. this.getInvoiceHeaderDetails(id);
  88. }
  89. },
  90. onReady() {
  91. this.$refs.uForm.setRules(this.rules);
  92. },
  93. methods: {
  94. customBack() {
  95. uni.navigateBack();
  96. },
  97. addInvoice() {},
  98. /**
  99. * @description: 获取发票抬头信息
  100. * @param {*} id
  101. * @return {*}
  102. */
  103. async getInvoiceHeaderDetails(id) {
  104. try {
  105. this.skeletonLoading = true;
  106. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceHeadDetailsApi({ id });
  107. if (code === 200) {
  108. this.form.id = data.id;
  109. this.form.invoHeadType = data.invoHeadType;
  110. this.form.invoName = data.invoName;
  111. this.form.invoCode = data.invoCode;
  112. this.form.invoPhone = data.invoPhone;
  113. this.form.invoMail = data.invoMail;
  114. this.form.invoStatus = data.invoStatus === 1 ? true : false;
  115. }
  116. } catch (error) {
  117. } finally {
  118. this.skeletonLoading = false;
  119. }
  120. },
  121. handleDelete() {
  122. uni.showModal({
  123. title: '提示',
  124. content: '你确认要删除该条发票抬头吗?',
  125. success: async (res) => {
  126. if (res.confirm) {
  127. try {
  128. this.loading = true;
  129. const { id } = this.form;
  130. const { code } = await this.$u.api.invoiceModuleApi.deleteInvoiceHeaderApi({ id });
  131. if (code === 200) {
  132. this.$refs.uToast.show({
  133. title: '删除成功!',
  134. type: 'success',
  135. duration: 2000
  136. });
  137. setTimeout(() => {
  138. this.loading = false;
  139. this.$u.route({
  140. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList',
  141. params: {
  142. invoType: this.invoType
  143. }
  144. });
  145. }, 2000);
  146. }
  147. } catch (error) {
  148. this.loading = false;
  149. }
  150. }
  151. }
  152. });
  153. },
  154. /**
  155. * @description: 提交发票
  156. * @return {*}
  157. */
  158. submitForm() {
  159. this.$refs.uForm.validate(async (valid) => {
  160. if (!valid) return;
  161. this.loading = true;
  162. const form = { ...this.form };
  163. form.invoStatus = form.invoStatus ? 1 : 0;
  164. if (form.invoHeadType === 2) {
  165. form.invoCode = null;
  166. }
  167. try {
  168. let response;
  169. if (form.id) {
  170. response = await this.$u.api.invoiceModuleApi.updateInvoiceHeaderApi({ ...form });
  171. this.$refs.uToast.show({
  172. title: '修改成功!',
  173. type: 'success',
  174. duration: 2000
  175. });
  176. } else {
  177. response = await this.$u.api.invoiceModuleApi.addInvoiceHeaderApi({ ...form });
  178. this.$refs.uToast.show({
  179. title: '保存成功!',
  180. type: 'success',
  181. duration: 2000
  182. });
  183. }
  184. if (response.code === 200) {
  185. setTimeout(() => {
  186. this.$u.route({
  187. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList',
  188. params: {
  189. invoType: this.invoType
  190. },
  191. type: 'redirect'
  192. });
  193. }, 2000);
  194. }
  195. } catch (error) {
  196. console.error(error);
  197. } finally {
  198. this.loading = false;
  199. }
  200. });
  201. }
  202. }
  203. };
  204. </script>
  205. <style lang="scss" scoped>
  206. @import './addInvoiceHeader.scss';
  207. </style>