AddDownModal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. import { useUserStore } from '/@/store/modules/user';
  31. const { t } = useI18n();
  32. export default defineComponent({
  33. components: { BasicModal, BasicForm },
  34. props: {
  35. userData: { type: Object },
  36. },
  37. emits: ['update', 'register'],
  38. setup(props, { emit }) {
  39. const otherInfo = otherInfoStore();
  40. const userStore = useUserStore();
  41. const overviewInfo = computed(() => otherInfo.getOverviewInfo);
  42. // const overviewInfo = getOverviewInfo() || {}
  43. const fileFlow = reactive({
  44. file: null,
  45. id: '',
  46. type: 'down', //down-下载,equity-权益
  47. title: '新增下载',
  48. });
  49. const { createMessage, createConfirm } = useMessage();
  50. const schemas: FormSchema[] = [
  51. ...Addschemas,
  52. // {
  53. // field: 'id',
  54. // component: 'Input',
  55. // show: false,
  56. // label: 'id',
  57. // },
  58. {
  59. field: 'count',
  60. component: 'InputNumber',
  61. label: '新增次数',
  62. required: true,
  63. componentProps: {
  64. min: 1,
  65. },
  66. colProps: {
  67. span: 22,
  68. },
  69. },
  70. {
  71. field: 'amount',
  72. component: 'InputNumber',
  73. label: '订单金额',
  74. required: true,
  75. colProps: {
  76. span: 16,
  77. },
  78. componentProps: {
  79. precision: 2,
  80. min: 0,
  81. step: 1
  82. },
  83. },
  84. {
  85. field: 'currencySymbol',
  86. component: 'ApiSelect',
  87. required: true,
  88. label: '币种',
  89. defaultValue: userStore.isEnv ? '' : 'CNY',
  90. componentProps: {
  91. // filterOption: onFilterOption,
  92. // showSearch: true,
  93. api: currencyList,
  94. labelField: 'name',
  95. valueField: 'symbol',
  96. immediate: true,
  97. },
  98. colProps: {
  99. span: 20,
  100. },
  101. },
  102. ...remarkschemas,
  103. ];
  104. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  105. labelWidth: 120,
  106. schemas: schemas,
  107. showActionButtonGroup: false,
  108. actionColOptions: {
  109. span: 24,
  110. },
  111. });
  112. onMounted(() => {});
  113. let addListFunc = () => {};
  114. const [register, { closeModal }] = useModalInner((data) => {
  115. data && onDataReceive(data);
  116. updateSchema([
  117. {
  118. field: 'useType',
  119. componentProps: {
  120. onChange: useTypeChange,
  121. },
  122. },
  123. {
  124. field: 'projectNum',
  125. ifShow: false,
  126. },
  127. ]);
  128. useTypeChange(0)
  129. });
  130. async function onDataReceive(data) {
  131. const res = await dincrementList();
  132. console.log('onDataReceive', data, res);
  133. resetFields();
  134. fileFlow.type = data.type;
  135. fileFlow.id = data.id;
  136. // fileFlow.title = data.type == '1' ? '新增下载(四维深时)' : '新增下载(四维看看)';
  137. // setFieldsValue(data);
  138. }
  139. const useTypeChange = (value) => {
  140. updateSchema([
  141. { field: 'projectNum', ifShow: value == '4' },
  142. { field: 'companyName', ifShow: value != '3' },
  143. { field: 'businessDept', ifShow: value != '3' },
  144. { field: 'businessName', ifShow: value != '3' },
  145. { field: 'customerName', ifShow: value != '3' },
  146. { field: 'customerType', ifShow: value != '3' },
  147. { field: 'endCustomer', ifShow: value != '3' },
  148. { field: 'customerPayTime', required: value == '4' },
  149. ]);
  150. };
  151. async function handleConfirm() {
  152. await validate();
  153. createConfirm({
  154. iconType: 'warning',
  155. title: () => h('span', '温馨提示'),
  156. content: () => h('span', `确定要新增下载次数吗?`),
  157. onOk: async () => {
  158. handleSubmit();
  159. },
  160. });
  161. }
  162. const handleSubmit = async () => {
  163. const submitUrl = AddDownNumApi;
  164. try {
  165. const params = await validate();
  166. console.log('validate', params);
  167. const res = await submitUrl({ userId: fileFlow.id, ...params }); //downType:fileFlow.type,
  168. overviewInfo.value.surDownNum = overviewInfo.value.surDownNum + params.count;
  169. console.log('res', res);
  170. otherInfo.updateOverviewInfo();
  171. closeModal();
  172. resetFields();
  173. createMessage.success(t('common.optSuccess'));
  174. emit('update');
  175. } catch (error) {
  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. handleConfirm,
  191. t,
  192. };
  193. },
  194. });
  195. </script>
  196. <style lang="less">
  197. .zdysrk {
  198. .ant-calendar-picker {
  199. min-width: 285px;
  200. }
  201. }
  202. </style>