feedback.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view :style="{fontSize: fontSize(30)}">
  3. <view class="header-nav" :style="{height: `calc(88rpx + ${statusBarHeight}px)`,paddingTop: statusBarHeight + 'px'}">
  4. <view class="arrow-left" :style="{top: statusBarHeight + 'px'}" @click="goBack">返回</view>
  5. <view class="header-title" :style="{height:menuButtonH+'px',lineHeight:menuButtonH+'px'}">投诉反馈</view>
  6. </view>
  7. <view class="container" :style="{paddingTop: `calc(88rpx + ${statusBarHeight}px)`}">
  8. <view class="formbox" v-if="isLastChild==1">
  9. <view class="formbox-title">{{ text }}</view>
  10. <view class="form">
  11. <u-form labelPosition="top" labelWidth='auto' :model="formdata" :rules="rules" ref="uForm" errorType="toast">
  12. <u-form-item label=" " prop="complaintContent">
  13. <u--textarea v-model="formdata.complaintContent" border="none" :clearable="true" placeholder="请填写反馈内容" count maxlength='200'></u--textarea>
  14. </u-form-item>
  15. <view class="box">
  16. <u-form-item label="图片(最多9张)">
  17. <view class="imgitem">
  18. <u-upload
  19. :fileList="fileList1"
  20. @afterRead="afterRead"
  21. @delete="deletePic"
  22. name="1"
  23. :maxCount="9"
  24. ></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. <!-- <button class="submit-btn back-btn" @click="goBack">返回</button> -->
  33. </view>
  34. </view>
  35. <view class="container" v-else>
  36. <view class="list-item title">请选择反馈类型</view>
  37. <view class="list-item" v-for="(item, index) in feedbackItems" :key="index"
  38. @click="handleClick(item,index)">
  39. <view>{{ item.complaintTypeName }}</view>
  40. <uni-icons type="right" size="20" color="rgba(0,0,0,.3)" v-if="isLastChild==0"></uni-icons>
  41. </view>
  42. <view class="list-item" v-if="pageIndex!=0&&isLastChild==0" @click="goBack">
  43. 返回上一层
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { mapGetters } from 'vuex';
  51. import{ getTypeTree, complaintRecord,loginByMp } from "@/api/course.js"
  52. export default {
  53. data() {
  54. return {
  55. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  56. menuButtonH: 45,
  57. pageIndex: 0,
  58. list: [],
  59. feedbackItems: [],
  60. userId: '',
  61. courseId: '',
  62. videoId: '',
  63. formdata: {
  64. complaintContent: ""
  65. },
  66. rules: {
  67. complaintContent:[{
  68. required: true,
  69. message: '投诉反馈内容不能为空',
  70. trigger: ["change", "blur"]
  71. }]
  72. },
  73. text: '',
  74. templateId: 0,
  75. user: {},
  76. isLastChild: 0,
  77. isLogin: false,
  78. fileList1: [],
  79. };
  80. },
  81. computed: {
  82. ...mapGetters(['coureLogin']),
  83. fontSize() {
  84. return size=>{
  85. const value = uni.upx2px(size)
  86. const scale = uni.getStorageSync('fontScale') || 1;
  87. if(scale>1.5) {
  88. return value * 1.5 + 'px';
  89. } else if(scale<1){
  90. return value + 'px';
  91. }else {
  92. return value * scale + 'px';
  93. }
  94. }
  95. },
  96. },
  97. watch: {
  98. coureLogin: {
  99. immediate: true, // 页面一进入就检查一次
  100. handler(val) {
  101. if (val == 2) {
  102. console.log("AppToken失效,请重新登录")
  103. this.isLogin = false
  104. this.goLogin()
  105. }
  106. }
  107. }
  108. },
  109. onLoad(option) {
  110. this.userId = option.userId || ''
  111. this.courseId = option.courseId || ''
  112. this.videoId = option.videoId || ''
  113. this.utils.isLoginCourse().then(
  114. res => {
  115. if(res){
  116. this.isLogin = true
  117. this.getMenuButton()
  118. this.getList()
  119. } else{
  120. this.isLogin = false
  121. this.goLogin()
  122. }
  123. },
  124. rej => {}
  125. );
  126. },
  127. methods: {
  128. getMenuButton(){
  129. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  130. this.menuButtonH = menuButtonInfo.height
  131. },
  132. goBack() {
  133. // 返回上一层逻辑
  134. if (this.pageIndex == 0) {
  135. uni.navigateBack();
  136. } else {
  137. this.pageIndex--;
  138. this.formdata = {
  139. complaintContent: ""
  140. }
  141. if (this.isLastChild == 1) {
  142. this.isLastChild = 0
  143. } else {
  144. if (this.pageIndex == 0) {
  145. this.feedbackItems = this.list
  146. this.templateId = 0
  147. } else {
  148. const list = this.findGrandparentOrAllData(this.list, this.templateId)
  149. this.feedbackItems = list.childrenType
  150. this.templateId = list.complaintTypeId
  151. }
  152. }
  153. }
  154. },
  155. findGrandparentOrAllData(data, targetId) {
  156. // 递归函数,用于查找目标节点的父级节点
  157. function findParent(node, targetId) {
  158. if (!node || !node.childrenType) return null;
  159. for (let child of node.childrenType) {
  160. if (child.complaintTypeId === targetId) {
  161. return node; // 找到目标节点的父级节点
  162. }
  163. const result = findParent(child, targetId); // 递归查找子节点
  164. if (result) return result;
  165. }
  166. return null;
  167. }
  168. // 遍历顶层节点,查找目标节点的父级和祖父级节点
  169. for (let root of data) {
  170. if (root.complaintTypeId === targetId) {
  171. return data; // 如果目标节点是顶层节点,返回所有数据
  172. }
  173. const parent = findParent(root, targetId); // 查找目标节点的父级节点
  174. if (parent) {
  175. const grandparent = findParent(root, parent.complaintTypeId); // 查找父级节点的父级节点
  176. return grandparent || data; // 如果找到祖父节点返回祖父节点,否则返回所有数据
  177. }
  178. }
  179. return data; // 如果没有找到目标节点,返回所有数据
  180. },
  181. handleClick(item,index) {
  182. if (this.isLastChild == 1) return
  183. if (this.pageIndex >= 0) {
  184. this.pageIndex++
  185. let children = this.feedbackItems[index].childrenType || [];
  186. this.templateId = this.feedbackItems[index].complaintTypeId
  187. this.formdata = {
  188. complaintContent: ""
  189. }
  190. this.text = this.feedbackItems[index].complaintTypeName
  191. if (children.length > 0) {
  192. this.isLastChild = 0
  193. this.feedbackItems = children
  194. this.templateId = this.feedbackItems[0].complaintTypeId
  195. } else {
  196. this.isLastChild = 1
  197. this.formdata = {
  198. complaintContent: ""
  199. }
  200. setTimeout(() => {
  201. this.$refs.uForm.setRules(this.rules)
  202. }, 200)
  203. }
  204. }
  205. },
  206. getList(){
  207. getTypeTree().then(res=>{
  208. if(res.code == 200) {
  209. this.list = res.data
  210. this.pageIndex = 0
  211. this.feedbackItems = this.list
  212. }
  213. })
  214. },
  215. submit() {
  216. if(this.fileList1.some(item=>item.status == 'uploading')) {
  217. uni.showToast({
  218. title: '等待图片上传中',
  219. icon: 'none'
  220. })
  221. return
  222. }
  223. var images=[];
  224. this.fileList1.forEach(function(element) {
  225. images.push(element.url)
  226. });
  227. this.$refs.uForm.validate().then(res => {
  228. if (res) {
  229. const param = {
  230. userId: this.userId,
  231. complaintTypeId: this.templateId,
  232. complaintContent: this.formdata.complaintContent,
  233. courseId: this.courseId,
  234. videoId: this.videoId,
  235. complaintUrl: images.toString()
  236. }
  237. complaintRecord(param).then(res=>{
  238. uni.showModal({
  239. title: '',
  240. content: '我们已收到您的反馈,谢谢',
  241. showCancel: false,
  242. success: function (res) {
  243. if (res.confirm) {
  244. uni.navigateBack()
  245. } else if (res.cancel) {
  246. uni.navigateBack()
  247. }
  248. }
  249. });
  250. })
  251. }
  252. })
  253. },
  254. deletePic(event) {
  255. this[`fileList${event.name}`].splice(event.index, 1)
  256. },
  257. async afterRead(event) {
  258. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  259. let lists = [].concat(event.file)
  260. let fileListLen = this[`fileList${event.name}`].length
  261. lists.map((item) => {
  262. this[`fileList${event.name}`].push({
  263. ...item,
  264. status: 'uploading',
  265. message: '上传中'
  266. })
  267. })
  268. for (let i = 0; i < lists.length; i++) {
  269. const result = await this.uploadFilePromise(lists[i].url)
  270. let item = this[`fileList${event.name}`][fileListLen]
  271. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  272. status: 'success',
  273. message: '',
  274. url: result
  275. }))
  276. fileListLen++
  277. }
  278. },
  279. uploadFilePromise(url) {
  280. return new Promise((resolve, reject) => {
  281. let a = uni.uploadFile({
  282. url: 'https://h5api.his.cdwjyyh.com/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  283. filePath: url,
  284. name: 'file',
  285. success: (res) => {
  286. setTimeout(() => {
  287. console.log(JSON.parse(res.data).url)
  288. resolve(JSON.parse(res.data).url)
  289. }, 1000)
  290. }
  291. });
  292. })
  293. },
  294. goLogin() {
  295. this.utils.getProvider().then(provider=>{
  296. console.log('当前的环境商',provider)
  297. if (!provider) {
  298. reject()
  299. }
  300. uni.login({
  301. provider: provider,
  302. success: async loginRes => {
  303. console.log(loginRes)
  304. uni.getUserInfo({
  305. provider: provider,
  306. success: (infoRes)=> {
  307. uni.showToast({
  308. title: '处理中...',
  309. icon: 'loading'
  310. });
  311. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId:"wx19c8813ffc33d1cb"}).then(res=>{
  312. uni.hideLoading();
  313. if (res.code == 200) {
  314. this.$store.commit('setCoureLogin', 1);
  315. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  316. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  317. this.userId = res.user.userId || ''
  318. this.isLogin = true
  319. this.getMenuButton()
  320. this.getList()
  321. } else {
  322. uni.showToast({
  323. title: res.msg,
  324. icon: 'none'
  325. });
  326. }
  327. }).catch(err=>{
  328. uni.hideLoading();
  329. uni.showToast({
  330. icon:'none',
  331. title: "登录失败,请重新登录",
  332. });
  333. });
  334. }
  335. });
  336. }
  337. })
  338. }).catch(err => {})
  339. },
  340. }
  341. };
  342. </script>
  343. <style scoped lang="scss">
  344. .container {
  345. background-color: #fff;
  346. }
  347. .formbox-title {
  348. padding-bottom: 30rpx;
  349. border-bottom: 1px solid #f4f4f4;
  350. }
  351. .formbox {
  352. border-top: 1px solid #f4f4f4;
  353. padding: 30rpx;
  354. }
  355. .box {
  356. padding-bottom: 24rpx;
  357. border-top: 1px solid #f4f4f4;
  358. .imgitem {
  359. padding-top: 20rpx;
  360. }
  361. }
  362. .footer-btn {
  363. margin-top: 50rpx;
  364. }
  365. .submit-btn {
  366. width: 50%;
  367. height: 88rpx;
  368. line-height: 88rpx;
  369. text-align: center;
  370. font-size: 30rpx;
  371. font-family: PingFang SC;
  372. color: #FFFFFF;
  373. background: rgb(0,178,106);
  374. border-radius: 16rpx;
  375. border: 1rpx solid ;
  376. margin-bottom: 30rpx;
  377. &::after {
  378. border: none;
  379. }
  380. }
  381. .back-btn {
  382. color: #bbb;
  383. background: transparent;
  384. border-radius: 16rpx;
  385. border: 1rpx solid #999;
  386. }
  387. .header-nav {
  388. height: 88rpx;
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. overflow: hidden;
  393. background-color: #fff;
  394. box-sizing: border-box;
  395. width: 100%;
  396. position: fixed;
  397. top: 0;
  398. left: 0;
  399. .header-title {
  400. flex: 1;
  401. text-align: center;
  402. overflow: hidden;
  403. white-space: nowrap;
  404. text-overflow: ellipsis;
  405. font-family: PingFang SC,PingFang SC;
  406. font-weight: 500;
  407. font-size: 15px;
  408. color: #000;
  409. box-sizing: border-box;
  410. }
  411. }
  412. .arrow-left {
  413. position: absolute;
  414. left: 24rpx;
  415. height: 88rpx;
  416. display: flex;
  417. align-items: center;
  418. justify-content: center;
  419. overflow: hidden;
  420. }
  421. .list-item {
  422. background-color: #fff;
  423. padding: 24rpx;
  424. border-bottom: 1rpx solid #f4f4f4;
  425. font-size: 15px;
  426. color: #333;
  427. }
  428. .title {
  429. background-color: #f4f4f4;
  430. }
  431. </style>