src/views/fytz/user/components/CompUserInfo.vue
@@ -33,9 +33,7 @@
        </el-col>
        <el-col :span="6" v-if="!create">
          <el-row justify="end">
            <el-button type="danger" @click="onResetPw" :loading="pwLoading"
              >重置密码</el-button
            >
            <el-button type="danger" @click="onResetPw" :loading="pwLoading">重置密码</el-button>
          </el-row>
        </el-col>
      </el-form-item>
@@ -54,20 +52,13 @@
      </el-form-item> -->
      <el-form-item label="是否可用" prop="isenable">
        <el-switch v-model="formObj.isenable" />
        <span style="margin-left: 16px">{{
          formObj.isenable ? '可用' : '不可用'
        }}</span>
        <span style="margin-left: 16px">{{ formObj.isenable ? '可用' : '不可用' }}</span>
      </el-form-item>
      <el-form-item label="工号" prop="workno">
        <el-input clearable v-model="formObj.workno" placeholder="工号" />
      </el-form-item>
      <el-form-item label="手机" prop="telephone">
        <el-input
          clearable
          type="tel"
          v-model="formObj.telephone"
          placeholder="手机"
        />
        <el-input clearable type="tel" v-model="formObj.telephone" placeholder="手机" />
      </el-form-item>
      <!-- <el-form-item label="省/市/区/镇" prop="_locations">
        <el-cascader
@@ -94,6 +85,7 @@
import { getSceneName } from '@/enum/scene';
import { enumLocation } from '@/enum/location';
import userApi from '@/api/fytz/userApi';
import { useMessageBoxTip } from '@/composables/messageBox';
const props = defineProps({
  //基本信息
@@ -101,36 +93,37 @@
  isEdit: Boolean,
  create: {
    type: Boolean,
    default: false,
    default: false
  },
  active: {
    type: Boolean,
    default: false,
  },
    default: false
  }
});
const emit = defineEmits(['onSubmit', 'onCancel', 'update:isEdit']);
const _formInfo = ref();
const _formObject = { value: {} };
const _edit = ref(false);
const locations = enumLocation(false);
const locationsProps = reactive({
  checkStrictly: true,
  checkStrictly: true
});
const rules = reactive({
  acountname: [
    {
      required: true,
      message: '账户名不能为空',
      trigger: 'blur',
    },
      trigger: 'blur'
    }
  ],
  realname: [
    {
      required: true,
      message: '用户昵称不能为空',
      trigger: 'blur',
    },
      trigger: 'blur'
    }
  ],
  // password: [
  //   {
@@ -143,30 +136,30 @@
    {
      required: true,
      message: '用户类型不能为空',
      trigger: 'change',
    },
      trigger: 'change'
    }
  ],
  _locations: [
    {
      required: props.create,
      message: '省/市/区/镇不能为空',
      trigger: 'change',
    },
      trigger: 'change'
    }
  ],
  _scenetype: [
    {
      required: true,
      message: '场景类型不能为空',
      trigger: 'change',
    },
  ],
      trigger: 'change'
    }
  ]
});
// 用户基本信息格式化
function parseUserInfo(s) {
  s._usertype = {
    label: s.usertype,
    value: s.usertypeid + '',
    value: s.usertypeid + ''
  };
  s._scenetype = getSceneName(s.extension2, 1);
@@ -176,6 +169,19 @@
  return s;
}
function parseUserInfoReverse(formObj) {
  // 用户类型信息填充
  const b = formObj.value._usertype;
  formObj.value.usertypeid = b.value;
  formObj.value.usertype = b.label;
  // 场景类型信息填充
  const c = formObj.value._scenetype;
  formObj.value.extension2 = c.value;
  return formObj;
}
function createUser(formObj, func) {
  return userApi
    .createUser(formObj.value)
@@ -183,6 +189,7 @@
      emit('onSubmit', formObj);
    })
    .finally(() => {
      _formObject.value = formObj.value;
      func();
    });
}
@@ -194,38 +201,32 @@
      emit('onSubmit', formObj);
    })
    .finally(() => {
      func();
      _formObject.value = formObj.value;
      if (func) func();
    });
}
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];
  }
  // 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];
  // }
  // 用户类型信息填充
  const b = formObj.value._usertype;
  formObj.value.usertypeid = b.value;
  formObj.value.usertype = b.label;
  // 场景类型信息填充
  const c = formObj.value._scenetype;
  formObj.value.extension2 = c.value;
  parseUserInfoReverse(formObj);
  return props.create ? createUser(formObj, func) : updateUser(formObj, func);
}
@@ -238,6 +239,7 @@
  () => props.formInfo,
  (nValue) => {
    _formInfo.value = parseUserInfo(nValue);
    _formObject.value = _formInfo.value;
  }
);
@@ -245,5 +247,21 @@
  emit('update:isEdit', nValue);
});
// 重置密码
const pwLoading = ref(false);
function onResetPw() {
  useMessageBoxTip({
    confirmMsg: '是否重置该场景密码?',
    confirmTitle: '重置密码',
    onConfirm: async () => {
      pwLoading.value = true
      _formObject.value.password = '123456';
      await updateUser(_formObject);
      pwLoading.value = false
    }
  });
}
</script>