feedback.vue 12 KB

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