AddCameraModal.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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, newAddschemas } 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 { authorizeCameraaddOrUpdate } from '/@/api/authorizeModeling';
  29. import { copyTextToClipboard } from '/@/hooks/web/useCopyToClipboard';
  30. import dayjs from 'dayjs';
  31. import { otherInfoStore } from '/@/store/modules/other';
  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. key: '',
  47. type: 'down', //down-下载,equity-权益
  48. });
  49. const { createMessage, createConfirm, createSuccessModal } = useMessage();
  50. const schemas: FormSchema[] = [
  51. {
  52. field: 'id',
  53. component: 'Input',
  54. show: false,
  55. label: 'id',
  56. },
  57. {
  58. field: 'machineCode',
  59. component: 'InputTextArea',
  60. required: true,
  61. componentProps: {
  62. rows: 4,
  63. },
  64. label: '机器码',
  65. colProps: { span: 20 },
  66. },
  67. {
  68. field: 'modelAuthCode',
  69. component: 'Input',
  70. required: true,
  71. label: '算法授权码',
  72. colProps: { span: 20 },
  73. componentProps: {
  74. maxlength: 100,
  75. },
  76. },
  77. {
  78. field: 'snCodes',
  79. component: 'InputTextArea',
  80. required: true,
  81. label: '授权SN码',
  82. componentProps: {
  83. placeholder: '请输入授权SN码,多个sn码换行输入',
  84. rows: 4,
  85. },
  86. colProps: { span: 20 },
  87. },
  88. ];
  89. const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
  90. labelWidth: 120,
  91. schemas: [...newAddschemas, ...Addschemas, ...schemas, ...remarkschemas],
  92. showActionButtonGroup: false,
  93. actionColOptions: {
  94. span: 24,
  95. },
  96. });
  97. onMounted(() => {});
  98. let addListFunc = () => {};
  99. const [register, { closeModal }] = useModalInner((data) => {
  100. data && onDataReceive(data);
  101. });
  102. async function onDataReceive(data) {
  103. resetFields();
  104. fileFlow.id = data.id;
  105. fileFlow.key = data.authorizeKey;
  106. updateSchema([
  107. {
  108. field: 'useType',
  109. componentProps: {
  110. onChange: useTypeChange,
  111. },
  112. },
  113. {
  114. field: 'projectNum',
  115. ifShow: data.useType == '4',
  116. },
  117. {
  118. field: 'machineCode',
  119. componentProps: {
  120. disabled: data.id ? true : false,
  121. },
  122. },
  123. {
  124. field: 'snCodes',
  125. componentProps: {
  126. disabled: data.id ? true : false,
  127. },
  128. },
  129. ]);
  130. useTypeChange(data.useType || 0);
  131. setFieldsValue(data);
  132. }
  133. const useTypeChange = (value) => {
  134. updateSchema([
  135. { field: 'projectNum', ifShow: value == '4' },
  136. { field: 'companyName', ifShow: value != '3' },
  137. { field: 'businessDept', ifShow: value != '3' },
  138. { field: 'businessName', ifShow: value != '3' },
  139. { field: 'customerPayTime', ifShow: value != '3' },
  140. { field: 'customerName', ifShow: value != '3' },
  141. { field: 'customerType', ifShow: value != '3' },
  142. { field: 'endCustomer', ifShow: value != '3' },
  143. ]);
  144. };
  145. async function handleConfirm() {
  146. const { id } = await validate();
  147. createConfirm({
  148. iconType: 'warning',
  149. title: () => h('span', '温馨提示'),
  150. content: () => h('span', `确定要${id ? '编辑' : '新增'}授权吗?`),
  151. onOk: async () => {
  152. handleSubmit();
  153. },
  154. });
  155. }
  156. const handleSubmit = async () => {
  157. try {
  158. const params = await validate();
  159. console.log('params', params)
  160. // let authorizeTime = params.authorizeTime.split('_');
  161. const apiData = {
  162. ...params,
  163. snCodes:params.snCodes && params.snCodes.split(' ').join(''),
  164. machineCode:params.machineCode && params.machineCode.replace(/\s*/g,""),
  165. userId: params.id,
  166. // authorizeTime: authorizeTime[0],
  167. // authorizeTimeUnit: authorizeTime[1],
  168. };
  169. console.log('apiData', apiData)
  170. let res = await authorizeCameraaddOrUpdate(apiData);
  171. let count = (res.snCodes && res.snCodes.split('\n')) || [];
  172. closeModal();
  173. resetFields();
  174. createSuccessModal({
  175. title: t('layout.setting.operatingTitle'),
  176. content: h('div', {}, [
  177. h('p', `授权Key:${res.authorizeKey || fileFlow.key}`),
  178. h('p', `授权相机数量:${count.length}`),
  179. ]),
  180. okText: '复制授权Key',
  181. onOk: async () => {
  182. // 双击复制
  183. copyTextToClipboard(res.authorizeKey || fileFlow.key);
  184. createMessage.success('复制成功');
  185. },
  186. });
  187. // createMessage.success(t('common.optSuccess'));
  188. emit('update');
  189. } catch (error) {
  190. console.log('not passing', error);
  191. }
  192. };
  193. function handleVisibleChange(v) {
  194. v && props.userData && nextTick(() => onDataReceive(props.userData));
  195. }
  196. return {
  197. register,
  198. registerForm,
  199. fileFlow,
  200. handleVisibleChange,
  201. handleSubmit,
  202. addListFunc,
  203. resetFields,
  204. handleConfirm,
  205. t,
  206. };
  207. },
  208. });
  209. </script>
  210. <style lang="less">
  211. .zdysrk {
  212. .ant-calendar-picker {
  213. min-width: 285px;
  214. }
  215. }
  216. </style>