familyMemberVindicate.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="common_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header :title="title" bgColor="#FFFFFF"></cus-header>
  4. <view class="form">
  5. <view class="avatar">
  6. <view class="title"><span>*</span>头像</view>
  7. <view class="adfac" style="margin: 24rpx 0 52rpx;">
  8. <view class="imgbox">
  9. <image class="imgbox-avatar" :src="memberInfo?.avatarPath||defaultAvatar" @click="changeAvatar"></image>
  10. </view>
  11. <image class="add-avatar" src="https://oss.familydaf.cn/sxsnfile/20251219/0b4d0f26464945dbae17491f1b529229.png" @click="changeAvatar"></image>
  12. </view>
  13. </view>
  14. <view class="item adfacjb">
  15. <view class="left">个人公益名称</view>
  16. <view class="right">
  17. <input min="3" class="setinp"v-model="memberInfo.welfareName" placeholder-style="color: #A1A4A9;font-size: 28rpx;" placeholder="请输入最少三个字"></input>
  18. </view>
  19. </view>
  20. <view class="item adfacjb">
  21. <view class="left">个人公益口号</view>
  22. <view class="right">
  23. <input class="setinp"v-model="memberInfo.welfareSlogan" placeholder-style="color: #A1A4A9;font-size: 28rpx;" placeholder="请输入个人公益口号"></input>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="form">
  28. <view class="title">成员信息</view>
  29. <view class="pre adfac" style="margin-top: 40rpx;">
  30. <view class="pre-title"><span>*</span>人员类型</view>
  31. <view class="pre-content adfac">
  32. <view class="pre-content-box adfac" @click="changeMember(1,'personnelType')">
  33. <image v-if="memberInfo.personnelType==1" src="https://oss.familydaf.cn/sxsnfile/20251218/ef2d43944c7e4cea8c6ebe0b4179f0fc.png"></image>
  34. <image v-else src="https://oss.familydaf.cn/sxsnfile/20251218/a27c9b23939d4d5085ff790ed4bd2d6a.png"></image>
  35. <text>成人</text>
  36. </view>
  37. <view class="pre-content-box adfac" @click="changeMember(2,'personnelType')">
  38. <image v-if="memberInfo.personnelType==2" src="https://oss.familydaf.cn/sxsnfile/20251218/ef2d43944c7e4cea8c6ebe0b4179f0fc.png"></image>
  39. <image v-else src="https://oss.familydaf.cn/sxsnfile/20251218/a27c9b23939d4d5085ff790ed4bd2d6a.png"></image>
  40. <text>学生</text>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="pre adfac">
  45. <view class="pre-title"><span>*</span>姓名</view>
  46. <view class="pre-content">
  47. <input v-model="memberInfo.name" style="font-size: 30rpx;color: #252525;text-align: right;" placeholder-style="color: #A1A4A9;font-size: 28rpx;" placeholder="请输入姓名"></input>
  48. </view>
  49. </view>
  50. <view class="pre adfac">
  51. <view class="pre-title"><span>*</span>身份证</view>
  52. <view class="pre-content">
  53. <input v-model="memberInfo.idCard" style="font-size: 30rpx;color: #252525;text-align: right;" placeholder-style="color: #A1A4A9;font-size: 28rpx;" placeholder="请输入身份证"></input>
  54. </view>
  55. </view>
  56. <view class="pre adfac">
  57. <view class="pre-title"><span style="color: #FFFFFF;">*</span>义工号</view>
  58. <view class="pre-content">
  59. <input v-model="memberInfo.volunteerNo" style="font-size: 30rpx;color: #252525;text-align: right;" placeholder-style="color: #A1A4A9;font-size: 28rpx;" placeholder="请输入义工号"></input>
  60. </view>
  61. </view>
  62. <view class="pre adfac">
  63. <view class="pre-title"><span>*</span>性别</view>
  64. <view class="pre-content adfac">
  65. <view class="pre-content-box adfac" @click="changeMember(0,'gender')">
  66. <image v-if="memberInfo.gender==0" src="https://oss.familydaf.cn/sxsnfile/20251218/ef2d43944c7e4cea8c6ebe0b4179f0fc.png"></image>
  67. <image v-else src="https://oss.familydaf.cn/sxsnfile/20251218/a27c9b23939d4d5085ff790ed4bd2d6a.png"></image>
  68. <text>男</text>
  69. </view>
  70. <view class="pre-content-box adfac" @click="changeMember(1,'gender')" style="margin-left: 114rpx;">
  71. <image v-if="memberInfo.gender==1" src="https://oss.familydaf.cn/sxsnfile/20251218/ef2d43944c7e4cea8c6ebe0b4179f0fc.png"></image>
  72. <image v-else src="https://oss.familydaf.cn/sxsnfile/20251218/a27c9b23939d4d5085ff790ed4bd2d6a.png"></image>
  73. <text>女</text>
  74. </view>
  75. </view>
  76. </view>
  77. <view class="pre adfac" v-if="memberInfo.personnelType==2">
  78. <view class="pre-title"><span>*</span>就读学校</view>
  79. <view class="pre-content">
  80. <input v-model="memberInfo.currentSchool" style="font-size: 30rpx;color: #252525;text-align: right;" placeholder-style="color: #A1A4A9;font-size: 28rpx;" placeholder="请输入就读学校"></input>
  81. </view>
  82. </view>
  83. <view class="pre adfac">
  84. <view class="pre-title">会员渠道</view>
  85. <view class="pre-content">
  86. <picker v-if="channelList.length > 0" :range="channelList" range-key="channelName" :value="selectedChannelIndex" @change="onChannelChange">
  87. <view style="font-size: 30rpx;color: #252525;text-align: right;">
  88. {{ memberChannelNames || '请选择渠道' }}
  89. </view>
  90. </picker>
  91. <view v-else style="font-size: 30rpx;color: #A1A4A9;text-align: right;">暂无可用渠道</view>
  92. </view>
  93. </view>
  94. </view>
  95. <view class="btn" @click="handleSave">保存</view>
  96. <qf-image-cropper :width="500" :height="500" :radius="30" @crop="handleCrop" ref="qicRef" v-if="qicShow"></qf-image-cropper>
  97. </view>
  98. </template>
  99. <script setup name="">
  100. import { BaseApi2 } from '../common/api/baseApi';
  101. import CusHeader from '@/components/CusHeader/index.vue'
  102. import { onLoad } from '@dcloudio/uni-app'
  103. import { ref, getCurrentInstance, nextTick } from 'vue'
  104. const { proxy } = getCurrentInstance()
  105. const title = ref('添加家庭成员')
  106. const defaultAvatar = ref('https://oss.familydaf.cn/sxsnfile/20251218/3821654e080945998d464f3c3aa64122.png')
  107. const memberInfo = ref({
  108. userId:'',
  109. personnelType:1,
  110. name:'',
  111. idCard:'',
  112. volunteerNo:'',
  113. gender:0,
  114. currentSchool:''
  115. })
  116. const qicShow = ref(false)
  117. // 渠道相关
  118. const channelList = ref([]) // 会员渠道列表(可选项)
  119. const memberChannelNames = ref('') // 成员已加入的渠道名称(逗号分隔)
  120. const selectedChannelId = ref('') // 已选渠道 ID(字符串)
  121. const selectedChannelIndex = ref(-1) // picker 当前选中下标,-1 表示未选
  122. const hasSelectedChannel = ref(false) // 用户是否主动选择过渠道
  123. const turnType = ref('')
  124. const loadChannelList = () => {
  125. return new Promise((resolve) => {
  126. proxy.$api.get('/channel/list', {}).then(({ data: res }) => {
  127. if (res.code !== 0) {
  128. resolve()
  129. return
  130. }
  131. channelList.value = res.data || []
  132. // 若 loadMemberChannel 已先完成并设置了 selectedChannelId,补充同步 index
  133. if (selectedChannelId.value) {
  134. const idx = channelList.value.findIndex(c => String(c.id) === selectedChannelId.value)
  135. if (idx >= 0) selectedChannelIndex.value = idx
  136. }
  137. resolve()
  138. })
  139. })
  140. }
  141. const loadMemberChannel = (memberId) => {
  142. proxy.$api.get('/member/channelList', { memberId }).then(({ data: res }) => {
  143. if (res.code !== 0) return
  144. const list = res.data || []
  145. if (list.length > 0) {
  146. // 显示所有已加入的渠道名称
  147. memberChannelNames.value = list.map(c => c.channelName).join('、')
  148. // 默认选中第一个渠道
  149. selectedChannelId.value = String(list[0].id)
  150. const idx = channelList.value.findIndex(c => String(c.id) === selectedChannelId.value)
  151. if (idx >= 0) selectedChannelIndex.value = idx
  152. }
  153. })
  154. }
  155. const changeMember = (value,key) => {
  156. memberInfo.value[key] = value;
  157. }
  158. const handleSave = async () => {
  159. if(!memberInfo.value.avatarPath) return proxy.$showToast('请上传头像')
  160. if(memberInfo.value.welfareName&&memberInfo.value.welfareName.length<3) return proxy.$showToast('个人公益名称至少三个字')
  161. if(!memberInfo.value.name) return proxy.$showToast('请输入姓名')
  162. if(!proxy.$reg.idCard(memberInfo.value.idCard)) return proxy.$showToast('请输入正确的身份证号')
  163. if(!memberInfo.value.currentSchool&&memberInfo.value.personnelType==2) return proxy.$showToast('请输入就读学校')
  164. memberInfo.value.gender = memberInfo.value.gender??1;
  165. const checkMsgs = ['welfareName','welfareSlogan','name'].map(k=>checkMsg(k));
  166. const tipRes = (await Promise.all(checkMsgs)).filter(item=>item!=='ok');
  167. if(tipRes&&tipRes.length) return proxy.$showModal(tipRes.join('、'))
  168. if(!memberInfo.value.userId) memberInfo.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  169. proxy.$api[memberInfo.value.id?'put':'post']('/core/family/member',memberInfo.value).then(({data:res})=>{
  170. if(res.code!==0) return proxy.$showToast(res.msg)
  171. const memberId = memberInfo.value.id || res.data?.id
  172. // 编辑时(memberInfo.value.id 存在)或用户主动选择了渠道,才调用 setMemberChannel
  173. if (memberId && (hasSelectedChannel.value || memberInfo.value.id)) {
  174. setMemberChannel(memberId) // 异步,不 await,不阻断跳转
  175. }
  176. proxy.$showToast(memberInfo.value.id?'编辑成功':'添加成功')
  177. setTimeout(()=>{
  178. if(turnType.value==='my'){
  179. uni.reLaunch({
  180. url:'/pages/my'
  181. })
  182. return
  183. }
  184. uni.redirectTo({
  185. url:'/pagesMy/familyMember'
  186. })
  187. },1000)
  188. })
  189. }
  190. const onChannelChange = (e) => {
  191. const idx = e.detail.value
  192. selectedChannelIndex.value = idx
  193. selectedChannelId.value = String(channelList.value[idx].id)
  194. memberChannelNames.value = channelList.value[idx].channelName
  195. hasSelectedChannel.value = true
  196. }
  197. const setMemberChannel = (memberId) => {
  198. proxy.$api.post(`/member/setChannels?memberId=${memberId}&channelIds=${selectedChannelId.value}`, {}).then(({ data: res }) => {
  199. if (res.code !== 0) proxy.$showToast(res.msg)
  200. }).catch(() => {
  201. proxy.$showToast('渠道设置失败,请稍后重试')
  202. })
  203. }
  204. const checkMsg = async msg => {
  205. const msgAlert = {
  206. welfareName:'家庭公益名称',
  207. welfareSlogan:'家庭公益口号',
  208. name:'姓名'
  209. }
  210. return new Promise((resolve,reject)=>{
  211. proxy.$api.detectionContent(memberInfo.value[msg]).then(res=>{
  212. resolve(res.code!==0?(`${msgAlert[msg]}:`+res.msg):'ok')
  213. })
  214. })
  215. }
  216. const getMemberInfo = (id) => {
  217. proxy.$api.get(`/core/family/member/${id}`).then(({data:res})=>{
  218. if(res.code!==0) return proxy.$showToast(res.msg)
  219. if(res.data){
  220. memberInfo.value = {...memberInfo.value,...res.data}
  221. }
  222. })
  223. }
  224. const changeAvatar = () => {
  225. uni.showActionSheet({
  226. itemList: ['从手机相册选择'],
  227. success: (res) => {
  228. if (res.tapIndex === 0) { // 从手机相册选择
  229. chooseLocalImage();
  230. }
  231. }
  232. });
  233. }
  234. // 从本地选择图片并显示
  235. const chooseLocalImage = () => {
  236. uni.chooseImage({
  237. count: 1, // 只能选择一张
  238. sizeType: ['compressed'], // 压缩图片
  239. sourceType: ['album', 'camera'], // 可以从相册或相机选择
  240. success: (res) => {
  241. const tempFilePaths = res.tempFilePaths;
  242. if (tempFilePaths && tempFilePaths.length > 0) {
  243. proxy.$api.detectionContent(tempFilePaths[0],2).then(res=>{
  244. if(res.code!==0) return proxy.$showToast(res.msg)
  245. qicShow.value = true;
  246. nextTick(()=>{
  247. proxy.$refs.qicRef.initImage(tempFilePaths[0],true)
  248. })
  249. })
  250. }
  251. },
  252. fail: (err) => {
  253. console.error('选择图片失败', err);
  254. }
  255. });
  256. }
  257. const handleCrop = async (e) => {
  258. const result = await uploadFilePromise(e.tempFilePath);
  259. memberInfo.value.avatarPath = result||'';
  260. qicShow.value = false;
  261. }
  262. const uploadFilePromise = (url) => {
  263. return new Promise((resolve, reject) => {
  264. let a = uni.uploadFile({
  265. url: BaseApi2+'/sys/oss/upload',
  266. filePath: url,
  267. name: 'file',
  268. success: (res) => {
  269. setTimeout(() => {
  270. let data = JSON.parse(res.data)
  271. if(data&&data.code===0){
  272. resolve(data.data);
  273. }else proxy.$showToast(data?.msg)
  274. }, 1000);
  275. },
  276. fail: err =>{
  277. resolve('');
  278. }
  279. });
  280. });
  281. };
  282. onLoad(async (options)=>{
  283. turnType.value = options.type;
  284. await loadChannelList()
  285. const id = options?.id;
  286. if(id){
  287. title.value = '编辑家庭成员';
  288. getMemberInfo(id)
  289. loadMemberChannel(id)
  290. }
  291. })
  292. </script>
  293. <style scoped lang="scss">
  294. .common_page{
  295. padding-bottom: 184rpx;
  296. .form{
  297. background: #FFFFFF;
  298. border-radius: 24rpx;
  299. margin-top: 20rpx;
  300. padding: 36rpx 24rpx 0;
  301. .avatar{
  302. .title{
  303. font-family: PingFang-SC, PingFang-SC;
  304. font-weight: bold;
  305. font-size: 30rpx;
  306. color: #252525;
  307. line-height: 42rpx;
  308. label{
  309. font-family: PingFangSC, PingFang SC;
  310. font-weight: 400;
  311. font-size: 30rpx;
  312. color: #F4657A;
  313. line-height: 42rpx;
  314. }
  315. }
  316. .imgbox{
  317. width: 122rpx;
  318. height: 122rpx;
  319. &-avatar{
  320. width: 100%;
  321. height: 100%;
  322. border-radius: 50%;
  323. }
  324. }
  325. .add-avatar{
  326. margin-left: 40rpx;
  327. width: 122rpx;
  328. height: 122rpx;
  329. border-radius: 50%;
  330. }
  331. border-bottom: 1rpx solid #E6E6E6;
  332. }
  333. .item{
  334. height: 90rpx;
  335. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  336. .left{
  337. width: 200rpx;
  338. font-family: PingFangSC, PingFang SC;
  339. font-weight: 400;
  340. font-size: 28rpx;
  341. color: #676775;
  342. line-height: 40rpx;
  343. }
  344. .right{
  345. width: calc(100% - 200rpx);
  346. }
  347. }
  348. .title{
  349. font-family: PingFang-SC, PingFang-SC;
  350. font-weight: bold;
  351. font-size: 36rpx;
  352. color: #151B29;
  353. line-height: 48rpx;
  354. }
  355. .pre{
  356. padding: 25rpx 0;
  357. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #F2F2F2;
  358. &-title{
  359. width: 209rpx;
  360. font-family: PingFangSC, PingFang SC;
  361. font-weight: 400;
  362. font-size: 28rpx;
  363. color: #676775;
  364. line-height: 40rpx;
  365. label{
  366. font-family: PingFangSC, PingFang SC;
  367. font-weight: 400;
  368. font-size: 30rpx;
  369. color: #F4657A;
  370. line-height: 42rpx;
  371. margin-right: 4rpx;
  372. }
  373. }
  374. &-content{
  375. width: calc(100% - 209rpx);
  376. display: flex;
  377. align-items: center;
  378. justify-content: flex-end;
  379. &-box{
  380. margin-left: 80rpx;
  381. image{
  382. width: 28rpx;
  383. height: 28rpx;
  384. }
  385. text{
  386. font-family: PingFangSC, PingFang SC;
  387. font-weight: 400;
  388. font-size: 30rpx;
  389. color: #252525;
  390. line-height: 42rpx;
  391. margin-left: 16rpx;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. .btn{
  398. width: calc(100% - 80rpx);
  399. height: 90rpx;
  400. background: #B7F358;
  401. border-radius: 45rpx;
  402. font-family: PingFang-SC, PingFang-SC;
  403. font-weight: bold;
  404. font-size: 32rpx;
  405. color: #151B29;
  406. line-height: 90rpx;
  407. text-align: center;
  408. letter-spacing: 2rpx;
  409. position: fixed;
  410. left: 40rpx;
  411. bottom: 64rpx;
  412. }
  413. }
  414. </style>