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

405 lines
9.0 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="baseInfo.info.userImage" mode="widthFix"></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. <view class="form-item flex-rowb">
  28. <view class="size-28">昵称</view>
  29. <view class="flex-rowr">
  30. <input type="text" placeholder="请输入" v-model="form.nickname" class="input-right" />
  31. </view>
  32. </view>
  33. <view class="form-item flex-rowb">
  34. <view class="size-28">手机号</view>
  35. <view class="flex-rowr">
  36. <text>{{baseInfo.info.userTelephone || ''}}</text>
  37. </view>
  38. </view>
  39. <view class="form-item flex-rowb">
  40. <view class="size-28">性别</view>
  41. <view class="flex-rowr" @click="openGenderSelect">
  42. <text>{{form.gender || '请选择'}}</text>
  43. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="info">
  49. <view class="title mt24 flex-rowl">
  50. 展示信息
  51. <text class="size-22 color-ffb fw700">(重要)</text>
  52. </view>
  53. <view class="form">
  54. <view class="form-item flex-rowb">
  55. <view class="size-28">个人简介</view>
  56. <view class="flex-rowr">
  57. <textarea v-model="form.introduction" placeholder="请输入" class="textarea-full" maxlength="200"></textarea>
  58. </view>
  59. </view>
  60. <view class="form-item flex-rowb">
  61. <view class="size-28">养宠经验</view>
  62. <view class="flex-rowr">
  63. <input type="number" v-model="form.petExperience" placeholder="请输入您的养宠年限" class="input-right" />
  64. <text class="ml10"></text>
  65. </view>
  66. </view>
  67. <view class="form-item flex-rowb">
  68. <view class="size-28">服务记录</view>
  69. <view class="flex-rowr" @click="jumpToServeRecord">
  70. <text>{{ `${serviceCount}` }}</text>
  71. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="info">
  77. <view class="title mt24 flex-rowl">
  78. 服务资料
  79. </view>
  80. <view class="form">
  81. <view class="form-item flex-rowb">
  82. <view class="size-28">服务宠物类型</view>
  83. <view class="flex-rowr" @click="openTypeSelectPopup">
  84. <text>{{ typeDesc }}</text>
  85. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  86. </view>
  87. </view>
  88. <view class="form-item flex-rowb">
  89. <view class="size-28">基础服务</view>
  90. <view class="flex-rowr">
  91. <text>宠物喂养 上门遛狗</text>
  92. </view>
  93. </view>
  94. <view class="form-item flex-rowb">
  95. <view class="size-28">增值服务</view>
  96. <view class="flex-rowr" @click="openServeSelectPopup">
  97. <text>{{ serveDesc }}</text>
  98. <up-icon name="arrow-right" color="#999999" size="32rpx"></up-icon>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="size-24 color-ffb flex-rowc mt32 pb28">
  104. 伴宠师查看服务酬劳服务时长等规则
  105. </view>
  106. <popupTypeSelect ref="popupTypeSelectRef" v-model="form.type" @confirm="fetchUpdate" ></popupTypeSelect>
  107. <popupServeSelect ref="popupServeSelectRef" v-model="form.serve" @confirm="fetchUpdate" ></popupServeSelect>
  108. <view class="uni-btn-color"
  109. @click="submit">
  110. 保存
  111. </view>
  112. </view>
  113. </template>
  114. <script setup>
  115. import { ref, reactive, computed, onMounted, nextTick } from "vue";
  116. import { useStore } from 'vuex'
  117. import { onShow } from '@dcloudio/uni-app'
  118. import { ossUpload } from '@/utils/oss-upload/oss/index.js'
  119. import popupTypeSelect from "./popupTypeSelect.vue";
  120. import popupServeSelect from "./popupServeSelect.vue";
  121. import { serviceLogList } from '@/api/serviceLog'
  122. import {
  123. binBaseInfo,
  124. } from "@/api/home.js"
  125. const store = useStore()
  126. const configList = computed(() => {
  127. return store.getters.configList
  128. })
  129. const userInfo = computed(() => {
  130. return store.getters.userInfo
  131. })
  132. const baseInfo = ref(JSON.parse(uni.getStorageSync("baseInfo")))
  133. const serviceCount = ref(0)
  134. const form = reactive({
  135. headImage: null,
  136. nickname: '',
  137. gender: '',
  138. introduction: '',
  139. petExperience: '',
  140. type: [],
  141. serve: [],
  142. })
  143. const onChooseAvatar = (res) => {
  144. ossUpload(res.target.avatarUrl)
  145. .then(url => {
  146. form.headImage = url
  147. fetchUpdate()
  148. })
  149. }
  150. const baseInfoRef = ref(null)
  151. const displayInfoRef = ref(null)
  152. const serveInfoRef = ref(null)
  153. const jumpToServeRecord = () => {
  154. uni.navigateTo({
  155. url: "/otherPages/authentication/serve/record"
  156. })
  157. }
  158. const popupTypeSelectRef = ref()
  159. const openTypeSelectPopup = () => {
  160. popupTypeSelectRef.value.open()
  161. }
  162. const petTypeOptions = computed(() => {
  163. return store.getters.petTypeOptions
  164. })
  165. const typeDesc = computed(() => {
  166. const typeIds = form.type
  167. if (!typeIds.length) {
  168. return '请选择'
  169. }
  170. let descArr = typeIds.map(typeId => {
  171. return petTypeOptions.value.find(item => item.id === typeId).title
  172. })
  173. return descArr.join('、')
  174. })
  175. const popupServeSelectRef = ref()
  176. const increaseServiceOptions = computed(() => {
  177. return store.getters.increaseServiceOptions
  178. })
  179. const openServeSelectPopup = () => {
  180. popupServeSelectRef.value.open()
  181. }
  182. const serveDesc = computed(() => {
  183. const serveIds = form.serve
  184. if (!serveIds.length) {
  185. return '请选择'
  186. }
  187. let descArr = serveIds.map(serveId => {
  188. return increaseServiceOptions.value.find(option => option.id === serveId)?.title
  189. })
  190. return descArr.join('、')
  191. })
  192. function getCountSerivce(){
  193. serviceLogList({ userId: userInfo.value.userId })
  194. .then(res => {
  195. serviceCount.value = res.length
  196. })
  197. }
  198. const getBaseInfo = () => {
  199. binBaseInfo(baseInfo.value.userId).then(res => {
  200. baseInfo.value = res.data
  201. uni.setStorageSync(JSON.stringify(res.data))
  202. // baseInfoRef.value.setData(res.data.info)
  203. })
  204. }
  205. const genderOptions = [
  206. { text: '男', value: '男' },
  207. { text: '女', value: '女' }
  208. ]
  209. const openGenderSelect = () => {
  210. uni.showActionSheet({
  211. itemList: genderOptions.map(item => item.text),
  212. success: function (res) {
  213. form.gender = genderOptions[res.tapIndex].value
  214. fetchUpdate()
  215. }
  216. })
  217. }
  218. const fetchUpdate = () => {
  219. // 这里可以添加更新数据的逻辑
  220. console.log('更新数据', form)
  221. }
  222. function submit(){
  223. // 表单验证
  224. if (!form.nickname) {
  225. uni.showToast({
  226. title: '请输入昵称',
  227. icon: 'none'
  228. })
  229. return
  230. }
  231. // 提交表单数据
  232. console.log('提交表单数据', form)
  233. uni.showToast({
  234. title: '保存成功',
  235. icon: 'success'
  236. })
  237. }
  238. onShow(() => {
  239. getCountSerivce()
  240. getBaseInfo()
  241. store.dispatch('fetchPetTypeOptions')
  242. store.dispatch('fetchIncreaseServiceOptions')
  243. })
  244. onMounted(()=> {
  245. // todo: fetch data and init data
  246. // 初始化表单数据
  247. if (baseInfo.value && baseInfo.value.info) {
  248. form.nickname = baseInfo.value.info.userName || ''
  249. form.gender = baseInfo.value.info.gender || ''
  250. }
  251. })
  252. </script>
  253. <style lang="scss" scoped>
  254. .form{
  255. .form-item {
  256. min-height: 90rpx;
  257. padding-top: 10rpx;
  258. width: 100%;
  259. border-bottom: 1rpx solid #f5f5f5;
  260. }
  261. .flex-rowr {
  262. display: flex;
  263. justify-content: flex-end;
  264. align-items: center;
  265. }
  266. .flex-rowb {
  267. display: flex;
  268. justify-content: space-between;
  269. align-items: center;
  270. padding: 20rpx 0;
  271. }
  272. .ml10 {
  273. margin-left: 10rpx;
  274. }
  275. .input-right {
  276. text-align: right;
  277. }
  278. .textarea-full {
  279. width: 100%;
  280. min-height: 120rpx;
  281. text-align: right;
  282. }
  283. }
  284. .page {
  285. padding-top: 16rpx;
  286. padding-bottom: 150rpx;
  287. .tip {
  288. background-color: rgba($color: #FFBF60, $alpha: 0.16);
  289. padding: 13rpx 22rpx;
  290. margin: 0 28rpx 37rpx 28rpx;
  291. .icon {
  292. width: 36rpx;
  293. height: 36rpx;
  294. margin-right: 15rpx;
  295. }
  296. }
  297. }
  298. .info {
  299. & + & {
  300. margin-top: 50rpx;
  301. }
  302. }
  303. .head {
  304. width: 165rpx;
  305. height: auto;
  306. margin-top: 28rpx;
  307. }
  308. .btn-avatar {
  309. border: none;
  310. padding: 0;
  311. }
  312. .title {
  313. font-size: 30rpx;
  314. font-weight: 700;
  315. display: flex;
  316. align-items: center;
  317. padding: 0 40rpx;
  318. &:before {
  319. display: inline-block;
  320. content: "";
  321. width: 10rpx;
  322. border-radius: 5rpx;
  323. height: 33rpx;
  324. background-color: #FFBF60;
  325. margin-right: 7rpx;
  326. }
  327. }
  328. .form {
  329. padding: 0 22rpx;
  330. :deep(.form-item){
  331. padding-left: 24rpx;
  332. padding-right: 30rpx;
  333. box-sizing: border-box;
  334. }
  335. }
  336. .uni-btn-color{
  337. border-radius: 40rpx;
  338. padding: 20rpx;
  339. margin: 40rpx;
  340. background: #FFBF60;
  341. color: #fff;
  342. text-align: center;
  343. font-size: 28rpx;
  344. }
  345. </style>