100 lines
3.2 KiB
Vue
100 lines
3.2 KiB
Vue
<script setup lang="ts">
|
|
import { reactive, ref, computed } from "vue"
|
|
import { onLoad, onShow } from "@dcloudio/uni-app"
|
|
|
|
import { storageConstant } from "@@/constant"
|
|
import { userApi } from '@@/api'
|
|
|
|
const emit = defineEmits(["close"])
|
|
|
|
type ModifyUserProps = {
|
|
warnText?: string
|
|
}
|
|
|
|
const props = withDefaults(defineProps<ModifyUserProps>(), {
|
|
warnText: ''
|
|
})
|
|
|
|
const formRef = ref<any>(null)
|
|
|
|
const showQrCodeDialog = ref(false)
|
|
const form = reactive({
|
|
name: "",
|
|
phone: "",
|
|
birthday: ""
|
|
})
|
|
|
|
const rules = {
|
|
birthday: [{ required: true, message: '请输入生日' }],
|
|
}
|
|
|
|
// 修改用户信息
|
|
const doFormSubmit = async () => {
|
|
formRef.value.submit()
|
|
const { isPass } = formRef.value.validate()
|
|
if (!isPass) return
|
|
uni.showLoading({ title: "修改中...", mask: true })
|
|
try {
|
|
const res: any = await userApi.appModifyUser({ ...form })
|
|
if (res.code != 0) {
|
|
uni.showToast({ title: res.msg ?? "修改失败", icon: "none" })
|
|
return
|
|
}
|
|
uni.showToast({ title: "修改成功", icon: "success" })
|
|
// 存入缓存
|
|
const { data: userData } = await userApi.userInfo()
|
|
uni.setStorageSync(storageConstant.USERINFO, userData)
|
|
|
|
showQrCodeDialog.value = false
|
|
setTimeout(() => uni.hideLoading(), 1000);
|
|
} catch (error) {
|
|
console.log("|修改用户信息|意外的错误error:", error);
|
|
uni.hideLoading()
|
|
}
|
|
}
|
|
|
|
const open = () => {
|
|
const user = uni.getStorageSync(storageConstant.USERINFO)
|
|
if (user && user.sysUser) {
|
|
form.name = user.sysUser.name
|
|
form.phone = user.sysUser.phone
|
|
form.birthday = user.sysUser.birthday
|
|
}
|
|
showQrCodeDialog.value = true
|
|
}
|
|
|
|
defineExpose({
|
|
open
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<tm-drawer z-index="100" v-model:show="showQrCodeDialog" title="编辑个人资料" :show-close="true" position="bottom"
|
|
size="70%" @close="emit('close')">
|
|
<view v-if="warnText" class="py-20rpx">
|
|
<tm-alert status="warn" :showClose="false" :margin="[]">{{ warnText }}</tm-alert>
|
|
</view>
|
|
<view class="card p-x-30rpx p-y-40rpx">
|
|
<view class="h-30rpx" />
|
|
<tm-form ref="formRef" v-model="form" :rules="rules">
|
|
<tm-form-item name="name" label="姓名">
|
|
<tm-input v-model="form.name" disabled>
|
|
</tm-input>
|
|
</tm-form-item>
|
|
<tm-form-item name="phone" label="手机号">
|
|
<tm-input v-model="form.phone" disabled>
|
|
</tm-input>
|
|
</tm-form-item>
|
|
<tm-form-item name="birthday" label="出生日期" :show-bottom="false">
|
|
<tm-picker-date v-model="form.birthday" v-model:model-str="form.birthday" format="YYYY-MM-DD"
|
|
start="1950-1-1" end="2030-12-31">
|
|
<tm-input v-model="form.birthday" style="pointer-events: none" disabled>
|
|
</tm-input>
|
|
</tm-picker-date>
|
|
</tm-form-item>
|
|
<view class="h-30rpx" />
|
|
<tm-button block @tap="doFormSubmit">修改</tm-button>
|
|
</tm-form>
|
|
</view>
|
|
</tm-drawer>
|
|
</template> |