AddDownModal.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. :title="fileFlow.title"
  6. @visible-change="handleVisibleChange"
  7. @cancel="resetFields"
  8. @ok="handleConfirm"
  9. >
  10. <div class="pt-2px pr-3px zdysrk">
  11. <BasicForm @register="registerForm">
  12. <template #text="{ model, field }"> {{ model[field] }}{{ fileFlow.type }} </template>
  13. </BasicForm>
  14. </div>
  15. </BasicModal>
  16. </template>
  17. <script lang="ts">
  18. import { defineComponent, nextTick, onMounted, reactive, computed, h } from 'vue';
  19. import { BasicModal, useModalInner } from '/@/components/Modal';
  20. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  21. import { useMessage } from '/@/hooks/web/useMessage';
  22. import { InvoiceRegister } from '/@/api/order';
  23. import { useI18n } from '/@/hooks/web/useI18n';
  24. import { uploadApi } from '/@/api/product/index';
  25. import { ResultEnum } from '/@/enums/httpEnum';
  26. import { DetailsApi, dincrementList, AddUserIncrementApi, AddDownNumApi } from '/@/api/account';
  27. import dayjs from 'dayjs';
  28. import { remarkschemas, Addschemas } from "./data";
  29. import { otherInfoStore } from '/@/store/modules/other';
  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 otherInfo = otherInfoStore();
  39. const overviewInfo = computed(() => otherInfo.getOverviewInfo);
  40. // const overviewInfo = getOverviewInfo() || {}
  41. const fileFlow = reactive({
  42. file: null,
  43. id: '',
  44. type: 'down', //down-下载,equity-权益
  45. title: '新增下载',
  46. });
  47. const { createMessage, createConfirm } = useMessage();
  48. const schemas: FormSchema[] = [
  49. ...Addschemas,
  50. // {
  51. // field: 'id',
  52. // component: 'Input',
  53. // show: false,
  54. // label: 'id',
  55. // },
  56. {
  57. field: 'count',
  58. component: 'InputNumber',
  59. label: '新增次数',
  60. required: true,
  61. componentProps: {
  62. min: 1,
  63. },
  64. colProps: {
  65. span: 22,
  66. },
  67. },
  68. ...remarkschemas,
  69. ];
  70. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  71. labelWidth: 120,
  72. schemas: schemas,
  73. showActionButtonGroup: false,
  74. actionColOptions: {
  75. span: 24,
  76. },
  77. });
  78. onMounted(() => {});
  79. let addListFunc = () => {};
  80. const [register, { closeModal }] = useModalInner((data) => {
  81. data && onDataReceive(data);
  82. updateSchema([
  83. {
  84. field: 'useType',
  85. componentProps: {
  86. onChange: (value) => {
  87. updateSchema({ field: 'projectNum', ifShow: value == '4' });
  88. },
  89. },
  90. },
  91. {
  92. field: 'projectNum',
  93. ifShow: false,
  94. },
  95. ]);
  96. });
  97. async function onDataReceive(data) {
  98. const res = await dincrementList();
  99. console.log('onDataReceive', data, res);
  100. resetFields();
  101. fileFlow.type = data.type;
  102. fileFlow.id = data.id;
  103. fileFlow.title = data.type == '1' ? '新增下载(四维深时)' : '新增下载(四维看看)';
  104. // setFieldsValue(data);
  105. }
  106. async function handleConfirm() {
  107. await validate();
  108. createConfirm({
  109. iconType: 'warning',
  110. title: () => h('span', '温馨提示'),
  111. content: () => h('span', `确定要新增下载次数吗?`),
  112. onOk: async () => {
  113. handleSubmit();
  114. },
  115. });
  116. }
  117. const handleSubmit = async () => {
  118. const submitUrl = AddDownNumApi;
  119. try {
  120. const params = await validate();
  121. console.log('validate', params);
  122. const res = await submitUrl({ userId: fileFlow.id, downType:fileFlow.type, ...params });
  123. overviewInfo.value.surDownNum = overviewInfo.value.surDownNum + params.count;
  124. console.log('res', res);
  125. otherInfo.updateOverviewInfo();
  126. closeModal();
  127. resetFields();
  128. createMessage.success(t('common.optSuccess'));
  129. emit('update');
  130. } catch (error) {
  131. console.log('not passing', error);
  132. }
  133. };
  134. function handleVisibleChange(v) {
  135. v && props.userData && nextTick(() => onDataReceive(props.userData));
  136. }
  137. return {
  138. register,
  139. registerForm,
  140. fileFlow,
  141. handleVisibleChange,
  142. handleSubmit,
  143. addListFunc,
  144. resetFields,
  145. handleConfirm,
  146. t,
  147. };
  148. },
  149. });
  150. </script>
  151. <style lang="less">
  152. .zdysrk {
  153. .ant-calendar-picker {
  154. min-width: 285px;
  155. }
  156. }
  157. </style>