userInfo.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="bg">
  3. <view v-if="showType == '1'" class="scrollview">
  4. <u--form :rules="rules" labelPosition="left" :model="form" ref="uForm">
  5. <u-form-item prop="username" :labelWidth="labelWidth" label="用户名" borderBottom >
  6. <u--input maxlength="12" placeholder="请输入用户名" v-model="form.username" border="none" ></u--input>
  7. </u-form-item>
  8. <!--
  9. <u-form-item prop="address" :labelWidth="labelWidth" label="签名" borderBottom >
  10. <u--input placeholder="签名" v-model="form.address" border="none" ></u--input>
  11. </u-form-item> -->
  12. <u-form-item :labelWidth="labelWidth" label="头像" borderBottom >
  13. <u-upload
  14. :fileList="fileList1"
  15. @afterRead="afterRead"
  16. @delete="deletePic"
  17. name="1"
  18. multiple
  19. :maxCount="1"
  20. ></u-upload>
  21. </u-form-item>
  22. </u--form>
  23. </view>
  24. <view v-if="showType == 'fangkui'" class="scrollview">
  25. <u--form :rules="rules" labelPosition="left" :model="form" ref="uForm">
  26. <u-form-item prop="fangkuiyijian" :labelWidth="labelWidth" label="反馈意见" borderBottom >
  27. <u--textarea v-model="form.fangkuiyijian" placeholder="请输入反馈意见"
  28. count maxlength="200" ></u--textarea>
  29. </u-form-item>
  30. <u-form-item prop="phone" :labelWidth="labelWidth" label="手机号" borderBottom >
  31. <u--input placeholder="请输入手机号" v-model="form.phone" border="none" ></u--input>
  32. </u-form-item>
  33. </u--form>
  34. </view>
  35. <view class="btnbox" style="left: 24rpx;">
  36. <view @click="submit" class="btn">
  37. 保存
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. modifyInfo,myInfo,feedback
  45. } from '@/http/api/common.js'
  46. import env from "@/http/config/config.js"
  47. import {toastFunc} from '@/pages/util/util.js'
  48. export default {
  49. data() {
  50. return {
  51. form:{
  52. username:'',
  53. phone:'',
  54. address:'',
  55. address2:'',
  56. check:false,
  57. fangkuiyijian:''
  58. },
  59. fileList1:[],
  60. fileList:[],
  61. file:[],
  62. labelWidth:100,
  63. popupShow:false,
  64. rules: {
  65. 'username': {
  66. type: 'string',
  67. required: true,
  68. message: '请填写用户名',
  69. trigger: ['blur', 'change']
  70. },
  71. 'fangkuiyijian': {
  72. type: 'string',
  73. required: true,
  74. message: '请填写反馈意见',
  75. trigger: ['blur', 'change']
  76. },
  77. 'phone':[
  78. {
  79. type: 'string',
  80. required: true,
  81. message: '请输入手机号',
  82. trigger: ['blur', 'change']
  83. },
  84. {
  85. validator: (rule, value, callback) => {
  86. return uni.$u.test.mobile(value);
  87. },
  88. message: '手机号码格式不正确',
  89. // 触发器可以同时用blur和change
  90. trigger: ['blur'],
  91. }
  92. ]
  93. },
  94. showType:'1',
  95. }
  96. },
  97. components: {
  98. // appitem,
  99. },
  100. onLoad(e) {
  101. if (e?.showType) {
  102. uni.setNavigationBarTitle({
  103. title: "意见反馈"
  104. })
  105. this.showType = e?.showType
  106. }
  107. if (this.showType == '1') {
  108. //获取个人信息
  109. this.getmyInfo()
  110. }
  111. },
  112. onReady() {
  113. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  114. this.$refs.uForm?.setRules(this.rules)
  115. },
  116. methods: {
  117. async getmyInfo(){
  118. let res = await myInfo()
  119. if (res.data.code == 200) {
  120. this.form.username = res.data.data.nickName
  121. this.fileList1.push({
  122. url:res.data.data.image
  123. })
  124. }
  125. },
  126. submit(){
  127. this.$refs.uForm.validate().then(async res1 => {
  128. if (this.showType == '1') {
  129. //修改个人信息
  130. let images = this.fileList1[0].url
  131. let res = await modifyInfo({
  132. nickname:this.form.username,
  133. images:images
  134. })
  135. if (res.data.code == 200) {
  136. toastFunc('修改成功',()=>{
  137. uni.switchTab({
  138. url: '/pages/myinfo/myinfo',
  139. });
  140. })
  141. }
  142. }else{
  143. //意见反馈
  144. let res = await feedback({
  145. content:this.form.fangkuiyijian,
  146. contact:this.form.phone
  147. })
  148. if (res.data.code == 200) {
  149. toastFunc('反馈成功',()=>{
  150. uni.switchTab({
  151. url: '/pages/myinfo/myinfo',
  152. });
  153. })
  154. }
  155. }
  156. }).catch(errors => {
  157. // uni.$u.toast('校验失败')
  158. })
  159. },
  160. // 删除图片
  161. deletePic(event) {
  162. this[`fileList${event.name}`].splice(event.index, 1)
  163. },
  164. // 新增图片
  165. async afterRead(event) {
  166. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  167. let lists = [].concat(event.file)
  168. let fileListLen = this[`fileList${event.name}`].length
  169. lists.map((item) => {
  170. this[`fileList${event.name}`].push({
  171. ...item,
  172. status: 'uploading',
  173. message: '上传中'
  174. })
  175. })
  176. for (let i = 0; i < lists.length; i++) {
  177. const result = await this.uploadFilePromise(lists[i])
  178. console.log('result',result);
  179. if (result != '') {
  180. let item = this[`fileList${event.name}`][fileListLen]
  181. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  182. status: 'success',
  183. message: '',
  184. url: result
  185. }))
  186. fileListLen++
  187. }else{
  188. toastFunc('上传失败,请删除重试')
  189. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign({}, {
  190. status: 'fail',
  191. message: '',
  192. url: ''
  193. }))
  194. }
  195. }
  196. },
  197. uploadFilePromise(file) {
  198. return new Promise((resolve, reject) => {
  199. let a = uni.uploadFile({
  200. url: env.BASEURL + '/open/upload/uploadFile', // 仅为示例,非真实的接口地址
  201. filePath: file.url,
  202. name: 'file',
  203. success: (res) => {
  204. const fileData = JSON.parse(res.data)
  205. if (fileData.code == 500) {
  206. resolve('')
  207. }else{
  208. const fileData = JSON.parse(res.data)
  209. resolve(fileData.data.fileUrl)
  210. }
  211. }
  212. });
  213. })
  214. },
  215. }
  216. }
  217. </script>
  218. <style lang="scss">
  219. .bg{
  220. width: 750rpx;
  221. height: auto;
  222. // min-height: 100vh;
  223. // background: #F1F1F1;
  224. border-radius: 0rpx 0rpx 0rpx 0rpx;
  225. display: flex;
  226. flex-direction: column;
  227. align-items: center;
  228. }
  229. .btnbox{
  230. position: fixed;
  231. bottom: 20rpx;
  232. }
  233. .btn{
  234. width: 702rpx;
  235. height: 80rpx;
  236. background: #46A6FF;
  237. border-radius: 64rpx 64rpx 64rpx 64rpx;
  238. opacity: 1;
  239. font-size: 28rpx;
  240. font-weight: 500;
  241. color: #FFFFFF;
  242. line-height: 80rpx;
  243. text-align: center;
  244. }
  245. </style>