addInvoiceHeader.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!-- 新增发票抬头 -->
  2. <template>
  3. <view class="invoice-header u-skeleton">
  4. <view class="invoice-header-form">
  5. <u-form :model="form" ref="uForm" label-width="220" label-align="right">
  6. <u-form-item label="抬 头:" prop="invoHeadType" class="u-skeleton-fillet">
  7. <u-radio-group v-model="form.invoHeadType" :disabled="!!form.id">
  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" class="u-skeleton-fillet">
  13. <u-input v-model="form.invoName" placeholder="请输入发票抬头" />
  14. </u-form-item>
  15. <u-form-item label="税 号:" prop="invoCode" class="u-skeleton-fillet" v-if="form.invoHeadType === 1">
  16. <u-input v-model="form.invoCode" placeholder="请输入税号" />
  17. </u-form-item>
  18. </u-form>
  19. </view>
  20. <view class="invoice-header-default">
  21. <u-form :model="form" ref="uForm1" label-width="220" label-align="right">
  22. <u-form-item label="电子邮箱(选填):" prop="invoMail" class="u-skeleton-fillet">
  23. <u-input v-model="form.invoMail" placeholder="请输入电子邮箱" />
  24. </u-form-item>
  25. <u-form-item label="手机号码(选填):" prop="invoPhone" class="u-skeleton-fillet">
  26. <u-input v-model="form.invoPhone" placeholder="请输入手机号码" />
  27. </u-form-item>
  28. <u-form-item label="默认抬头:" prop="invoStatus" class="u-skeleton-fillet">
  29. <view class="invoice-header-default-item">
  30. <text class="tips">每次开票默认抬头信息</text>
  31. <u-switch v-model="form.invoStatus" size="40" />
  32. </view>
  33. </u-form-item>
  34. </u-form>
  35. </view>
  36. <view class="invoice-header-bottom">
  37. <u-button type="primary" @click="submitForm" :loading="loading">保存</u-button>
  38. </view>
  39. <!--引用组件-->
  40. <u-skeleton :loading="skeletonLoading" :animation="true" bgColor="#FFF"></u-skeleton>
  41. <u-toast ref="uToast" />
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. form: {
  49. invoHeadType: 1,
  50. invoName: '',
  51. invoCode: '',
  52. invoPhone: '',
  53. invoMail: '',
  54. invoStatus: false,
  55. id: undefined
  56. },
  57. rules: {
  58. invoName: [{ required: true, message: '请输入发票抬头', trigger: ['blur', 'change'] }],
  59. invoCode: [{ required: true, message: '请输入税号', trigger: ['blur', 'change'] }]
  60. },
  61. loading: false,
  62. skeletonLoading: false
  63. };
  64. },
  65. onLoad(options) {
  66. const { id } = options;
  67. if (id) {
  68. uni.setNavigationBarTitle({
  69. title: '编辑抬头'
  70. });
  71. this.getInvoiceHeaderDetails(id);
  72. }
  73. },
  74. onReady() {
  75. this.$refs.uForm.setRules(this.rules);
  76. },
  77. methods: {
  78. /**
  79. * @description: 获取发票抬头信息
  80. * @param {*} id
  81. * @return {*}
  82. */
  83. async getInvoiceHeaderDetails(id) {
  84. try {
  85. this.skeletonLoading = true;
  86. const { code, data } = await this.$u.api.invoiceModuleApi.getInvoiceHeadDetailsApi({ id });
  87. if (code === 200) {
  88. this.form.id = data.id;
  89. this.form.invoHeadType = data.invoHeadType;
  90. this.form.invoName = data.invoName;
  91. this.form.invoCode = data.invoCode;
  92. this.form.invoPhone = data.invoPhone;
  93. this.form.invoMail = data.invoMail;
  94. this.form.invoStatus = data.invoStatus === 1 ? true : false;
  95. }
  96. } catch (error) {
  97. } finally {
  98. this.skeletonLoading = false;
  99. }
  100. },
  101. /**
  102. * @description: 提交发票
  103. * @return {*}
  104. */
  105. submitForm() {
  106. this.$refs.uForm.validate(async (valid) => {
  107. if (valid) {
  108. this.loading = true;
  109. const form = { ...this.form };
  110. form.invoStatus = form.invoStatus ? 1 : 0;
  111. if (form.invoHeadType === 2) {
  112. form.invoCode = null;
  113. }
  114. if (form.id) {
  115. try {
  116. const { code } = await this.$u.api.invoiceModuleApi.updateInvoiceHeaderApi({ ...form });
  117. if (code === 200) {
  118. this.$refs.uToast.show({
  119. title: '修改成功!',
  120. type: 'success',
  121. duration: 2000,
  122. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
  123. });
  124. }
  125. } catch (error) {
  126. } finally {
  127. this.loading = false;
  128. }
  129. } else {
  130. try {
  131. const { code } = await this.$u.api.invoiceModuleApi.addInvoiceHeaderApi({ ...form });
  132. if (code === 200) {
  133. this.$refs.uToast.show({
  134. title: '保存成功!',
  135. type: 'success',
  136. duration: 2000,
  137. url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
  138. });
  139. }
  140. } catch (error) {
  141. } finally {
  142. this.loading = false;
  143. }
  144. }
  145. }
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. @import './addInvoiceHeader.scss';
  153. </style>