猫妈狗爸伴宠师小程序前端代码
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.

469 lines
12 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. <template>
  2. <view class="page bg-fff">
  3. <view class="size-22 color-ffb flex-rowl tip">
  4. <image class="icon" :src="configList.my_information_statement.paramValueImage"></image>
  5. <view>
  6. <up-parse :content="configList.my_information_statement.paramValueArea" containerStyle="{
  7. color: '#FFBF60',
  8. fontSize: '22rpx',
  9. lineHeight: '40rpx',
  10. }"></up-parse>
  11. </view>
  12. </view>
  13. <view class="info">
  14. <view class="title mt24">
  15. 基本资料
  16. </view>
  17. <view class="flex-colc">
  18. <button class="btn-avatar" :plain="true" :hairline="false" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  19. <view class="flex-colc">
  20. <image class="head" :src="form.headImage" mode="aspectFill"></image>
  21. <!-- <image class="head" :src="form.headImage" mode="widthFix"></image> -->
  22. <text class="size-28 color-999 mt10">点击更换头像</text>
  23. </view>
  24. </button>
  25. </view>
  26. <view class="form">
  27. <up-form label-position="left" :model="baseFormData" :rules="baseRules" ref="baseFormRef" labelWidth="200rpx">
  28. <up-form-item label="昵称" prop="userName">
  29. <up-input inputAlign="right" v-model="baseFormData.userName" placeholder="请输入" border="none" fontSize="28rpx"></up-input>
  30. </up-form-item>
  31. <up-form-item label="手机号" prop="userTelephone">
  32. <up-input inputAlign="right" v-model="baseFormData.userTelephone" placeholder="请输入" border="none" fontSize="28rpx"></up-input>
  33. </up-form-item>
  34. <up-form-item label="性别" prop="sex">
  35. <view class="flex-rowr" @click="openSexSelectPopup">
  36. <text>{{ baseFormData.sex || '请选择' }}</text>
  37. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  38. </view>
  39. </up-form-item>
  40. </up-form>
  41. </view>
  42. </view>
  43. <view class="info">
  44. <view class="title mt24 flex-rowl">
  45. 展示信息
  46. <text class="size-22 color-ffb fw700">(重要)</text>
  47. </view>
  48. <view class="form">
  49. <up-form label-position="left" :model="formData" :rules="rules" ref="dFormRef" labelWidth="200rpx">
  50. <up-form-item label="个人简介" prop="introduction">
  51. <up-input v-model="formData.introduction"
  52. placeholder="请输入个人简介" border="none"
  53. inputAlign="right"
  54. fontSize="28rpx">
  55. </up-input>
  56. </up-form-item>
  57. <up-form-item label="养宠经验" prop="experience">
  58. <up-input inputAlign="right" v-model="formData.experience" placeholder="请输入养宠经验"
  59. border="none" fontSize="28rpx">
  60. <template #suffix>
  61. </template>
  62. </up-input>
  63. </up-form-item>
  64. <up-form-item label="服务记录" prop="serviceRecord">
  65. <view class="flex-rowr" @click="jumpToServeRecord">
  66. <text>{{ `${serviceCount}` }}</text>
  67. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  68. </view>
  69. </up-form-item>
  70. </up-form>
  71. </view>
  72. </view>
  73. <view class="info">
  74. <view class="title mt24 flex-rowl">
  75. 服务资料
  76. </view>
  77. <view class="form">
  78. <up-form label-position="left" :model="serveFormData" ref="serveFormRef" labelWidth="200rpx">
  79. <up-form-item label="服务宠物类型" prop="type">
  80. <view class="flex-rowr" @click="openTypeSelectPopup">
  81. <text>{{ typeDesc }}</text>
  82. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  83. </view>
  84. </up-form-item>
  85. <up-form-item label="增值服务" prop="serve">
  86. <view class="flex-rowr" @click="openServeSelectPopup">
  87. <text>{{ serveDesc }}</text>
  88. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  89. </view>
  90. </up-form-item>
  91. </up-form>
  92. </view>
  93. </view>
  94. <view class="size-24 color-ffb flex-rowc mt32 pb28">
  95. 伴宠师查看服务酬劳服务时长等规则
  96. </view>
  97. <popupTypeSelect ref="popupTypeSelectRef" v-model="form.type" @confirm="fetchUpdate" ></popupTypeSelect>
  98. <popupServeSelect ref="popupServeSelectRef" v-model="serveFormData.serve" @confirm="fetchUpdate" ></popupServeSelect>
  99. <popupSexSelect ref="popupSexSelectRef" v-model="baseFormData.sex" @confirm="fetchUpdate" ></popupSexSelect>
  100. <view class="uni-btn-color"
  101. @click="submit">
  102. 保存
  103. </view>
  104. </view>
  105. </template>
  106. <script setup>
  107. import { ref, reactive, computed, onMounted, nextTick } from "vue";
  108. import { useStore } from 'vuex'
  109. import { onShow } from '@dcloudio/uni-app'
  110. import { ossUpload } from '@/utils/oss-upload/oss/index.js'
  111. import popupTypeSelect from "./popupTypeSelect.vue";
  112. import popupServeSelect from "./popupServeSelect.vue";
  113. import popupSexSelect from "./popupSexSelect.vue";
  114. import { serviceLogList } from '@/api/serviceLog'
  115. import {
  116. binBaseInfo,
  117. } from "@/api/home.js"
  118. import { getUserOne, udpateUser } from '@/api/userTeacher'
  119. import { updateUserInfo } from '@/api/user/user'
  120. const store = useStore()
  121. const configList = computed(() => {
  122. return store.getters.configList
  123. })
  124. const userInfo = computed(() => {
  125. return store.getters.userInfo
  126. })
  127. const serviceCount = ref(0)
  128. const baseFormData = reactive({
  129. userName: '',
  130. userTelephone: '',
  131. sex: ''
  132. })
  133. const baseRules = {
  134. userName: {
  135. type: 'string',
  136. required: true,
  137. message: '请输入昵称',
  138. trigger: ['blur', 'change']
  139. },
  140. userTelephone: {
  141. type: 'string',
  142. required: true,
  143. message: '请输入手机号',
  144. trigger: ['blur', 'change']
  145. },
  146. sex: {
  147. type: 'string',
  148. required: true,
  149. message: '请选择性别',
  150. trigger: ['blur', 'change']
  151. }
  152. }
  153. const baseFormRef = ref(null)
  154. const formData = reactive({
  155. introduction: '',
  156. experience: '',
  157. serviceRecord: ''
  158. })
  159. const rules = {
  160. introduction: {
  161. type: 'string',
  162. required: true,
  163. message: '请输入个人简介',
  164. trigger: ['blur', 'change']
  165. },
  166. experience: {
  167. type: 'string',
  168. required: true,
  169. message: '请输入养宠经验',
  170. trigger: ['blur', 'change']
  171. }
  172. }
  173. const dFormRef = ref(null)
  174. const form = reactive({
  175. headImage: null,
  176. type: [],
  177. id : 0,
  178. })
  179. const serveFormData = reactive({
  180. serve: []
  181. })
  182. const serveFormRef = ref(null)
  183. const fetchUserInfo = async () => {
  184. try {
  185. const data = await getUserOne(userInfo.value.userId)
  186. if (data) {
  187. // 设置基本资料
  188. baseFormData.userName = userInfo.value.userName || ''
  189. baseFormData.userTelephone = data.phone || userInfo.value.userTelephone || ''
  190. baseFormData.sex = data.sex === 0 ? '男' : '女'
  191. // 设置展示信息
  192. formData.introduction = data.introduction || ''
  193. formData.experience = data.experience || ''
  194. form.headImage = userInfo.value.userImage || ''
  195. form.id = data.id || 0
  196. // 设置服务资料
  197. if (data.petType) {
  198. form.type = [data.petType]
  199. }
  200. // 设置增值服务
  201. if (data.license) {
  202. serveFormData.serve = data.license.split(';').map(item => parseInt(item))
  203. }
  204. }
  205. } catch (err) {
  206. console.log('--err', err)
  207. }
  208. }
  209. const fetchUpdate = () => {
  210. // 表单数据已更新,无需额外处理
  211. }
  212. const onChooseAvatar = (res) => {
  213. ossUpload(res.target.avatarUrl)
  214. .then(url => {
  215. form.headImage = url
  216. fetchUpdate()
  217. })
  218. }
  219. const jumpToServeRecord = () => {
  220. uni.navigateTo({
  221. url: "/otherPages/authentication/serve/record"
  222. })
  223. }
  224. const popupTypeSelectRef = ref()
  225. const openTypeSelectPopup = () => {
  226. popupTypeSelectRef.value.open()
  227. }
  228. const popupSexSelectRef = ref()
  229. const openSexSelectPopup = () => {
  230. popupSexSelectRef.value.open()
  231. }
  232. const petTypeOptions = computed(() => {
  233. return store.getters.petTypeOptions
  234. })
  235. const typeDesc = computed(() => {
  236. const typeIds = form.type
  237. if (!typeIds.length) {
  238. return '请选择'
  239. }
  240. let descArr = typeIds.map(typeId => {
  241. let t = petTypeOptions.value.find(item => item.id === typeId)
  242. return t && t.title
  243. })
  244. return descArr.join('、')
  245. })
  246. const popupServeSelectRef = ref()
  247. const increaseServiceOptions = computed(() => {
  248. return store.getters.increaseServiceOptions
  249. })
  250. const openServeSelectPopup = () => {
  251. popupServeSelectRef.value.open()
  252. }
  253. const serveDesc = computed(() => {
  254. const serveIds = serveFormData.serve
  255. if (!serveIds.length) {
  256. return '请选择'
  257. }
  258. let descArr = serveIds.map(serveId => {
  259. return increaseServiceOptions.value.find(option => option.id == serveId)?.title
  260. })
  261. return descArr.join('、')
  262. })
  263. function getCountSerivce(){
  264. serviceLogList({ userId: userInfo.value.userId })
  265. .then(res => {
  266. serviceCount.value = res.length
  267. })
  268. }
  269. const getBaseInfo = () => {
  270. binBaseInfo(userInfo.value.userId).then(res => {
  271. baseInfo.value = res.data
  272. uni.setStorageSync(JSON.stringify(res.data))
  273. })
  274. }
  275. function submit(){
  276. // 先验证基本资料表单
  277. baseFormRef.value.validate().then(() => {
  278. // 再验证展示信息表单
  279. return dFormRef.value.validate()
  280. }).then(res => {
  281. const submitData = {
  282. id : form.id,
  283. phone: baseFormData.userTelephone,
  284. sex: baseFormData.sex === '男' ? 0 : 1,
  285. introduction: formData.introduction,
  286. experience: formData.experience,
  287. petType: form.type.length > 0 ? form.type[0] : null,
  288. license: serveFormData.serve.join(';'),
  289. }
  290. if (form.headImage) {
  291. updateUserInfo({
  292. userImage : form.headImage,
  293. userName: baseFormData.userName,
  294. id : userInfo.value.id,
  295. userId : userInfo.value.userId,
  296. }).then(() => {
  297. store.dispatch('getUserInfo')
  298. })
  299. }
  300. udpateUser(submitData).then(() => {
  301. uni.showToast({
  302. title: '保存成功',
  303. icon: 'success'
  304. })
  305. setTimeout(uni.navigateBack, 1000, -1)
  306. }).catch(err => {
  307. console.error(err)
  308. uni.showToast({
  309. title: '保存失败',
  310. icon: 'error'
  311. })
  312. })
  313. }).catch(err => {
  314. console.log('表单验证失败', err)
  315. })
  316. }
  317. onShow(() => {
  318. getCountSerivce()
  319. fetchUserInfo()
  320. store.dispatch('fetchPetTypeOptions')
  321. store.dispatch('fetchIncreaseServiceOptions')
  322. })
  323. onMounted(()=> {
  324. })
  325. </script>
  326. <style lang="scss" scoped>
  327. .page {
  328. padding-top: 16rpx;
  329. padding-bottom: 150rpx;
  330. .tip {
  331. background-color: rgba($color: #FFBF60, $alpha: 0.16);
  332. padding: 13rpx 22rpx;
  333. margin: 0 28rpx 37rpx 28rpx;
  334. .icon {
  335. width: 36rpx;
  336. height: 36rpx;
  337. margin-right: 15rpx;
  338. }
  339. }
  340. }
  341. .info {
  342. & + & {
  343. margin-top: 50rpx;
  344. }
  345. }
  346. .head {
  347. width: 165rpx;
  348. height: 165rpx;
  349. margin-top: 28rpx;
  350. }
  351. .btn-avatar {
  352. border: none;
  353. padding: 0;
  354. .head{
  355. width: 140rpx;
  356. height: 140rpx;
  357. border-radius: 50%;
  358. }
  359. }
  360. .title {
  361. font-size: 30rpx;
  362. font-weight: 700;
  363. display: flex;
  364. align-items: center;
  365. padding: 0 40rpx;
  366. &:before {
  367. display: inline-block;
  368. content: "";
  369. width: 10rpx;
  370. border-radius: 5rpx;
  371. height: 33rpx;
  372. background-color: #FFBF60;
  373. margin-right: 7rpx;
  374. }
  375. }
  376. .form {
  377. padding: 0 38rpx;
  378. :deep(.form-item){
  379. padding-left: 24rpx;
  380. padding-right: 30rpx;
  381. box-sizing: border-box;
  382. }
  383. .form-item {
  384. min-height: 90rpx;
  385. padding-top: 10rpx;
  386. width: 100%;
  387. border-bottom: 1rpx solid #f5f5f5;
  388. }
  389. .flex-rowr {
  390. display: flex;
  391. justify-content: flex-end;
  392. align-items: center;
  393. }
  394. .ml10 {
  395. margin-left: 10rpx;
  396. }
  397. }
  398. .uni-btn-color{
  399. border-radius: 40rpx;
  400. padding: 20rpx;
  401. margin: 40rpx;
  402. background: #FFBF60;
  403. color: #fff;
  404. text-align: center;
  405. font-size: 28rpx;
  406. }
  407. </style>