InvoiceModal.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="开票登记"
  6. :okText="okText"
  7. @visible-change="handleVisibleChange"
  8. @cancel="resetFields"
  9. :confirmLoading="loading"
  10. @ok="handleSubmit"
  11. >
  12. <div class="pt-2px pr-3px">
  13. <BasicForm @register="registerForm">
  14. <template #text="{ model, field }">
  15. {{ model[field] }}
  16. </template>
  17. </BasicForm>
  18. </div>
  19. </BasicModal>
  20. </template>
  21. <script lang="ts">
  22. import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue';
  23. import { BasicModal, useModalInner } from '/@/components/Modal';
  24. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  25. import { useMessage } from '/@/hooks/web/useMessage';
  26. import { InvoiceRegister } from '/@/api/order';
  27. import { useI18n } from '/@/hooks/web/useI18n';
  28. import { uploadApi } from '/@/api/product/index';
  29. import { ResultEnum } from '/@/enums/httpEnum';
  30. const { t } = useI18n();
  31. export default defineComponent({
  32. components: { BasicModal, BasicForm },
  33. props: {
  34. userData: { type: Object },
  35. },
  36. emits: ['update', 'register'],
  37. setup(props, { emit }) {
  38. const fileFlow = reactive({
  39. file:null,
  40. type:2,//2-普通发票,3-专用发票
  41. })
  42. const okText = ref('发送')
  43. const loading = ref(false)
  44. const { createMessage } = useMessage();
  45. const schemas: FormSchema[] = [
  46. {
  47. field: 'id',
  48. component: 'Input',
  49. show:false,
  50. label: '发票编号',
  51. required: true,
  52. },
  53. {
  54. field: 'email',
  55. component: 'Input',
  56. label: '邮箱',
  57. slot: 'text',
  58. ifShow:fileFlow.type == 2,
  59. componentProps: {
  60. maxLength: 50,
  61. },
  62. colProps: {
  63. span: 24,
  64. },
  65. },{
  66. field: 'invoiceNum',
  67. component: 'Input',
  68. label: '发票编号',
  69. required: true,
  70. componentProps: {
  71. maxLength: 50,
  72. },
  73. colProps: {
  74. span: 24,
  75. },
  76. },{
  77. field: 'file',
  78. component: 'Upload',
  79. label: '电子发票',
  80. ifShow:fileFlow.type == 2,
  81. required: true,
  82. rules: [{ required: true, message: t('common.uploadMessge') }],
  83. itemProps: {
  84. validateTrigger: 'blur',
  85. },
  86. componentProps: {
  87. api: uploadApi,
  88. fileFlow:true,
  89. maxNumber: 1,
  90. maxSize: 1000,
  91. accept: ['jpeg','jpg','png'],
  92. afterFetch: function (data) {
  93. console.log('url',data)
  94. // Reflect.set(data, 'url', data.file);
  95. fileFlow.file = data.file
  96. return data;
  97. },
  98. },
  99. colProps: {
  100. span: 22,
  101. },
  102. },{
  103. field: 'invoiceNum',
  104. component: 'Input',
  105. label: '发票编号',
  106. required: true,
  107. componentProps: {
  108. maxLength: 50,
  109. },
  110. colProps: {
  111. span: 24,
  112. },
  113. },{
  114. field: 'shipNum',
  115. component: 'Input',
  116. ifShow:fileFlow.type == 3,
  117. label: '快递单号',
  118. componentProps: {
  119. maxLength: 50,
  120. },
  121. required: true,
  122. colProps: {
  123. span: 24,
  124. },
  125. },
  126. ];
  127. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  128. labelWidth: 120,
  129. schemas:schemas,
  130. showActionButtonGroup: false,
  131. actionColOptions: {
  132. span: 24,
  133. },
  134. });
  135. onMounted(() => {});
  136. let addListFunc = () => {};
  137. const [register, { closeModal }] = useModalInner((data) => {
  138. data && onDataReceive(data);
  139. });
  140. function onDataReceive(data) {
  141. resetFields();
  142. fileFlow.type = data.type
  143. setFieldsValue(data);
  144. okText.value = fileFlow.type == 2?'发送':'确认'
  145. updateSchema([
  146. {field: 'shipNum',ifShow:fileFlow.type == 3,},
  147. {field: 'email',ifShow:fileFlow.type == 2,},
  148. {field: 'file',ifShow:fileFlow.type == 2,},
  149. ])
  150. }
  151. const handleSubmit = async () => {
  152. loading.value = true
  153. try {
  154. const params = await validate();
  155. const apiData = {
  156. data:fileFlow.type == 3?{
  157. id:params.id,
  158. invoiceNum:params.invoiceNum,
  159. shipNum:params.shipNum,
  160. }:{
  161. id:params.id,
  162. invoiceNum:params.invoiceNum,
  163. file:fileFlow.file,
  164. // file:params.file[0],
  165. }
  166. }
  167. console.log('res', apiData,params);
  168. await InvoiceRegister(apiData);
  169. closeModal();
  170. resetFields();
  171. createMessage.success(t('common.optSuccess'));
  172. emit('update');
  173. loading.value = false
  174. } catch (error) {
  175. loading.value = false
  176. console.log('not passing', error);
  177. }
  178. };
  179. function handleVisibleChange(v) {
  180. v && props.userData && nextTick(() => onDataReceive(props.userData));
  181. }
  182. return {
  183. register,
  184. registerForm,
  185. fileFlow,
  186. handleVisibleChange,
  187. handleSubmit,
  188. addListFunc,
  189. resetFields,
  190. okText,
  191. loading,
  192. t,
  193. };
  194. },
  195. });
  196. </script>