riku
2023-12-19 7e9a217f6d3610d612328112ee538481f7db089b
src/views/fytz/user/components/CompUserInfo.vue
@@ -33,7 +33,9 @@
        </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>
@@ -52,13 +54,20 @@
      </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
@@ -83,9 +92,7 @@
<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 props = defineProps({
  //基本信息
@@ -93,37 +100,36 @@
  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: [
  //   {
@@ -136,30 +142,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);
@@ -169,19 +175,6 @@
  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)
@@ -189,7 +182,6 @@
      emit('onSubmit', formObj);
    })
    .finally(() => {
      _formObject.value = formObj.value;
      func();
    });
}
@@ -201,32 +193,38 @@
      emit('onSubmit', formObj);
    })
    .finally(() => {
      _formObject.value = formObj.value;
      if (func) 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];
  }
  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 props.create ? createUser(formObj, func) : updateUser(formObj, func);
}
@@ -239,7 +237,6 @@
  () => props.formInfo,
  (nValue) => {
    _formInfo.value = parseUserInfo(nValue);
    _formObject.value = _formInfo.value;
  }
);
@@ -247,21 +244,5 @@
  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>