AddInstallModal.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. 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 { remarkschemas, Addschemas } from './data';
  23. import { InvoiceRegister } from '/@/api/order';
  24. import { useI18n } from '/@/hooks/web/useI18n';
  25. import { uploadApi } from '/@/api/product/index';
  26. import { copyTextToClipboard } from '/@/hooks/web/useCopyToClipboard';
  27. import { ResultEnum } from '/@/enums/httpEnum';
  28. import { authorizeInstalladdOrUpdate, checkMachineCode } from '/@/api/authorizeModeling';
  29. import dayjs from 'dayjs';
  30. import { otherInfoStore } from '/@/store/modules/other';
  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 overviewInfo = computed(() => otherInfo.getOverviewInfo);
  41. // const overviewInfo = getOverviewInfo() || {}
  42. const fileFlow = reactive({
  43. file: null,
  44. id: '',
  45. key: '',
  46. type: 'down', //down-下载,equity-权益
  47. });
  48. const { createMessage, createConfirm, createSuccessModal } = useMessage();
  49. const schemas: FormSchema[] = [
  50. {
  51. field: 'id',
  52. component: 'Input',
  53. show: false,
  54. label: 'id',
  55. },
  56. {
  57. field: 'machineCode',
  58. component: 'InputTextArea',
  59. required: true,
  60. label: '机器码',
  61. componentProps: {
  62. rows: 4,
  63. },
  64. colProps: { span: 20 },
  65. },
  66. ];
  67. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  68. labelWidth: 120,
  69. schemas: [...Addschemas, ...schemas, ...remarkschemas],
  70. showActionButtonGroup: false,
  71. actionColOptions: {
  72. span: 24,
  73. },
  74. });
  75. onMounted(() => {});
  76. let addListFunc = () => {};
  77. const [register, { closeModal }] = useModalInner((data) => {
  78. data && onDataReceive(data);
  79. });
  80. async function onDataReceive(data) {
  81. resetFields();
  82. fileFlow.id = data.id;
  83. fileFlow.key = data.authorizeKey;
  84. updateSchema([
  85. {
  86. field: 'useType',
  87. componentProps: {
  88. onChange: (value) => {
  89. updateSchema({ field: 'projectNum', ifShow: value == '4' });
  90. },
  91. },
  92. },
  93. {
  94. field: 'projectNum',
  95. ifShow: data.useType == '4',
  96. },
  97. {
  98. field: 'machineCode',
  99. componentProps: {
  100. disabled: data.id ? true : false,
  101. },
  102. },
  103. ]);
  104. setFieldsValue(data);
  105. }
  106. async function handleConfirm() {
  107. const { id, machineCode } = await validate();
  108. let res = await checkMachineCode({ machineCode });
  109. console.log('res', res);
  110. if (res && !res.id) {
  111. createConfirm({
  112. iconType: 'warning',
  113. title: () => h('span', '温馨提示'),
  114. content: () => h('span', `当前设备已存在授权记录。`),
  115. okText: '继续',
  116. onOk: async () => {
  117. handleSubmit();
  118. },
  119. });
  120. } else {
  121. createConfirm({
  122. iconType: 'warning',
  123. title: () => h('span', '温馨提示'),
  124. content: () => h('span', `确定要${id ? '编辑' : '新增'}授权吗?`),
  125. onOk: async () => {
  126. handleSubmit();
  127. },
  128. });
  129. }
  130. }
  131. const handleSubmit = async () => {
  132. try {
  133. const params = await validate();
  134. console.log('validate', params);
  135. const apiData = {
  136. ...params,
  137. userId: params.id,
  138. };
  139. let res = await authorizeInstalladdOrUpdate(apiData);
  140. closeModal();
  141. resetFields();
  142. createSuccessModal({
  143. title: t('layout.setting.operatingTitle'),
  144. content: `安装Key:${res.authorizeKey || fileFlow.key}`,
  145. okText: '复制',
  146. onOk: async () => {
  147. // 双击复制
  148. copyTextToClipboard(res.authorizeKey || fileFlow.key);
  149. createMessage.success('复制成功');
  150. },
  151. });
  152. // createMessage.success(t('common.optSuccess'));
  153. emit('update');
  154. } catch (error) {
  155. console.log('not passing', error);
  156. }
  157. };
  158. function handleVisibleChange(v) {
  159. v && props.userData && nextTick(() => onDataReceive(props.userData));
  160. }
  161. return {
  162. register,
  163. registerForm,
  164. fileFlow,
  165. handleVisibleChange,
  166. handleSubmit,
  167. addListFunc,
  168. resetFields,
  169. handleConfirm,
  170. t,
  171. };
  172. },
  173. });
  174. </script>
  175. <style lang="less">
  176. .zdysrk {
  177. .ant-calendar-picker {
  178. min-width: 285px;
  179. }
  180. }
  181. </style>