complaint.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. return new Promise((resolve, reject) => {
  269. let a = uni.uploadFile({
  270. url: uni.getStorageSync('addressUrl_' + projectCode) +
  271. '/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  272. filePath: url,
  273. name: 'file',
  274. success: (res) => {
  275. setTimeout(() => {
  276. console.log(JSON.parse(res.data).url)
  277. resolve(JSON.parse(res.data).url)
  278. }, 1000)
  279. }
  280. });
  281. })
  282. },
  283. // goLogin(data) {
  284. // if (!this.projectCode) {
  285. // uni.showToast({
  286. // title: '链接有误',
  287. // icon: 'none'
  288. // });
  289. // return
  290. // }
  291. // this.loginFsUserWx(data)
  292. // return
  293. // this.utils.getProvider().then(provider => {
  294. // console.log('当前的环境商', provider)
  295. // if (!provider) {
  296. // reject()
  297. // }
  298. // uni.login({
  299. // provider: provider,
  300. // success: async loginRes => {
  301. // console.log(loginRes)
  302. // uni.getUserInfo({
  303. // provider: provider,
  304. // success: (infoRes) => {
  305. // uni.showToast({
  306. // title: '处理中...',
  307. // icon: 'loading'
  308. // });
  309. // loginByMp({
  310. // code: loginRes.code,
  311. // encryptedData: infoRes.encryptedData,
  312. // iv: infoRes.iv,
  313. // appId: getApp().globalData.appId
  314. // }).then(res => {
  315. // uni.hideLoading();
  316. // if (res.code == 200) {
  317. // this.$store.commit('setCoureLogin', 1);
  318. // uni.setStorageSync(this.utils
  319. // .TOKEN_KEYAuto, res.token);
  320. // uni.setStorageSync('auto_userInfo',
  321. // JSON.stringify(res.user));
  322. // this.userId = res.user.userId || ''
  323. // this.isLogin = true
  324. // this.getMenuButton()
  325. // this.getList()
  326. // } else {
  327. // uni.showToast({
  328. // title: res.msg,
  329. // icon: 'none'
  330. // });
  331. // }
  332. // }).catch(err => {
  333. // uni.hideLoading();
  334. // uni.showToast({
  335. // icon: 'none',
  336. // title: "登录失败,请重新登录",
  337. // });
  338. // });
  339. // }
  340. // });
  341. // }
  342. // })
  343. // }).catch(err => {})
  344. // },
  345. // H5授权绑定关系
  346. // async loginFsUserWx(data) {
  347. // if (data) {
  348. // let token = uni.getStorageSync('TOKEN_WEXIN');
  349. // let user = uni.getStorageSync('userInfo')
  350. // uni.setStorageSync(this.utils.TOKEN_KEYAuto, token);
  351. // uni.setStorageSync('auto_userInfo', JSON.stringify(user));
  352. // this.userId = user.userId || ''
  353. // this.isLogin = true
  354. // this.getMenuButton()
  355. // this.getList()
  356. // } else {
  357. // uni.setStorageSync('H5course', {
  358. // companyId: this.urlOption.companyId,
  359. // companyUserId: this.urlOption.companyUserId,
  360. // type: 1, //1自动,其他手动
  361. // })
  362. // uni.showLoading({
  363. // title: '加载中'
  364. // });
  365. // try {
  366. // await this.utils.getDomain({
  367. // projectCode: this.projectCode
  368. // }); // code 换成你的业务标识
  369. // await this.utils.getConfigKey();
  370. // uni.navigateTo({
  371. // url: '/pages_course/webview?H5course=' + uni.getStorageSync('H5course')
  372. // })
  373. // } catch (err) {
  374. // console.error('初始化失败', err);
  375. // uni.showToast({
  376. // title: '请求失败',
  377. // icon: 'none'
  378. // });
  379. // } finally {
  380. // uni.hideLoading();
  381. // }
  382. // }
  383. // }
  384. }
  385. };
  386. </script>
  387. <style scoped lang="scss">
  388. .container {
  389. background-color: #fff;
  390. }
  391. .formbox-title {
  392. padding-bottom: 30rpx;
  393. border-bottom: 1px solid #f4f4f4;
  394. }
  395. .formbox {
  396. border-top: 1px solid #f4f4f4;
  397. padding: 30rpx;
  398. }
  399. .box {
  400. padding-bottom: 24rpx;
  401. border-top: 1px solid #f4f4f4;
  402. .imgitem {
  403. padding-top: 20rpx;
  404. }
  405. }
  406. .footer-btn {
  407. margin-top: 50rpx;
  408. }
  409. .submit-btn {
  410. width: 50%;
  411. height: 88rpx;
  412. line-height: 88rpx;
  413. text-align: center;
  414. font-size: 30rpx;
  415. font-family: PingFang SC;
  416. color: #FFFFFF;
  417. background: rgb(0, 178, 106);
  418. border-radius: 16rpx;
  419. border: 1rpx solid;
  420. margin-bottom: 30rpx;
  421. &::after {
  422. border: none;
  423. }
  424. }
  425. .back-btn {
  426. color: #bbb;
  427. background: transparent;
  428. border-radius: 16rpx;
  429. border: 1rpx solid #999;
  430. }
  431. .header-nav {
  432. height: 88rpx;
  433. display: flex;
  434. align-items: center;
  435. justify-content: center;
  436. overflow: hidden;
  437. background-color: #fff;
  438. box-sizing: border-box;
  439. width: 100%;
  440. position: fixed;
  441. top: 0;
  442. left: 0;
  443. .header-title {
  444. flex: 1;
  445. text-align: center;
  446. overflow: hidden;
  447. white-space: nowrap;
  448. text-overflow: ellipsis;
  449. font-family: PingFang SC, PingFang SC;
  450. font-weight: 500;
  451. font-size: 15px;
  452. color: #000;
  453. box-sizing: border-box;
  454. }
  455. }
  456. .arrow-left {
  457. position: absolute;
  458. left: 24rpx;
  459. height: 88rpx;
  460. display: flex;
  461. align-items: center;
  462. justify-content: center;
  463. overflow: hidden;
  464. }
  465. .list-item {
  466. background-color: #fff;
  467. padding: 24rpx;
  468. border-bottom: 1rpx solid #f4f4f4;
  469. font-size: 15px;
  470. color: #333;
  471. }
  472. .title {
  473. background-color: #f4f4f4;
  474. }
  475. </style>