|
@@ -2,7 +2,7 @@
|
|
|
<BasicModal
|
|
|
v-bind="$attrs"
|
|
|
@register="register"
|
|
|
- title="新增子账号"
|
|
|
+ :title="t('routes.devices.addSubAccount')"
|
|
|
@visible-change="handleVisibleChange"
|
|
|
@ok="handleSubmit"
|
|
|
>
|
|
@@ -12,11 +12,11 @@
|
|
|
</BasicModal>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
- import { defineComponent, ref, nextTick } from 'vue';
|
|
|
+ import { defineComponent, ref, nextTick, onMounted } from 'vue';
|
|
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
|
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
- import { checkUserAddAble } from '/@/api/corporation/modal';
|
|
|
+ import { allCompanyApi, addCameraApi } from '/@/api/device/list';
|
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
|
// address: "11111"
|
|
|
// balance: "111"
|
|
@@ -29,107 +29,131 @@
|
|
|
// snCode: "1111"
|
|
|
// wifiName: "1111"
|
|
|
const { t } = useI18n();
|
|
|
- const schemas: FormSchema[] = [
|
|
|
- {
|
|
|
- field: 'own',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.own'),
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- componentProps: {
|
|
|
- options: [
|
|
|
- {
|
|
|
- label: '全部',
|
|
|
- value: '1',
|
|
|
- key: '1',
|
|
|
- },
|
|
|
- {
|
|
|
- label: '正常',
|
|
|
- value: '2',
|
|
|
- key: '2',
|
|
|
- },
|
|
|
- {
|
|
|
- label: '已关闭',
|
|
|
- value: '2',
|
|
|
- key: '2',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- required: true,
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'cameraType',
|
|
|
- component: 'Select',
|
|
|
- label: t('routes.devices.cameraType'),
|
|
|
- required: true,
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'childName',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.childName'),
|
|
|
- required: true,
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'wifiName',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.wifiName'),
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'address',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.address'),
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'balance',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.balance'),
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'orderSn',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.orderSn'),
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- required: true,
|
|
|
- },
|
|
|
- {
|
|
|
- field: 'companyId',
|
|
|
- component: 'Input',
|
|
|
- label: t('routes.devices.companyId'),
|
|
|
- colProps: {
|
|
|
- span: 24,
|
|
|
- },
|
|
|
- },
|
|
|
- ];
|
|
|
export default defineComponent({
|
|
|
components: { BasicModal, BasicForm },
|
|
|
props: {
|
|
|
userData: { type: Object },
|
|
|
},
|
|
|
- setup(props) {
|
|
|
+ setup(props, { emit }) {
|
|
|
const modelRef = ref({});
|
|
|
const { createMessage } = useMessage();
|
|
|
+ const schemas: FormSchema[] = [
|
|
|
+ {
|
|
|
+ field: 'own',
|
|
|
+ component: 'Select',
|
|
|
+ label: t('routes.devices.own'),
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ componentProps: {
|
|
|
+ options: [0, 2, 1, 3].map((ele) => {
|
|
|
+ return { value: ele, key: ele, label: renderOwnTypeLabel(ele) };
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'cameraType',
|
|
|
+ component: 'Select',
|
|
|
+ label: t('routes.devices.cameraType'),
|
|
|
+ required: true,
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ componentProps: {
|
|
|
+ options: [4, 1, 9, 10, 6].map((ele) => {
|
|
|
+ return { value: ele, key: ele, label: rendercameraTypeLabel(ele) };
|
|
|
+ }),
|
|
|
+ onChange: function (val) {
|
|
|
+ console.log('appendSchemaByField', val);
|
|
|
+ if (val !== 6) {
|
|
|
+ appendSchemaByField(
|
|
|
+ {
|
|
|
+ field: 'snCode',
|
|
|
+ component: 'Input',
|
|
|
+ label: t('routes.devices.snCode'),
|
|
|
+ required: true,
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'address',
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ removeSchemaByFiled('snCode');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'childName',
|
|
|
+ component: 'Input',
|
|
|
+ label: t('routes.devices.childName'),
|
|
|
+ required: true,
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'wifiName',
|
|
|
+ component: 'Input',
|
|
|
+ label: t('routes.devices.wifiName'),
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'address',
|
|
|
+ component: 'Input',
|
|
|
+ label: t('routes.devices.address'),
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'balance',
|
|
|
+ component: 'Input',
|
|
|
+ label: t('routes.devices.balance'),
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'orderSn',
|
|
|
+ component: 'Input',
|
|
|
+ label: t('routes.devices.orderSn'),
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'companyId',
|
|
|
+ component: 'ApiSelect',
|
|
|
+ label: t('routes.devices.companyId'),
|
|
|
+ componentProps: {
|
|
|
+ api: allCompanyApi,
|
|
|
+ numberToString: true,
|
|
|
+ labelField: 'name',
|
|
|
+ valueField: 'id',
|
|
|
+ immediate: true,
|
|
|
+ params: {
|
|
|
+ page: 1,
|
|
|
+ limit: 1000,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
const [
|
|
|
registerForm,
|
|
|
{
|
|
|
getFieldsValue,
|
|
|
+ validateFields,
|
|
|
+ appendSchemaByField,
|
|
|
+ removeSchemaByFiled,
|
|
|
// setFieldsValue,
|
|
|
// setProps
|
|
|
},
|
|
@@ -141,11 +165,41 @@
|
|
|
span: 24,
|
|
|
},
|
|
|
});
|
|
|
+ onMounted(() => {});
|
|
|
let addListFunc = () => {};
|
|
|
const [register, { closeModal }] = useModalInner((data) => {
|
|
|
data && onDataReceive(data);
|
|
|
});
|
|
|
-
|
|
|
+ function renderOwnTypeLabel(type: number): string {
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ return t('routes.devices.ownName.0');
|
|
|
+ case 2:
|
|
|
+ return t('routes.devices.ownName.2');
|
|
|
+ case 1:
|
|
|
+ return t('routes.devices.ownName.1');
|
|
|
+ case 3:
|
|
|
+ return t('routes.devices.ownName.3');
|
|
|
+ default:
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function rendercameraTypeLabel(cameraType: number): string {
|
|
|
+ switch (cameraType) {
|
|
|
+ case 4:
|
|
|
+ return t('routes.devices.cameraName.4');
|
|
|
+ case 1:
|
|
|
+ return t('routes.devices.cameraName.1');
|
|
|
+ case 9:
|
|
|
+ return t('routes.devices.cameraName.9');
|
|
|
+ case 10:
|
|
|
+ return t('routes.devices.cameraName.10');
|
|
|
+ case 6:
|
|
|
+ return t('routes.devices.cameraName.6');
|
|
|
+ default:
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
function onDataReceive(data) {
|
|
|
console.log('Data Received', data);
|
|
|
const { addList } = data;
|
|
@@ -156,22 +210,19 @@
|
|
|
}
|
|
|
const handleSubmit = async () => {
|
|
|
console.log('getFieldsValue()', getFieldsValue());
|
|
|
- var reg_tel =
|
|
|
- /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
|
|
|
- let { phone, memoName } = getFieldsValue();
|
|
|
- if (phone == '') {
|
|
|
- createMessage.error('请填写您的手机号码!');
|
|
|
- return false;
|
|
|
- } else if (!reg_tel.test(phone)) {
|
|
|
- createMessage.error('请正确填写您的手机号码!');
|
|
|
- return false;
|
|
|
- }
|
|
|
- let res = await checkUserAddAble({ phone });
|
|
|
- if (res.result == false) {
|
|
|
- addListFunc({ phone, memoName });
|
|
|
- closeModal();
|
|
|
- } else {
|
|
|
- createMessage.error('子账号已被该企业绑定');
|
|
|
+ try {
|
|
|
+ const data = await validateFields();
|
|
|
+ const param = await getFieldsValue();
|
|
|
+ let res = await addCameraApi(param);
|
|
|
+ console.log('getFieldsValue()', res, data, param);
|
|
|
+ if (res.code) {
|
|
|
+ createMessage.error(res.error || t('common.optFail'));
|
|
|
+ } else {
|
|
|
+ emit('getList');
|
|
|
+ closeModal();
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log('not passing', error);
|
|
|
}
|
|
|
};
|
|
|
function handleVisibleChange(v) {
|
|
@@ -180,13 +231,15 @@
|
|
|
|
|
|
return {
|
|
|
register,
|
|
|
+ rendercameraTypeLabel,
|
|
|
+ renderOwnTypeLabel,
|
|
|
schemas,
|
|
|
registerForm,
|
|
|
model: modelRef,
|
|
|
handleVisibleChange,
|
|
|
handleSubmit,
|
|
|
addListFunc,
|
|
|
- closeModal,
|
|
|
+ t,
|
|
|
};
|
|
|
},
|
|
|
});
|