complaint.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <view>
  3. <view class="mt60 p34">
  4. <view class="color#{$5} ">投诉对象</view>
  5. <view class="align-center mt30 mb50">
  6. <image class="w100 h100 mr30" style="border-radius: 50%;" src="/static/images/logo.png"></image>
  7. <text>芳华悦选</text>
  8. </view>
  9. </view>
  10. <view class="container" >
  11. <view class="formbox">
  12. <view class="formbox-title">{{ text }}</view>
  13. <view class="form">
  14. <u-form labelPosition="top" labelWidth='auto' :model="formdata" :rules="rules" ref="uForm"
  15. errorType="toast">
  16. <u-form-item label=" " prop="complaintContent">
  17. <u--textarea v-model="formdata.complaintContent" border="none" :clearable="true"
  18. placeholder="请填写反馈内容" count maxlength='200'></u--textarea>
  19. </u-form-item>
  20. <view class="box">
  21. <u-form-item label="图片(最多9张)">
  22. <view class="imgitem">
  23. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1"
  24. :maxCount="9"></u-upload>
  25. </view>
  26. </u-form-item>
  27. </view>
  28. </u-form>
  29. </view>
  30. <view class="footer-btn">
  31. <button class="submit-btn" @click="submit">提交</button>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. mapGetters
  40. } from 'vuex';
  41. // complaintRecord
  42. import {
  43. getTypeTree,
  44. loginByMp
  45. } from "@/api/course.js"
  46. export default {
  47. data() {
  48. return {
  49. menuButtonH: 45,
  50. pageIndex: 0,
  51. list: [],
  52. feedbackItems: [],
  53. userId: '',
  54. // courseId: '',
  55. // videoId: '',
  56. formdata: {
  57. complaintContent: ""
  58. },
  59. rules: {
  60. complaintContent: [{
  61. required: true,
  62. message: '投诉反馈内容不能为空',
  63. trigger: ["change", "blur"]
  64. }]
  65. },
  66. text: '',
  67. templateId: 0,
  68. user: {},
  69. isLastChild: 0,
  70. isLogin: false,
  71. fileList1: [],
  72. code: ''
  73. };
  74. },
  75. // computed: {
  76. // ...mapGetters(['coureLogin']),
  77. // },
  78. // watch: {
  79. // coureLogin: {
  80. // immediate: true, // 页面一进入就检查一次
  81. // handler(val) {
  82. // if (val == 2) {
  83. // console.log("AppToken失效,请重新登录")
  84. // this.isLogin = false
  85. // this.goLogin()
  86. // }
  87. // }
  88. // }
  89. // },
  90. onLoad(option) {
  91. this.text=option.selectText
  92. // this.userId = option.userId || ''
  93. // this.courseId = option.courseId || ''
  94. // this.videoId = option.videoId || ''
  95. // this.projectCode = option.projectCode || ''
  96. // uni.$on('usercode', (data) => {
  97. // if (data) {
  98. // this.code = data.code
  99. // this.goLogin(data)
  100. // }
  101. // })
  102. // this.utils.getDomain({projectCode:this.projectCode}).then(res=>{
  103. // if(res.code == 200) {
  104. // uni.setStorageSync('addressUrl',res.addressUrl)
  105. // this.utils.isLoginCourseAuto().then(
  106. // res => {
  107. // if(res){
  108. // this.isLogin = true
  109. // this.getMenuButton()
  110. // this.getList()
  111. // } else{
  112. // this.isLogin = false
  113. // this.goLogin()
  114. // }
  115. // },
  116. // rej => {}
  117. // );
  118. // }
  119. // })
  120. },
  121. onUnload() {
  122. uni.$off('usercode')
  123. },
  124. methods: {
  125. getMenuButton() {
  126. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  127. this.menuButtonH = menuButtonInfo.height
  128. },
  129. goBack() {
  130. // 返回上一层逻辑
  131. if (this.pageIndex == 0) {
  132. uni.navigateBack();
  133. } else {
  134. this.pageIndex--;
  135. this.formdata = {
  136. complaintContent: ""
  137. }
  138. if (this.isLastChild == 1) {
  139. this.isLastChild = 0
  140. } else {
  141. if (this.pageIndex == 0) {
  142. this.feedbackItems = this.list
  143. this.templateId = 0
  144. } else {
  145. const list = this.findGrandparentOrAllData(this.list, this.templateId)
  146. this.feedbackItems = list.childrenType
  147. this.templateId = list.complaintTypeId
  148. }
  149. }
  150. }
  151. },
  152. findGrandparentOrAllData(data, targetId) {
  153. // 递归函数,用于查找目标节点的父级节点
  154. function findParent(node, targetId) {
  155. if (!node || !node.childrenType) return null;
  156. for (let child of node.childrenType) {
  157. if (child.complaintTypeId === targetId) {
  158. return node; // 找到目标节点的父级节点
  159. }
  160. const result = findParent(child, targetId); // 递归查找子节点
  161. if (result) return result;
  162. }
  163. return null;
  164. }
  165. // 遍历顶层节点,查找目标节点的父级和祖父级节点
  166. for (let root of data) {
  167. if (root.complaintTypeId === targetId) {
  168. return data; // 如果目标节点是顶层节点,返回所有数据
  169. }
  170. const parent = findParent(root, targetId); // 查找目标节点的父级节点
  171. if (parent) {
  172. const grandparent = findParent(root, parent.complaintTypeId); // 查找父级节点的父级节点
  173. return grandparent || data; // 如果找到祖父节点返回祖父节点,否则返回所有数据
  174. }
  175. }
  176. return data; // 如果没有找到目标节点,返回所有数据
  177. },
  178. // handleClick(item, index) {
  179. // if (this.isLastChild == 1) return
  180. // if (this.pageIndex >= 0) {
  181. // this.pageIndex++
  182. // let children = this.feedbackItems[index].childrenType || [];
  183. // this.templateId = this.feedbackItems[index].complaintTypeId
  184. // this.formdata = {
  185. // complaintContent: ""
  186. // }
  187. // this.text = this.feedbackItems[index].complaintTypeName
  188. // if (children.length > 0) {
  189. // this.isLastChild = 0
  190. // this.feedbackItems = children
  191. // this.templateId = this.feedbackItems[0].complaintTypeId
  192. // } else {
  193. // this.isLastChild = 1
  194. // this.formdata = {
  195. // complaintContent: ""
  196. // }
  197. // setTimeout(() => {
  198. // this.$refs.uForm.setRules(this.rules)
  199. // }, 200)
  200. // }
  201. // }
  202. // },
  203. // getList() {
  204. // getTypeTree().then(res => {
  205. // if (res.code == 200) {
  206. // this.list = res.data
  207. // this.pageIndex = 0
  208. // this.feedbackItems = this.list
  209. // }
  210. // })
  211. // },
  212. submit() {
  213. if (this.fileList1.some(item => item.status == 'uploading')) {
  214. uni.showToast({
  215. title: '等待图片上传中',
  216. icon: 'none'
  217. })
  218. return
  219. }
  220. var images = [];
  221. this.fileList1.forEach(function(element) {
  222. images.push(element.url)
  223. });
  224. this.$refs.uForm.validate().then(res => {
  225. if (res) {
  226. uni.showModal({
  227. title: '',
  228. content: '我们已收到您的反馈,谢谢',
  229. showCancel: false,
  230. success: function(res) {
  231. if (res.confirm) {
  232. uni.navigateBack()
  233. } else if (res.cancel) {
  234. uni.navigateBack()
  235. }
  236. }
  237. });
  238. }
  239. })
  240. },
  241. deletePic(event) {
  242. this[`fileList${event.name}`].splice(event.index, 1)
  243. },
  244. async afterRead(event) {
  245. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  246. let lists = [].concat(event.file)
  247. let fileListLen = this[`fileList${event.name}`].length
  248. lists.map((item) => {
  249. this[`fileList${event.name}`].push({
  250. ...item,
  251. status: 'uploading',
  252. message: '上传中'
  253. })
  254. })
  255. for (let i = 0; i < lists.length; i++) {
  256. const result = await this.uploadFilePromise(lists[i].url)
  257. let item = this[`fileList${event.name}`][fileListLen]
  258. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  259. status: 'success',
  260. message: '',
  261. url: result
  262. }))
  263. fileListLen++
  264. }
  265. },
  266. uploadFilePromise(url) {
  267. const projectCode = uni.getStorageSync('projectCode')
  268. // 添加日志检查关键参数
  269. // console.log('上传参数检查:', {
  270. // projectCode: projectCode,
  271. // addressUrl: uni.getStorageSync('addressUrl_' + projectCode),
  272. // url: url
  273. // })
  274. return new Promise((resolve, reject) => {
  275. let a = uni.uploadFile({
  276. url: uni.getStorageSync('requestPath')+ '/app/common/uploadOSS',
  277. filePath: url,
  278. name: 'file',
  279. formData: {
  280. // 可以添加其他必要参数
  281. 'user': 'test' // 上传附带参数
  282. },
  283. success: (res) => {
  284. console.log('上传成功响应:', res)
  285. if (res.statusCode === 200) {
  286. try {
  287. const data = JSON.parse(res.data)
  288. if (data.code === 200) {
  289. resolve(data.url)
  290. } else {
  291. reject(new Error(data.msg || '上传失败'))
  292. }
  293. } catch (e) {
  294. reject(new Error('解析响应数据失败'))
  295. }
  296. } else {
  297. reject(new Error(`HTTP错误: ${res.statusCode}`))
  298. }
  299. },
  300. fail: (err) => {
  301. console.error('上传失败:', err)
  302. reject(err)
  303. }
  304. });
  305. })
  306. },
  307. // goLogin(data) {
  308. // if (!this.projectCode) {
  309. // uni.showToast({
  310. // title: '链接有误',
  311. // icon: 'none'
  312. // });
  313. // return
  314. // }
  315. // this.loginFsUserWx(data)
  316. // return
  317. // this.utils.getProvider().then(provider => {
  318. // console.log('当前的环境商', provider)
  319. // if (!provider) {
  320. // reject()
  321. // }
  322. // uni.login({
  323. // provider: provider,
  324. // success: async loginRes => {
  325. // console.log(loginRes)
  326. // uni.getUserInfo({
  327. // provider: provider,
  328. // success: (infoRes) => {
  329. // uni.showToast({
  330. // title: '处理中...',
  331. // icon: 'loading'
  332. // });
  333. // loginByMp({
  334. // code: loginRes.code,
  335. // encryptedData: infoRes.encryptedData,
  336. // iv: infoRes.iv,
  337. // appId: getApp().globalData.appId
  338. // }).then(res => {
  339. // uni.hideLoading();
  340. // if (res.code == 200) {
  341. // this.$store.commit('setCoureLogin', 1);
  342. // uni.setStorageSync(this.utils
  343. // .TOKEN_KEYAuto, res.token);
  344. // uni.setStorageSync('auto_userInfo',
  345. // JSON.stringify(res.user));
  346. // this.userId = res.user.userId || ''
  347. // this.isLogin = true
  348. // this.getMenuButton()
  349. // this.getList()
  350. // } else {
  351. // uni.showToast({
  352. // title: res.msg,
  353. // icon: 'none'
  354. // });
  355. // }
  356. // }).catch(err => {
  357. // uni.hideLoading();
  358. // uni.showToast({
  359. // icon: 'none',
  360. // title: "登录失败,请重新登录",
  361. // });
  362. // });
  363. // }
  364. // });
  365. // }
  366. // })
  367. // }).catch(err => {})
  368. // },
  369. // H5授权绑定关系
  370. // async loginFsUserWx(data) {
  371. // if (data) {
  372. // let token = uni.getStorageSync('TOKEN_WEXIN');
  373. // let user = uni.getStorageSync('userInfo')
  374. // uni.setStorageSync(this.utils.TOKEN_KEYAuto, token);
  375. // uni.setStorageSync('auto_userInfo', JSON.stringify(user));
  376. // this.userId = user.userId || ''
  377. // this.isLogin = true
  378. // this.getMenuButton()
  379. // this.getList()
  380. // } else {
  381. // uni.setStorageSync('H5course', {
  382. // companyId: this.urlOption.companyId,
  383. // companyUserId: this.urlOption.companyUserId,
  384. // type: 1, //1自动,其他手动
  385. // })
  386. // uni.showLoading({
  387. // title: '加载中'
  388. // });
  389. // try {
  390. // await this.utils.getDomain({
  391. // projectCode: this.projectCode
  392. // }); // code 换成你的业务标识
  393. // await this.utils.getConfigKey();
  394. // uni.navigateTo({
  395. // url: '/pages_course/webview?H5course=' + uni.getStorageSync('H5course')
  396. // })
  397. // } catch (err) {
  398. // console.error('初始化失败', err);
  399. // uni.showToast({
  400. // title: '请求失败',
  401. // icon: 'none'
  402. // });
  403. // } finally {
  404. // uni.hideLoading();
  405. // }
  406. // }
  407. // }
  408. }
  409. };
  410. </script>
  411. <style scoped lang="scss">
  412. .container {
  413. background-color: #fff;
  414. }
  415. .formbox-title {
  416. padding-bottom: 30rpx;
  417. border-bottom: 1px solid #f4f4f4;
  418. }
  419. .formbox {
  420. border-top: 1px solid #f4f4f4;
  421. padding: 30rpx;
  422. }
  423. .box {
  424. padding-bottom: 24rpx;
  425. border-top: 1px solid #f4f4f4;
  426. .imgitem {
  427. padding-top: 20rpx;
  428. }
  429. }
  430. .footer-btn {
  431. margin-top: 50rpx;
  432. }
  433. .submit-btn {
  434. width: 50%;
  435. height: 88rpx;
  436. line-height: 88rpx;
  437. text-align: center;
  438. font-size: 30rpx;
  439. font-family: PingFang SC;
  440. color: #FFFFFF;
  441. background: rgb(0, 178, 106);
  442. border-radius: 16rpx;
  443. border: 1rpx solid;
  444. margin-bottom: 30rpx;
  445. &::after {
  446. border: none;
  447. }
  448. }
  449. .back-btn {
  450. color: #bbb;
  451. background: transparent;
  452. border-radius: 16rpx;
  453. border: 1rpx solid #999;
  454. }
  455. .header-nav {
  456. height: 88rpx;
  457. display: flex;
  458. align-items: center;
  459. justify-content: center;
  460. overflow: hidden;
  461. background-color: #fff;
  462. box-sizing: border-box;
  463. width: 100%;
  464. position: fixed;
  465. top: 0;
  466. left: 0;
  467. .header-title {
  468. flex: 1;
  469. text-align: center;
  470. overflow: hidden;
  471. white-space: nowrap;
  472. text-overflow: ellipsis;
  473. font-family: PingFang SC, PingFang SC;
  474. font-weight: 500;
  475. font-size: 15px;
  476. color: #000;
  477. box-sizing: border-box;
  478. }
  479. }
  480. .arrow-left {
  481. position: absolute;
  482. left: 24rpx;
  483. height: 88rpx;
  484. display: flex;
  485. align-items: center;
  486. justify-content: center;
  487. overflow: hidden;
  488. }
  489. .list-item {
  490. background-color: #fff;
  491. padding: 24rpx;
  492. border-bottom: 1rpx solid #f4f4f4;
  493. font-size: 15px;
  494. color: #333;
  495. }
  496. .title {
  497. background-color: #f4f4f4;
  498. }
  499. </style>