familyMemberVindicate.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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>
  84. <view class="btn" @click="handleSave">保存</view>
  85. <qf-image-cropper :width="500" :height="500" :radius="30" @crop="handleCrop" ref="qicRef" v-if="qicShow"></qf-image-cropper>
  86. </view>
  87. </template>
  88. <script setup name="">
  89. import { BaseApi2 } from '../common/api/baseApi';
  90. import CusHeader from '@/components/CusHeader/index.vue'
  91. import { onLoad } from '@dcloudio/uni-app'
  92. import { ref, getCurrentInstance, nextTick } from 'vue'
  93. const { proxy } = getCurrentInstance()
  94. const title = ref('添加家庭成员')
  95. const defaultAvatar = ref('https://oss.familydaf.cn/sxsnfile/20251218/3821654e080945998d464f3c3aa64122.png')
  96. const memberInfo = ref({
  97. userId:'',
  98. personnelType:1,
  99. name:'',
  100. idCard:'',
  101. volunteerNo:'',
  102. gender:0,
  103. currentSchool:''
  104. })
  105. const qicShow = ref(false)
  106. // 渠道相关
  107. const channelList = ref([]) // 会员渠道列表(可选项)
  108. const selectedChannelId = ref('') // 已选渠道 ID(字符串)
  109. const selectedChannelIndex = ref(-1) // picker 当前选中下标,-1 表示未选
  110. const turnType = ref('')
  111. const loadChannelList = () => {
  112. proxy.$api.get('/app/channel/list', {}).then(({ data: res }) => {
  113. if (res.code !== 0) return
  114. channelList.value = res.data || []
  115. })
  116. }
  117. const loadMemberChannel = (memberId) => {
  118. proxy.$api.get('/app/member/channelList', { memberId }).then(({ data: res }) => {
  119. if (res.code !== 0) return
  120. const list = res.data || []
  121. if (list.length > 0) {
  122. selectedChannelId.value = String(list[0].id)
  123. const idx = channelList.value.findIndex(c => String(c.id) === selectedChannelId.value)
  124. if (idx >= 0) selectedChannelIndex.value = idx
  125. }
  126. })
  127. }
  128. const changeMember = (value,key) => {
  129. memberInfo.value[key] = value;
  130. }
  131. const handleSave = async () => {
  132. if(!memberInfo.value.avatarPath) return proxy.$showToast('请上传头像')
  133. if(memberInfo.value.welfareName&&memberInfo.value.welfareName.length<3) return proxy.$showToast('个人公益名称至少三个字')
  134. if(!memberInfo.value.name) return proxy.$showToast('请输入姓名')
  135. if(!proxy.$reg.idCard(memberInfo.value.idCard)) return proxy.$showToast('请输入正确的身份证号')
  136. if(!memberInfo.value.currentSchool&&memberInfo.value.personnelType==2) return proxy.$showToast('请输入就读学校')
  137. memberInfo.value.gender = memberInfo.value.gender??1;
  138. const checkMsgs = ['welfareName','welfareSlogan','name'].map(k=>checkMsg(k));
  139. const tipRes = (await Promise.all(checkMsgs)).filter(item=>item!=='ok');
  140. if(tipRes&&tipRes.length) return proxy.$showModal(tipRes.join('、'))
  141. if(!memberInfo.value.userId) memberInfo.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  142. proxy.$api[memberInfo.value.id?'put':'post']('/core/family/member',memberInfo.value).then(({data:res})=>{
  143. if(res.code!==0) return proxy.$showToast(res.msg)
  144. proxy.$showToast(memberInfo.value.id?'编辑成功':'添加成功')
  145. setTimeout(()=>{
  146. if(turnType.value==='my'){
  147. uni.reLaunch({
  148. url:'/pages/my'
  149. })
  150. return
  151. }
  152. uni.redirectTo({
  153. url:'/pagesMy/familyMember'
  154. })
  155. },1000)
  156. })
  157. }
  158. const checkMsg = async msg => {
  159. const msgAlert = {
  160. welfareName:'家庭公益名称',
  161. welfareSlogan:'家庭公益口号',
  162. name:'姓名'
  163. }
  164. return new Promise((resolve,reject)=>{
  165. proxy.$api.detectionContent(memberInfo.value[msg]).then(res=>{
  166. resolve(res.code!==0?(`${msgAlert[msg]}:`+res.msg):'ok')
  167. })
  168. })
  169. }
  170. const getMemberInfo = (id) => {
  171. proxy.$api.get(`/core/family/member/${id}`).then(({data:res})=>{
  172. if(res.code!==0) return proxy.$showToast(res.msg)
  173. if(res.data){
  174. memberInfo.value = {...memberInfo.value,...res.data}
  175. }
  176. })
  177. }
  178. const changeAvatar = () => {
  179. uni.showActionSheet({
  180. itemList: ['从手机相册选择'],
  181. success: (res) => {
  182. if (res.tapIndex === 0) { // 从手机相册选择
  183. chooseLocalImage();
  184. }
  185. }
  186. });
  187. }
  188. // 从本地选择图片并显示
  189. const chooseLocalImage = () => {
  190. uni.chooseImage({
  191. count: 1, // 只能选择一张
  192. sizeType: ['compressed'], // 压缩图片
  193. sourceType: ['album', 'camera'], // 可以从相册或相机选择
  194. success: (res) => {
  195. const tempFilePaths = res.tempFilePaths;
  196. if (tempFilePaths && tempFilePaths.length > 0) {
  197. proxy.$api.detectionContent(tempFilePaths[0],2).then(res=>{
  198. if(res.code!==0) return proxy.$showToast(res.msg)
  199. qicShow.value = true;
  200. nextTick(()=>{
  201. proxy.$refs.qicRef.initImage(tempFilePaths[0],true)
  202. })
  203. })
  204. }
  205. },
  206. fail: (err) => {
  207. console.error('选择图片失败', err);
  208. }
  209. });
  210. }
  211. const handleCrop = async (e) => {
  212. const result = await uploadFilePromise(e.tempFilePath);
  213. memberInfo.value.avatarPath = result||'';
  214. qicShow.value = false;
  215. }
  216. const uploadFilePromise = (url) => {
  217. return new Promise((resolve, reject) => {
  218. let a = uni.uploadFile({
  219. url: BaseApi2+'/sys/oss/upload',
  220. filePath: url,
  221. name: 'file',
  222. success: (res) => {
  223. setTimeout(() => {
  224. let data = JSON.parse(res.data)
  225. if(data&&data.code===0){
  226. resolve(data.data);
  227. }else proxy.$showToast(data?.msg)
  228. }, 1000);
  229. },
  230. fail: err =>{
  231. resolve('');
  232. }
  233. });
  234. });
  235. };
  236. onLoad((options)=>{
  237. turnType.value = options.type;
  238. loadChannelList()
  239. const id = options?.id;
  240. if(id){
  241. title.value = '编辑家庭成员';
  242. getMemberInfo(id)
  243. loadMemberChannel(id)
  244. }
  245. })
  246. </script>
  247. <style scoped lang="scss">
  248. .common_page{
  249. padding-bottom: 184rpx;
  250. .form{
  251. background: #FFFFFF;
  252. border-radius: 24rpx;
  253. margin-top: 20rpx;
  254. padding: 36rpx 24rpx 0;
  255. .avatar{
  256. .title{
  257. font-family: PingFang-SC, PingFang-SC;
  258. font-weight: bold;
  259. font-size: 30rpx;
  260. color: #252525;
  261. line-height: 42rpx;
  262. label{
  263. font-family: PingFangSC, PingFang SC;
  264. font-weight: 400;
  265. font-size: 30rpx;
  266. color: #F4657A;
  267. line-height: 42rpx;
  268. }
  269. }
  270. .imgbox{
  271. width: 122rpx;
  272. height: 122rpx;
  273. &-avatar{
  274. width: 100%;
  275. height: 100%;
  276. border-radius: 50%;
  277. }
  278. }
  279. .add-avatar{
  280. margin-left: 40rpx;
  281. width: 122rpx;
  282. height: 122rpx;
  283. border-radius: 50%;
  284. }
  285. border-bottom: 1rpx solid #E6E6E6;
  286. }
  287. .item{
  288. height: 90rpx;
  289. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  290. .left{
  291. width: 200rpx;
  292. font-family: PingFangSC, PingFang SC;
  293. font-weight: 400;
  294. font-size: 28rpx;
  295. color: #676775;
  296. line-height: 40rpx;
  297. }
  298. .right{
  299. width: calc(100% - 200rpx);
  300. }
  301. }
  302. .title{
  303. font-family: PingFang-SC, PingFang-SC;
  304. font-weight: bold;
  305. font-size: 36rpx;
  306. color: #151B29;
  307. line-height: 48rpx;
  308. }
  309. .pre{
  310. padding: 25rpx 0;
  311. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #F2F2F2;
  312. &-title{
  313. width: 209rpx;
  314. font-family: PingFangSC, PingFang SC;
  315. font-weight: 400;
  316. font-size: 28rpx;
  317. color: #676775;
  318. line-height: 40rpx;
  319. label{
  320. font-family: PingFangSC, PingFang SC;
  321. font-weight: 400;
  322. font-size: 30rpx;
  323. color: #F4657A;
  324. line-height: 42rpx;
  325. margin-right: 4rpx;
  326. }
  327. }
  328. &-content{
  329. width: calc(100% - 209rpx);
  330. display: flex;
  331. align-items: center;
  332. justify-content: flex-end;
  333. &-box{
  334. margin-left: 80rpx;
  335. image{
  336. width: 28rpx;
  337. height: 28rpx;
  338. }
  339. text{
  340. font-family: PingFangSC, PingFang SC;
  341. font-weight: 400;
  342. font-size: 30rpx;
  343. color: #252525;
  344. line-height: 42rpx;
  345. margin-left: 16rpx;
  346. }
  347. }
  348. }
  349. }
  350. }
  351. .btn{
  352. width: calc(100% - 80rpx);
  353. height: 90rpx;
  354. background: #B7F358;
  355. border-radius: 45rpx;
  356. font-family: PingFang-SC, PingFang-SC;
  357. font-weight: bold;
  358. font-size: 32rpx;
  359. color: #151B29;
  360. line-height: 90rpx;
  361. text-align: center;
  362. letter-spacing: 2rpx;
  363. position: fixed;
  364. left: 40rpx;
  365. bottom: 64rpx;
  366. }
  367. }
  368. </style>