123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <template>
- <view class="bg">
- <view v-if="showType == '1'" class="scrollview">
- <u--form :rules="rules" labelPosition="left" :model="form" ref="uForm">
- <u-form-item prop="username" :labelWidth="labelWidth" label="用户名" borderBottom >
- <u--input maxlength="12" placeholder="请输入用户名" v-model="form.username" border="none" ></u--input>
- </u-form-item>
- <!--
- <u-form-item prop="address" :labelWidth="labelWidth" label="签名" borderBottom >
- <u--input placeholder="签名" v-model="form.address" border="none" ></u--input>
- </u-form-item> -->
- <u-form-item :labelWidth="labelWidth" label="头像" borderBottom >
- <u-upload
- :fileList="fileList1"
- @afterRead="afterRead"
- @delete="deletePic"
- name="1"
- multiple
- :maxCount="1"
- ></u-upload>
- </u-form-item>
- </u--form>
- </view>
- <view v-if="showType == 'fangkui'" class="scrollview">
- <u--form :rules="rules" labelPosition="left" :model="form" ref="uForm">
- <u-form-item prop="fangkuiyijian" :labelWidth="labelWidth" label="反馈意见" borderBottom >
- <u--textarea v-model="form.fangkuiyijian" placeholder="请输入反馈意见"
- count maxlength="200" ></u--textarea>
- </u-form-item>
- <u-form-item prop="phone" :labelWidth="labelWidth" label="手机号" borderBottom >
- <u--input placeholder="请输入手机号" v-model="form.phone" border="none" ></u--input>
- </u-form-item>
- </u--form>
- </view>
- <view class="btnbox" style="left: 24rpx;">
- <view @click="submit" class="btn">
- 保存
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- modifyInfo,myInfo,feedback
- } from '@/http/api/common.js'
- import env from "@/http/config/config.js"
- import {toastFunc} from '@/pages/util/util.js'
- export default {
- data() {
- return {
- form:{
- username:'',
- phone:'',
- address:'',
- address2:'',
- check:false,
- fangkuiyijian:''
- },
- fileList1:[],
- fileList:[],
- file:[],
- labelWidth:100,
- popupShow:false,
- rules: {
- 'username': {
- type: 'string',
- required: true,
- message: '请填写用户名',
- trigger: ['blur', 'change']
- },
- 'fangkuiyijian': {
- type: 'string',
- required: true,
- message: '请填写反馈意见',
- trigger: ['blur', 'change']
- },
- 'phone':[
- {
- type: 'string',
- required: true,
- message: '请输入手机号',
- trigger: ['blur', 'change']
- },
- {
- validator: (rule, value, callback) => {
- return uni.$u.test.mobile(value);
- },
- message: '手机号码格式不正确',
- // 触发器可以同时用blur和change
- trigger: ['blur'],
- }
- ]
- },
- showType:'1',
- }
- },
- components: {
- // appitem,
- },
- onLoad(e) {
- if (e?.showType) {
- uni.setNavigationBarTitle({
- title: "意见反馈"
- })
- this.showType = e?.showType
- }
- if (this.showType == '1') {
- //获取个人信息
- this.getmyInfo()
- }
-
- },
- onReady() {
- //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
- this.$refs.uForm?.setRules(this.rules)
- },
- methods: {
- async getmyInfo(){
- let res = await myInfo()
- if (res.data.code == 200) {
- this.form.username = res.data.data.nickName
- this.fileList1.push({
- url:res.data.data.image
- })
-
- }
- },
- submit(){
- this.$refs.uForm.validate().then(async res1 => {
- if (this.showType == '1') {
- //修改个人信息
- let images = this.fileList1[0].url
- let res = await modifyInfo({
- nickname:this.form.username,
- images:images
- })
- if (res.data.code == 200) {
- toastFunc('修改成功',()=>{
- uni.switchTab({
- url: '/pages/myinfo/myinfo',
- });
- })
- }
- }else{
- //意见反馈
- let res = await feedback({
- content:this.form.fangkuiyijian,
- contact:this.form.phone
- })
- if (res.data.code == 200) {
- toastFunc('反馈成功',()=>{
- uni.switchTab({
- url: '/pages/myinfo/myinfo',
- });
- })
- }
- }
- }).catch(errors => {
- // uni.$u.toast('校验失败')
- })
- },
- // 删除图片
- deletePic(event) {
- this[`fileList${event.name}`].splice(event.index, 1)
- },
- // 新增图片
- async afterRead(event) {
- // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file)
- let fileListLen = this[`fileList${event.name}`].length
- lists.map((item) => {
- this[`fileList${event.name}`].push({
- ...item,
- status: 'uploading',
- message: '上传中'
- })
- })
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i])
- console.log('result',result);
- if (result != '') {
- let item = this[`fileList${event.name}`][fileListLen]
- this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
- status: 'success',
- message: '',
- url: result
- }))
- fileListLen++
- }else{
- toastFunc('上传失败,请删除重试')
- this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign({}, {
- status: 'fail',
- message: '',
- url: ''
- }))
- }
- }
- },
- uploadFilePromise(file) {
- return new Promise((resolve, reject) => {
- let a = uni.uploadFile({
- url: env.BASEURL + '/open/upload/uploadFile', // 仅为示例,非真实的接口地址
- filePath: file.url,
- name: 'file',
- success: (res) => {
- const fileData = JSON.parse(res.data)
- if (fileData.code == 500) {
- resolve('')
- }else{
- const fileData = JSON.parse(res.data)
- resolve(fileData.data.fileUrl)
- }
- }
- });
- })
- },
-
- }
- }
- </script>
- <style lang="scss">
- .bg{
- width: 750rpx;
- height: auto;
- // min-height: 100vh;
- // background: #F1F1F1;
- border-radius: 0rpx 0rpx 0rpx 0rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .btnbox{
- position: fixed;
- bottom: 20rpx;
- }
- .btn{
- width: 702rpx;
- height: 80rpx;
- background: #46A6FF;
- border-radius: 64rpx 64rpx 64rpx 64rpx;
- opacity: 1;
- font-size: 28rpx;
- font-weight: 500;
- color: #FFFFFF;
- line-height: 80rpx;
- text-align: center;
- }
- </style>
|