猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

406 lines
9.0 KiB

<template>
<view class="page bg-fff">
<view class="size-22 color-ffb flex-rowl tip">
<image class="icon" :src="configList.my_information_statement.paramValueImage"></image>
<view>
<up-parse :content="configList.my_information_statement.paramValueArea" containerStyle="{
color: '#FFBF60',
fontSize: '22rpx',
lineHeight: '40rpx',
}"></up-parse>
</view>
</view>
<view class="info">
<view class="title mt24">
基本资料
</view>
<view class="flex-colc">
<button class="btn-avatar" :plain="true" :hairline="false" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<view class="flex-colc">
<image class="head" :src="baseInfo.info.userImage" mode="widthFix"></image>
<!-- <image class="head" :src="form.headImage" mode="widthFix"></image> -->
<text class="size-28 color-999 mt10">点击更换头像</text>
</view>
</button>
</view>
<view class="form">
<view class="form-item flex-rowb">
<view class="size-28">昵称</view>
<view class="flex-rowr">
<input type="text" placeholder="请输入" v-model="form.nickname" class="input-right" />
</view>
</view>
<view class="form-item flex-rowb">
<view class="size-28">手机号</view>
<view class="flex-rowr">
<text>{{baseInfo.info.userTelephone || ''}}</text>
</view>
</view>
<view class="form-item flex-rowb">
<view class="size-28">性别</view>
<view class="flex-rowr" @click="openGenderSelect">
<text>{{form.gender || '请选择'}}</text>
<up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
</view>
</view>
</view>
</view>
<view class="info">
<view class="title mt24 flex-rowl">
展示信息
<text class="size-22 color-ffb fw700">(重要)</text>
</view>
<view class="form">
<view class="form-item flex-rowb">
<view class="size-28">个人简介</view>
<view class="flex-rowr">
<textarea v-model="form.introduction" placeholder="请输入" class="textarea-full" maxlength="200"></textarea>
</view>
</view>
<view class="form-item flex-rowb">
<view class="size-28">养宠经验</view>
<view class="flex-rowr">
<input type="number" v-model="form.petExperience" placeholder="请输入您的养宠年限" class="input-right" />
<text class="ml10">年</text>
</view>
</view>
<view class="form-item flex-rowb">
<view class="size-28">服务记录</view>
<view class="flex-rowr" @click="jumpToServeRecord">
<text>{{ `${serviceCount}条` }}</text>
<up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
</view>
</view>
</view>
</view>
<view class="info">
<view class="title mt24 flex-rowl">
服务资料
</view>
<view class="form">
<view class="form-item flex-rowb">
<view class="size-28">服务宠物类型</view>
<view class="flex-rowr" @click="openTypeSelectPopup">
<text>{{ typeDesc }}</text>
<up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
</view>
</view>
<view class="form-item flex-rowb">
<view class="size-28">基础服务</view>
<view class="flex-rowr">
<text>宠物喂养 上门遛狗</text>
</view>
</view>
<view class="form-item flex-rowb">
<view class="size-28">增值服务</view>
<view class="flex-rowr" @click="openServeSelectPopup">
<text>{{ serveDesc }}</text>
<up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
</view>
</view>
</view>
</view>
<view class="size-24 color-ffb flex-rowc mt32 pb28">
伴宠师查看服务酬劳、服务时长等规则
</view>
<popupTypeSelect ref="popupTypeSelectRef" v-model="form.type" @confirm="fetchUpdate" ></popupTypeSelect>
<popupServeSelect ref="popupServeSelectRef" v-model="form.serve" @confirm="fetchUpdate" ></popupServeSelect>
<view class="uni-btn-color"
@click="submit">
保存
</view>
</view>
</template>
<script setup>
import { ref, reactive, computed, onMounted, nextTick } from "vue";
import { useStore } from 'vuex'
import { onShow } from '@dcloudio/uni-app'
import { ossUpload } from '@/utils/oss-upload/oss/index.js'
import popupTypeSelect from "./popupTypeSelect.vue";
import popupServeSelect from "./popupServeSelect.vue";
import { serviceLogList } from '@/api/serviceLog'
import {
binBaseInfo,
} from "@/api/home.js"
const store = useStore()
const configList = computed(() => {
return store.getters.configList
})
const userInfo = computed(() => {
return store.getters.userInfo
})
const baseInfo = ref(JSON.parse(uni.getStorageSync("baseInfo")))
const serviceCount = ref(0)
const form = reactive({
headImage: null,
nickname: '',
gender: '',
introduction: '',
petExperience: '',
type: [],
serve: [],
})
const onChooseAvatar = (res) => {
ossUpload(res.target.avatarUrl)
.then(url => {
form.headImage = url
fetchUpdate()
})
}
const baseInfoRef = ref(null)
const displayInfoRef = ref(null)
const serveInfoRef = ref(null)
const jumpToServeRecord = () => {
uni.navigateTo({
url: "/otherPages/authentication/serve/record"
})
}
const popupTypeSelectRef = ref()
const openTypeSelectPopup = () => {
popupTypeSelectRef.value.open()
}
const petTypeOptions = computed(() => {
return store.getters.petTypeOptions
})
const typeDesc = computed(() => {
const typeIds = form.type
if (!typeIds.length) {
return '请选择'
}
let descArr = typeIds.map(typeId => {
return petTypeOptions.value.find(item => item.id === typeId).title
})
return descArr.join('、')
})
const popupServeSelectRef = ref()
const increaseServiceOptions = computed(() => {
return store.getters.increaseServiceOptions
})
const openServeSelectPopup = () => {
popupServeSelectRef.value.open()
}
const serveDesc = computed(() => {
const serveIds = form.serve
if (!serveIds.length) {
return '请选择'
}
let descArr = serveIds.map(serveId => {
return increaseServiceOptions.value.find(option => option.id === serveId)?.title
})
return descArr.join('、')
})
function getCountSerivce(){
serviceLogList({ userId: userInfo.value.userId })
.then(res => {
serviceCount.value = res.length
})
}
const getBaseInfo = () => {
binBaseInfo(baseInfo.value.userId).then(res => {
baseInfo.value = res.data
uni.setStorageSync(JSON.stringify(res.data))
// baseInfoRef.value.setData(res.data.info)
})
}
const genderOptions = [
{ text: '男', value: '男' },
{ text: '女', value: '女' }
]
const openGenderSelect = () => {
uni.showActionSheet({
itemList: genderOptions.map(item => item.text),
success: function (res) {
form.gender = genderOptions[res.tapIndex].value
fetchUpdate()
}
})
}
const fetchUpdate = () => {
// 这里可以添加更新数据的逻辑
console.log('更新数据', form)
}
function submit(){
// 表单验证
if (!form.nickname) {
uni.showToast({
title: '请输入昵称',
icon: 'none'
})
return
}
// 提交表单数据
console.log('提交表单数据', form)
uni.showToast({
title: '保存成功',
icon: 'success'
})
}
onShow(() => {
getCountSerivce()
getBaseInfo()
store.dispatch('fetchPetTypeOptions')
store.dispatch('fetchIncreaseServiceOptions')
})
onMounted(()=> {
// todo: fetch data and init data
// 初始化表单数据
if (baseInfo.value && baseInfo.value.info) {
form.nickname = baseInfo.value.info.userName || ''
form.gender = baseInfo.value.info.gender || ''
}
})
</script>
<style lang="scss" scoped>
.form{
.form-item {
min-height: 90rpx;
padding-top: 10rpx;
width: 100%;
border-bottom: 1rpx solid #f5f5f5;
}
.flex-rowr {
display: flex;
justify-content: flex-end;
align-items: center;
}
.flex-rowb {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 0;
}
.ml10 {
margin-left: 10rpx;
}
.input-right {
text-align: right;
}
.textarea-full {
width: 100%;
min-height: 120rpx;
text-align: right;
}
}
.page {
padding-top: 16rpx;
padding-bottom: 150rpx;
.tip {
background-color: rgba($color: #FFBF60, $alpha: 0.16);
padding: 13rpx 22rpx;
margin: 0 28rpx 37rpx 28rpx;
.icon {
width: 36rpx;
height: 36rpx;
margin-right: 15rpx;
}
}
}
.info {
& + & {
margin-top: 50rpx;
}
}
.head {
width: 165rpx;
height: auto;
margin-top: 28rpx;
}
.btn-avatar {
border: none;
padding: 0;
}
.title {
font-size: 30rpx;
font-weight: 700;
display: flex;
align-items: center;
padding: 0 40rpx;
&:before {
display: inline-block;
content: "";
width: 10rpx;
border-radius: 5rpx;
height: 33rpx;
background-color: #FFBF60;
margin-right: 7rpx;
}
}
.form {
padding: 0 22rpx;
:deep(.form-item){
padding-left: 24rpx;
padding-right: 30rpx;
box-sizing: border-box;
}
}
.uni-btn-color{
border-radius: 40rpx;
padding: 20rpx;
margin: 40rpx;
background: #FFBF60;
color: #fff;
text-align: center;
font-size: 28rpx;
}
</style>