AddModal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="本地版算法授权"
  6. @visible-change="handleVisibleChange"
  7. @cancel="resetFields"
  8. minHeight="900px"
  9. @ok="handleConfirm"
  10. >
  11. <div class="pt-2px pr-3px zdysrk">
  12. <BasicForm @register="registerForm">
  13. <template #text="{ model, field }"> {{ model[field] }}{{ fileFlow.type }} </template>
  14. </BasicForm>
  15. </div>
  16. </BasicModal>
  17. </template>
  18. <script lang="ts">
  19. import { defineComponent, nextTick, onMounted, reactive, computed, h } from 'vue';
  20. import { BasicModal, useModalInner } from '/@/components/Modal';
  21. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  22. import { useMessage } from '/@/hooks/web/useMessage';
  23. import { remarkschemas, Addschemas } from './data';
  24. import { InvoiceRegister } from '/@/api/order';
  25. import { useI18n } from '/@/hooks/web/useI18n';
  26. import { uploadApi } from '/@/api/product/index';
  27. import { ResultEnum } from '/@/enums/httpEnum';
  28. import { authorizeModelingaddOrUpdate } from '/@/api/authorizeModeling';
  29. import dayjs from 'dayjs';
  30. import { otherInfoStore } from '/@/store/modules/other';
  31. import { incrementUseTypeList } from '/@/api/account';
  32. const { t } = useI18n();
  33. export default defineComponent({
  34. components: { BasicModal, BasicForm },
  35. props: {
  36. userData: { type: Object },
  37. },
  38. emits: ['update', 'register'],
  39. setup(props, { emit }) {
  40. const otherInfo = otherInfoStore();
  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. });
  48. const { createMessage, createConfirm } = useMessage();
  49. const schemas: FormSchema[] = [
  50. {
  51. field: 'id',
  52. component: 'Input',
  53. show: false,
  54. label: 'id',
  55. },
  56. {
  57. field: 'authorizeKey',
  58. component: 'Input',
  59. required: true,
  60. label: '授权码',
  61. colProps: { span: 20 },
  62. },
  63. {
  64. field: 'authorizeTime',
  65. component: 'Select',
  66. label: '授权期限',
  67. required: true,
  68. defaultValue: '10_1',
  69. componentProps: {
  70. options: [
  71. {
  72. label: '10天',
  73. value: '10_1',
  74. key: '10',
  75. },
  76. {
  77. label: '1个月',
  78. value: '1_2',
  79. key: '30',
  80. },
  81. {
  82. label: '3个月',
  83. value: '3_2',
  84. key: '90',
  85. },
  86. {
  87. label: '1年',
  88. value: '1_3',
  89. key: '365',
  90. },
  91. {
  92. label: '2年',
  93. value: '2_3',
  94. key: '730',
  95. },
  96. {
  97. label: '3年',
  98. value: '3_3',
  99. key: '1095',
  100. },
  101. {
  102. label: '5年',
  103. value: '3_5',
  104. key: '1825',
  105. },
  106. ],
  107. },
  108. colProps: {
  109. span: 18,
  110. },
  111. },
  112. ];
  113. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  114. labelWidth: 120,
  115. schemas: [
  116. {
  117. field: 'useType',
  118. component: 'ApiSelect',
  119. required: true,
  120. label: '使用类型',
  121. componentProps: {
  122. // filterOption: onFilterOption,
  123. // showSearch: true,
  124. api: incrementUseTypeList,
  125. labelField: 'name',
  126. valueField: 'id',
  127. immediate: true,
  128. },
  129. itemProps: {
  130. autoLink: false,
  131. },
  132. colProps: {
  133. span: 20,
  134. },
  135. },
  136. ...Addschemas,
  137. ...schemas,
  138. ...remarkschemas,
  139. ],
  140. showActionButtonGroup: false,
  141. actionColOptions: {
  142. span: 24,
  143. },
  144. });
  145. onMounted(() => {});
  146. let addListFunc = () => {};
  147. const [register, { closeModal }] = useModalInner((data) => {
  148. data && onDataReceive(data);
  149. });
  150. async function onDataReceive(data) {
  151. resetFields();
  152. fileFlow.id = data.id;
  153. updateSchema([
  154. {
  155. field: 'useType',
  156. componentProps: {
  157. onChange: (value) => {
  158. updateSchema({ field: 'projectNum', ifShow: value == '4' });
  159. },
  160. },
  161. },
  162. {
  163. field: 'projectNum',
  164. ifShow: data.useType == '4',
  165. },
  166. ]);
  167. setFieldsValue(data);
  168. }
  169. async function handleConfirm() {
  170. const { id } = await validate();
  171. createConfirm({
  172. iconType: 'warning',
  173. title: () => h('span', '温馨提示'),
  174. content: () => h('span', `确定要${id ? '编辑' : '新增'}授权吗?`),
  175. onOk: async () => {
  176. handleSubmit();
  177. },
  178. });
  179. }
  180. const handleSubmit = async () => {
  181. try {
  182. const params = await validate();
  183. let authorizeTime = params.authorizeTime.split('_');
  184. const apiData = {
  185. ...params,
  186. userId: params.id,
  187. authorizeTime: authorizeTime[0],
  188. authorizeTimeUnit: authorizeTime[1],
  189. };
  190. await authorizeModelingaddOrUpdate(apiData);
  191. closeModal();
  192. resetFields();
  193. createMessage.success(t('common.optSuccess'));
  194. emit('update');
  195. } catch (error) {
  196. console.log('not passing', error);
  197. }
  198. };
  199. function handleVisibleChange(v) {
  200. v && props.userData && nextTick(() => onDataReceive(props.userData));
  201. }
  202. return {
  203. register,
  204. registerForm,
  205. fileFlow,
  206. handleVisibleChange,
  207. handleSubmit,
  208. addListFunc,
  209. resetFields,
  210. handleConfirm,
  211. t,
  212. };
  213. },
  214. });
  215. </script>
  216. <style lang="less">
  217. .zdysrk {
  218. .ant-calendar-picker {
  219. min-width: 285px;
  220. }
  221. }
  222. </style>