familyMemberVindicate.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. {{ selectedChannelIndex >= 0 ? channelList[selectedChannelIndex].channelName : '请选择渠道' }}
  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 selectedChannelId = ref('') // 已选渠道 ID(字符串)
  120. const selectedChannelIndex = ref(-1) // picker 当前选中下标,-1 表示未选
  121. const hasSelectedChannel = ref(false) // 用户是否主动选择过渠道
  122. const turnType = ref('')
  123. const loadChannelList = () => {
  124. return new Promise((resolve) => {
  125. proxy.$api.get('/channel/list', {}).then(({ data: res }) => {
  126. if (res.code !== 0) {
  127. resolve()
  128. return
  129. }
  130. channelList.value = res.data || []
  131. // 若 loadMemberChannel 已先完成并设置了 selectedChannelId,补充同步 index
  132. if (selectedChannelId.value) {
  133. const idx = channelList.value.findIndex(c => String(c.id) === selectedChannelId.value)
  134. if (idx >= 0) selectedChannelIndex.value = idx
  135. }
  136. resolve()
  137. })
  138. })
  139. }
  140. const loadMemberChannel = (memberId) => {
  141. proxy.$api.get('/member/channelList', { memberId }).then(({ data: res }) => {
  142. if (res.code !== 0) return
  143. const list = res.data || []
  144. if (list.length > 0) {
  145. selectedChannelId.value = String(list[0].id)
  146. const idx = channelList.value.findIndex(c => String(c.id) === selectedChannelId.value)
  147. if (idx >= 0) selectedChannelIndex.value = idx
  148. }
  149. })
  150. }
  151. const changeMember = (value,key) => {
  152. memberInfo.value[key] = value;
  153. }
  154. const handleSave = async () => {
  155. if(!memberInfo.value.avatarPath) return proxy.$showToast('请上传头像')
  156. if(memberInfo.value.welfareName&&memberInfo.value.welfareName.length<3) return proxy.$showToast('个人公益名称至少三个字')
  157. if(!memberInfo.value.name) return proxy.$showToast('请输入姓名')
  158. if(!proxy.$reg.idCard(memberInfo.value.idCard)) return proxy.$showToast('请输入正确的身份证号')
  159. if(!memberInfo.value.currentSchool&&memberInfo.value.personnelType==2) return proxy.$showToast('请输入就读学校')
  160. memberInfo.value.gender = memberInfo.value.gender??1;
  161. const checkMsgs = ['welfareName','welfareSlogan','name'].map(k=>checkMsg(k));
  162. const tipRes = (await Promise.all(checkMsgs)).filter(item=>item!=='ok');
  163. if(tipRes&&tipRes.length) return proxy.$showModal(tipRes.join('、'))
  164. if(!memberInfo.value.userId) memberInfo.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  165. proxy.$api[memberInfo.value.id?'put':'post']('/core/family/member',memberInfo.value).then(({data:res})=>{
  166. if(res.code!==0) return proxy.$showToast(res.msg)
  167. const memberId = memberInfo.value.id || res.data?.id
  168. // 编辑时(memberInfo.value.id 存在)或用户主动选择了渠道,才调用 setMemberChannel
  169. if (memberId && (hasSelectedChannel.value || memberInfo.value.id)) {
  170. setMemberChannel(memberId) // 异步,不 await,不阻断跳转
  171. }
  172. proxy.$showToast(memberInfo.value.id?'编辑成功':'添加成功')
  173. setTimeout(()=>{
  174. if(turnType.value==='my'){
  175. uni.reLaunch({
  176. url:'/pages/my'
  177. })
  178. return
  179. }
  180. uni.redirectTo({
  181. url:'/pagesMy/familyMember'
  182. })
  183. },1000)
  184. })
  185. }
  186. const onChannelChange = (e) => {
  187. const idx = e.detail.value
  188. selectedChannelIndex.value = idx
  189. selectedChannelId.value = String(channelList.value[idx].id)
  190. hasSelectedChannel.value = true
  191. }
  192. const setMemberChannel = (memberId) => {
  193. proxy.$api.post(`/member/setChannels?memberId=${memberId}&channelIds=${selectedChannelId.value}`, {}).then(({ data: res }) => {
  194. if (res.code !== 0) proxy.$showToast(res.msg)
  195. }).catch(() => {
  196. proxy.$showToast('渠道设置失败,请稍后重试')
  197. })
  198. }
  199. const checkMsg = async msg => {
  200. const msgAlert = {
  201. welfareName:'家庭公益名称',
  202. welfareSlogan:'家庭公益口号',
  203. name:'姓名'
  204. }
  205. return new Promise((resolve,reject)=>{
  206. proxy.$api.detectionContent(memberInfo.value[msg]).then(res=>{
  207. resolve(res.code!==0?(`${msgAlert[msg]}:`+res.msg):'ok')
  208. })
  209. })
  210. }
  211. const getMemberInfo = (id) => {
  212. proxy.$api.get(`/core/family/member/${id}`).then(({data:res})=>{
  213. if(res.code!==0) return proxy.$showToast(res.msg)
  214. if(res.data){
  215. memberInfo.value = {...memberInfo.value,...res.data}
  216. }
  217. })
  218. }
  219. const changeAvatar = () => {
  220. uni.showActionSheet({
  221. itemList: ['从手机相册选择'],
  222. success: (res) => {
  223. if (res.tapIndex === 0) { // 从手机相册选择
  224. chooseLocalImage();
  225. }
  226. }
  227. });
  228. }
  229. // 从本地选择图片并显示
  230. const chooseLocalImage = () => {
  231. uni.chooseImage({
  232. count: 1, // 只能选择一张
  233. sizeType: ['compressed'], // 压缩图片
  234. sourceType: ['album', 'camera'], // 可以从相册或相机选择
  235. success: (res) => {
  236. const tempFilePaths = res.tempFilePaths;
  237. if (tempFilePaths && tempFilePaths.length > 0) {
  238. proxy.$api.detectionContent(tempFilePaths[0],2).then(res=>{
  239. if(res.code!==0) return proxy.$showToast(res.msg)
  240. qicShow.value = true;
  241. nextTick(()=>{
  242. proxy.$refs.qicRef.initImage(tempFilePaths[0],true)
  243. })
  244. })
  245. }
  246. },
  247. fail: (err) => {
  248. console.error('选择图片失败', err);
  249. }
  250. });
  251. }
  252. const handleCrop = async (e) => {
  253. const result = await uploadFilePromise(e.tempFilePath);
  254. memberInfo.value.avatarPath = result||'';
  255. qicShow.value = false;
  256. }
  257. const uploadFilePromise = (url) => {
  258. return new Promise((resolve, reject) => {
  259. let a = uni.uploadFile({
  260. url: BaseApi2+'/sys/oss/upload',
  261. filePath: url,
  262. name: 'file',
  263. success: (res) => {
  264. setTimeout(() => {
  265. let data = JSON.parse(res.data)
  266. if(data&&data.code===0){
  267. resolve(data.data);
  268. }else proxy.$showToast(data?.msg)
  269. }, 1000);
  270. },
  271. fail: err =>{
  272. resolve('');
  273. }
  274. });
  275. });
  276. };
  277. onLoad(async (options)=>{
  278. turnType.value = options.type;
  279. await loadChannelList()
  280. const id = options?.id;
  281. if(id){
  282. title.value = '编辑家庭成员';
  283. getMemberInfo(id)
  284. loadMemberChannel(id)
  285. }
  286. })
  287. </script>
  288. <style scoped lang="scss">
  289. .common_page{
  290. padding-bottom: 184rpx;
  291. .form{
  292. background: #FFFFFF;
  293. border-radius: 24rpx;
  294. margin-top: 20rpx;
  295. padding: 36rpx 24rpx 0;
  296. .avatar{
  297. .title{
  298. font-family: PingFang-SC, PingFang-SC;
  299. font-weight: bold;
  300. font-size: 30rpx;
  301. color: #252525;
  302. line-height: 42rpx;
  303. label{
  304. font-family: PingFangSC, PingFang SC;
  305. font-weight: 400;
  306. font-size: 30rpx;
  307. color: #F4657A;
  308. line-height: 42rpx;
  309. }
  310. }
  311. .imgbox{
  312. width: 122rpx;
  313. height: 122rpx;
  314. &-avatar{
  315. width: 100%;
  316. height: 100%;
  317. border-radius: 50%;
  318. }
  319. }
  320. .add-avatar{
  321. margin-left: 40rpx;
  322. width: 122rpx;
  323. height: 122rpx;
  324. border-radius: 50%;
  325. }
  326. border-bottom: 1rpx solid #E6E6E6;
  327. }
  328. .item{
  329. height: 90rpx;
  330. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  331. .left{
  332. width: 200rpx;
  333. font-family: PingFangSC, PingFang SC;
  334. font-weight: 400;
  335. font-size: 28rpx;
  336. color: #676775;
  337. line-height: 40rpx;
  338. }
  339. .right{
  340. width: calc(100% - 200rpx);
  341. }
  342. }
  343. .title{
  344. font-family: PingFang-SC, PingFang-SC;
  345. font-weight: bold;
  346. font-size: 36rpx;
  347. color: #151B29;
  348. line-height: 48rpx;
  349. }
  350. .pre{
  351. padding: 25rpx 0;
  352. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #F2F2F2;
  353. &-title{
  354. width: 209rpx;
  355. font-family: PingFangSC, PingFang SC;
  356. font-weight: 400;
  357. font-size: 28rpx;
  358. color: #676775;
  359. line-height: 40rpx;
  360. label{
  361. font-family: PingFangSC, PingFang SC;
  362. font-weight: 400;
  363. font-size: 30rpx;
  364. color: #F4657A;
  365. line-height: 42rpx;
  366. margin-right: 4rpx;
  367. }
  368. }
  369. &-content{
  370. width: calc(100% - 209rpx);
  371. display: flex;
  372. align-items: center;
  373. justify-content: flex-end;
  374. &-box{
  375. margin-left: 80rpx;
  376. image{
  377. width: 28rpx;
  378. height: 28rpx;
  379. }
  380. text{
  381. font-family: PingFangSC, PingFang SC;
  382. font-weight: 400;
  383. font-size: 30rpx;
  384. color: #252525;
  385. line-height: 42rpx;
  386. margin-left: 16rpx;
  387. }
  388. }
  389. }
  390. }
  391. }
  392. .btn{
  393. width: calc(100% - 80rpx);
  394. height: 90rpx;
  395. background: #B7F358;
  396. border-radius: 45rpx;
  397. font-family: PingFang-SC, PingFang-SC;
  398. font-weight: bold;
  399. font-size: 32rpx;
  400. color: #151B29;
  401. line-height: 90rpx;
  402. text-align: center;
  403. letter-spacing: 2rpx;
  404. position: fixed;
  405. left: 40rpx;
  406. bottom: 64rpx;
  407. }
  408. }
  409. </style>