AddDownModal.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 { currencyList, 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. {
  69. field: 'amount',
  70. component: 'InputNumber',
  71. label: '订单金额',
  72. required: true,
  73. colProps: {
  74. span: 16,
  75. },
  76. componentProps: {
  77. precision: 2,
  78. min: 0,
  79. step: 1
  80. },
  81. },
  82. {
  83. field: 'currencySymbol',
  84. component: 'ApiSelect',
  85. required: true,
  86. label: '币种',
  87. componentProps: {
  88. // filterOption: onFilterOption,
  89. // showSearch: true,
  90. api: currencyList,
  91. labelField: 'name',
  92. valueField: 'symbol',
  93. immediate: true,
  94. },
  95. colProps: {
  96. span: 20,
  97. },
  98. },
  99. ...remarkschemas,
  100. ];
  101. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  102. labelWidth: 120,
  103. schemas: schemas,
  104. showActionButtonGroup: false,
  105. actionColOptions: {
  106. span: 24,
  107. },
  108. });
  109. onMounted(() => {});
  110. let addListFunc = () => {};
  111. const [register, { closeModal }] = useModalInner((data) => {
  112. data && onDataReceive(data);
  113. updateSchema([
  114. {
  115. field: 'useType',
  116. componentProps: {
  117. onChange: (value) => {
  118. updateSchema({ field: 'projectNum', ifShow: value == '4' });
  119. },
  120. },
  121. },
  122. {
  123. field: 'projectNum',
  124. ifShow: false,
  125. },
  126. ]);
  127. });
  128. async function onDataReceive(data) {
  129. const res = await dincrementList();
  130. console.log('onDataReceive', data, res);
  131. resetFields();
  132. fileFlow.type = data.type;
  133. fileFlow.id = data.id;
  134. fileFlow.title = data.type == '1' ? '新增下载(四维深时)' : '新增下载(四维看看)';
  135. // setFieldsValue(data);
  136. }
  137. async function handleConfirm() {
  138. await validate();
  139. createConfirm({
  140. iconType: 'warning',
  141. title: () => h('span', '温馨提示'),
  142. content: () => h('span', `确定要新增下载次数吗?`),
  143. onOk: async () => {
  144. handleSubmit();
  145. },
  146. });
  147. }
  148. const handleSubmit = async () => {
  149. const submitUrl = AddDownNumApi;
  150. try {
  151. const params = await validate();
  152. console.log('validate', params);
  153. const res = await submitUrl({ userId: fileFlow.id, downType:fileFlow.type, ...params });
  154. overviewInfo.value.surDownNum = overviewInfo.value.surDownNum + params.count;
  155. console.log('res', res);
  156. otherInfo.updateOverviewInfo();
  157. closeModal();
  158. resetFields();
  159. createMessage.success(t('common.optSuccess'));
  160. emit('update');
  161. } catch (error) {
  162. console.log('not passing', error);
  163. }
  164. };
  165. function handleVisibleChange(v) {
  166. v && props.userData && nextTick(() => onDataReceive(props.userData));
  167. }
  168. return {
  169. register,
  170. registerForm,
  171. fileFlow,
  172. handleVisibleChange,
  173. handleSubmit,
  174. addListFunc,
  175. resetFields,
  176. handleConfirm,
  177. t,
  178. };
  179. },
  180. });
  181. </script>
  182. <style lang="less">
  183. .zdysrk {
  184. .ant-calendar-picker {
  185. min-width: 285px;
  186. }
  187. }
  188. </style>