| | |
| | | <FYForm |
| | | :form-info="_formInfo" |
| | | :rules="rules" |
| | | :reset="active" |
| | | :doClear="active" |
| | | :useCancel="create" |
| | | :useReset="!create" |
| | | :clearAftSubmit="create" |
| | | v-model:is-edit="_edit" |
| | | @submit="submit" |
| | | @cancel="cancel" |
| | |
| | | </el-col> |
| | | </el-form-item> |
| | | <FYOptionUserType |
| | | prop="_usertype" |
| | | :allOption="false" |
| | | :initValue="false" |
| | | v-model:value="formObj._usertype" |
| | |
| | | <el-form-item label="手机" prop="telephone"> |
| | | <el-input clearable type="tel" v-model="formObj.telephone" placeholder="手机" /> |
| | | </el-form-item> |
| | | <!-- <el-form-item label="省/市/区/镇" prop="_locations"> |
| | | <el-cascader |
| | | v-model="formObj._locations" |
| | | :options="locations" |
| | | placeholder="省/市/区/镇" |
| | | :props="locationsProps" |
| | | style="width: 280px" |
| | | :disabled="!create" |
| | | /> |
| | | </el-form-item> --> |
| | | <FYOptionLocation |
| | | v-if="create" |
| | | prop="_locations" |
| | | :allOption="false" |
| | | :level="5" |
| | | :checkStrictly="true" |
| | | :initValue="false" |
| | | v-model:value="formObj._locations" |
| | | ></FYOptionLocation> |
| | | <FYOptionScene |
| | | prop="_scenetype" |
| | | :allOption="false" |
| | | :type="1" |
| | | :initValue="false" |
| | |
| | | <script setup> |
| | | import { defineProps, defineEmits, reactive, ref, watch } from 'vue'; |
| | | import { getSceneName } from '@/enum/scene'; |
| | | import { enumLocation } from '@/enum/location'; |
| | | import userApi from '@/api/fytz/userApi'; |
| | | import { useMessageBoxTip } from '@/composables/messageBox'; |
| | | |
| | |
| | | |
| | | const emit = defineEmits(['onSubmit', 'onCancel', 'update:isEdit']); |
| | | |
| | | const _formInfo = ref(); |
| | | const _formObject = { value: {} }; |
| | | const _formInfo = ref({ isenable: true }); |
| | | const _edit = ref(false); |
| | | const locations = enumLocation(false); |
| | | const locationsProps = reactive({ |
| | | checkStrictly: true |
| | | }); |
| | | const rules = reactive({ |
| | | acountname: [ |
| | | { |
| | |
| | | // trigger: 'blur', |
| | | // }, |
| | | // ], |
| | | _usertype: [ |
| | | { |
| | | required: true, |
| | | message: '用户类型不能为空', |
| | | trigger: 'change' |
| | | } |
| | | ], |
| | | _locations: [ |
| | | { |
| | | required: props.create, |
| | | message: '省/市/区/镇不能为空', |
| | | trigger: 'change' |
| | | } |
| | | ], |
| | | _scenetype: [ |
| | | { |
| | | required: true, |
| | | message: '场景类型不能为空', |
| | | trigger: 'change' |
| | | } |
| | | ] |
| | | }); |
| | | |
| | | // 用户基本信息格式化 |
| | |
| | | |
| | | s._scenetype = getSceneName(s.extension2, 1); |
| | | |
| | | s._locations = []; |
| | | s._locations = {}; |
| | | |
| | | return s; |
| | | } |
| | | |
| | | function parseUserInfoReverse(formObj) { |
| | | // 行政区划信息填充 |
| | | const a = formObj.value._locations; |
| | | formObj.value.extension1 = a.dName; |
| | | // 用户类型信息填充 |
| | | const b = formObj.value._usertype; |
| | | formObj.value.usertypeid = b.value; |
| | |
| | | return formObj; |
| | | } |
| | | |
| | | function createUser(formObj, func) { |
| | | function createUser(formObj, success, fail) { |
| | | const l = formObj.value._locations; |
| | | const params = { |
| | | userInfo: formObj.value, |
| | | baseInfo: { |
| | | biProvinceCode: l.pCode, |
| | | biProvinceName: l.pName, |
| | | biCityCode: l.cCode, |
| | | biCityName: l.cName, |
| | | biDistrictCode: l.dCode, |
| | | biDistrictName: l.dName, |
| | | biTownCode: l.tCode, |
| | | biTownName: l.tName, |
| | | biAreaCode: l.aCode, |
| | | biArea: l.aName, |
| | | // biManagementCompanyId: |
| | | // biManagementCompany: |
| | | // biContact |
| | | // biTelephone |
| | | // biAddress |
| | | } |
| | | }; |
| | | return userApi |
| | | .createUser(formObj.value) |
| | | .createUser(params) |
| | | .then(() => { |
| | | emit('onSubmit', formObj); |
| | | emit('onSubmit', params); |
| | | success(); |
| | | }) |
| | | .finally(() => { |
| | | _formObject.value = formObj.value; |
| | | func(); |
| | | .catch((err) => { |
| | | fail(err); |
| | | }); |
| | | } |
| | | |
| | | function updateUser(formObj, func) { |
| | | function updateUser(formObj, success, fail) { |
| | | return userApi |
| | | .updateUserInfo(formObj.value) |
| | | .then(() => { |
| | | emit('onSubmit', formObj); |
| | | if (success) success(); |
| | | }) |
| | | .finally(() => { |
| | | _formObject.value = formObj.value; |
| | | if (func) func(); |
| | | .catch((err) => { |
| | | if (fail) fail(err); |
| | | }); |
| | | } |
| | | |
| | | function submit(formObj, func) { |
| | | // 行政区划信息填充 |
| | | // const a = formObj.value._locations; |
| | | // if (a[0]) { |
| | | // formObj.value.provincecode = a[0][0]; |
| | | // formObj.value.provincename = a[0][1]; |
| | | // } |
| | | // if (a[1]) { |
| | | // formObj.value.citycode = a[1][0]; |
| | | // formObj.value.cityname = a[1][1]; |
| | | // } |
| | | // if (a[2]) { |
| | | // formObj.value.districtcode = a[2][0]; |
| | | // formObj.value.extension1 = a[2][1]; |
| | | // } |
| | | // if (a[3]) { |
| | | // formObj.value.towncode = a[3][0]; |
| | | // formObj.value.townname = a[3][1]; |
| | | // } |
| | | |
| | | function submit(formObj, success, fail) { |
| | | parseUserInfoReverse(formObj); |
| | | |
| | | return props.create ? createUser(formObj, func) : updateUser(formObj, func); |
| | | return props.create ? createUser(formObj, success, fail) : updateUser(formObj, success, fail); |
| | | } |
| | | |
| | | function cancel() { |
| | |
| | | () => props.formInfo, |
| | | (nValue) => { |
| | | _formInfo.value = parseUserInfo(nValue); |
| | | _formObject.value = _formInfo.value; |
| | | } |
| | | ); |
| | | |
| | | // watch( |
| | | // () => props.create, |
| | | // (nValue) => { |
| | | // if (nValue) { |
| | | |
| | | // } |
| | | // }, |
| | | // {immediate:true} |
| | | // ); |
| | | |
| | | watch(_edit, (nValue) => { |
| | | emit('update:isEdit', nValue); |
| | | }); |
| | | |
| | | |
| | | // 重置密码 |
| | | |
| | |
| | | confirmMsg: '是否重置该场景密码?', |
| | | confirmTitle: '重置密码', |
| | | onConfirm: async () => { |
| | | pwLoading.value = true |
| | | _formObject.value.password = '123456'; |
| | | await updateUser(_formObject); |
| | | pwLoading.value = false |
| | | pwLoading.value = true; |
| | | return userApi.resetPassword(props.formInfo.guid).finally(() => { |
| | | pwLoading.value = false; |
| | | }); |
| | | } |
| | | }); |
| | | } |