feedback.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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,handleFsUserWx,getByAppId } 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. authType:1,
  85. code:''
  86. };
  87. },
  88. computed: {
  89. ...mapGetters(['coureLogin']),
  90. fontSize() {
  91. return size=>{
  92. const value = uni.upx2px(size)
  93. const scale = uni.getStorageSync('fontScale') || 1;
  94. if(scale>1.5) {
  95. return value * 1.5 + 'px';
  96. } else if(scale<1){
  97. return value + 'px';
  98. }else {
  99. return value * scale + 'px';
  100. }
  101. }
  102. },
  103. },
  104. watch: {
  105. coureLogin: {
  106. immediate: true, // 页面一进入就检查一次
  107. handler(val) {
  108. if (val == 2) {
  109. console.log("AppToken失效,请重新登录")
  110. this.isLogin = false
  111. this.goLogin()
  112. }
  113. }
  114. }
  115. },
  116. onLoad(option) {
  117. this.userId = option.userId || ''
  118. this.courseId = option.courseId || ''
  119. this.videoId = option.videoId || ''
  120. uni.$on('usercode',(data)=>{
  121. if(data) {
  122. this.code=data.code
  123. this.loginFsUserWx(data)
  124. }
  125. })
  126. if(this.code) return;
  127. this.utils.isLoginCourse().then(
  128. res => {
  129. if(res){
  130. this.isLogin = true
  131. this.getMenuButton()
  132. this.getList()
  133. } else{
  134. this.isLogin = false
  135. this.goLogin()
  136. }
  137. },
  138. rej => {}
  139. );
  140. },
  141. onUnload() {
  142. uni.$off('usercode')
  143. },
  144. beforeDestroy() {
  145. uni.$off('usercode')
  146. },
  147. methods: {
  148. getMenuButton(){
  149. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  150. this.menuButtonH = menuButtonInfo.height
  151. },
  152. goBack() {
  153. // 返回上一层逻辑
  154. if (this.pageIndex == 0) {
  155. uni.navigateBack();
  156. } else {
  157. this.pageIndex--;
  158. this.formdata = {
  159. complaintContent: ""
  160. }
  161. if (this.isLastChild == 1) {
  162. this.isLastChild = 0
  163. } else {
  164. if (this.pageIndex == 0) {
  165. this.feedbackItems = this.list
  166. this.templateId = 0
  167. } else {
  168. const list = this.findGrandparentOrAllData(this.list, this.templateId)
  169. this.feedbackItems = list.childrenType
  170. this.templateId = list.complaintTypeId
  171. }
  172. }
  173. }
  174. },
  175. findGrandparentOrAllData(data, targetId) {
  176. // 递归函数,用于查找目标节点的父级节点
  177. function findParent(node, targetId) {
  178. if (!node || !node.childrenType) return null;
  179. for (let child of node.childrenType) {
  180. if (child.complaintTypeId === targetId) {
  181. return node; // 找到目标节点的父级节点
  182. }
  183. const result = findParent(child, targetId); // 递归查找子节点
  184. if (result) return result;
  185. }
  186. return null;
  187. }
  188. // 遍历顶层节点,查找目标节点的父级和祖父级节点
  189. for (let root of data) {
  190. if (root.complaintTypeId === targetId) {
  191. return data; // 如果目标节点是顶层节点,返回所有数据
  192. }
  193. const parent = findParent(root, targetId); // 查找目标节点的父级节点
  194. if (parent) {
  195. const grandparent = findParent(root, parent.complaintTypeId); // 查找父级节点的父级节点
  196. return grandparent || data; // 如果找到祖父节点返回祖父节点,否则返回所有数据
  197. }
  198. }
  199. return data; // 如果没有找到目标节点,返回所有数据
  200. },
  201. handleClick(item,index) {
  202. if (this.isLastChild == 1) return
  203. if (this.pageIndex >= 0) {
  204. this.pageIndex++
  205. let children = this.feedbackItems[index].childrenType || [];
  206. this.templateId = this.feedbackItems[index].complaintTypeId
  207. this.formdata = {
  208. complaintContent: ""
  209. }
  210. this.text = this.feedbackItems[index].complaintTypeName
  211. if (children.length > 0) {
  212. this.isLastChild = 0
  213. this.feedbackItems = children
  214. this.templateId = this.feedbackItems[0].complaintTypeId
  215. } else {
  216. this.isLastChild = 1
  217. this.formdata = {
  218. complaintContent: ""
  219. }
  220. setTimeout(() => {
  221. this.$refs.uForm.setRules(this.rules)
  222. }, 200)
  223. }
  224. }
  225. },
  226. getList(){
  227. getTypeTree().then(res=>{
  228. if(res.code == 200) {
  229. this.list = res.data
  230. this.pageIndex = 0
  231. this.feedbackItems = this.list
  232. }
  233. })
  234. },
  235. submit() {
  236. if(this.fileList1.some(item=>item.status == 'uploading')) {
  237. uni.showToast({
  238. title: '等待图片上传中',
  239. icon: 'none'
  240. })
  241. return
  242. }
  243. var images=[];
  244. this.fileList1.forEach(function(element) {
  245. images.push(element.url)
  246. });
  247. this.$refs.uForm.validate().then(res => {
  248. if (res) {
  249. const param = {
  250. userId: this.userId,
  251. complaintTypeId: this.templateId,
  252. complaintContent: this.formdata.complaintContent,
  253. courseId: this.courseId,
  254. videoId: this.videoId,
  255. complaintUrl: images.toString()
  256. }
  257. complaintRecord(param).then(res=>{
  258. uni.showModal({
  259. title: '',
  260. content: '我们已收到您的反馈,谢谢',
  261. showCancel: false,
  262. success: function (res) {
  263. if (res.confirm) {
  264. uni.navigateBack()
  265. } else if (res.cancel) {
  266. uni.navigateBack()
  267. }
  268. }
  269. });
  270. })
  271. }
  272. })
  273. },
  274. deletePic(event) {
  275. this[`fileList${event.name}`].splice(event.index, 1)
  276. },
  277. async afterRead(event) {
  278. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  279. let lists = [].concat(event.file)
  280. let fileListLen = this[`fileList${event.name}`].length
  281. lists.map((item) => {
  282. this[`fileList${event.name}`].push({
  283. ...item,
  284. status: 'uploading',
  285. message: '上传中'
  286. })
  287. })
  288. for (let i = 0; i < lists.length; i++) {
  289. const result = await this.uploadFilePromise(lists[i].url)
  290. let item = this[`fileList${event.name}`][fileListLen]
  291. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  292. status: 'success',
  293. message: '',
  294. url: result
  295. }))
  296. fileListLen++
  297. }
  298. },
  299. uploadFilePromise(url) {
  300. return new Promise((resolve, reject) => {
  301. let a = uni.uploadFile({
  302. url: 'https://h5api.his.cdwjyyh.com/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  303. filePath: url,
  304. name: 'file',
  305. success: (res) => {
  306. setTimeout(() => {
  307. console.log(JSON.parse(res.data).url)
  308. resolve(JSON.parse(res.data).url)
  309. }, 1000)
  310. }
  311. });
  312. })
  313. },
  314. goLogin(){
  315. this.getByAppId()
  316. },
  317. goWXLogin() {
  318. this.utils.getProvider().then(provider=>{
  319. console.log('当前的环境商',provider)
  320. if (!provider) {
  321. reject()
  322. }
  323. uni.login({
  324. provider: provider,
  325. success: async loginRes => {
  326. console.log(loginRes)
  327. uni.getUserInfo({
  328. provider: provider,
  329. success: (infoRes)=> {
  330. uni.showToast({
  331. title: '处理中...',
  332. icon: 'loading'
  333. });
  334. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId: getApp().globalData.appId}).then(res=>{
  335. uni.hideLoading();
  336. if (res.code == 200) {
  337. this.$store.commit('setCoureLogin', 1);
  338. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  339. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  340. this.userId = res.user.userId || ''
  341. this.isLogin = true
  342. this.getMenuButton()
  343. this.getList()
  344. } else {
  345. uni.showToast({
  346. title: res.msg,
  347. icon: 'none'
  348. });
  349. }
  350. }).catch(err=>{
  351. uni.hideLoading();
  352. uni.showToast({
  353. icon:'none',
  354. title: "登录失败,请重新登录",
  355. });
  356. });
  357. }
  358. });
  359. }
  360. })
  361. }).catch(err => {})
  362. },
  363. getByAppId(){
  364. getByAppId(getApp().globalData.appId).then(res=>{
  365. if(res.code == 200) {
  366. this.authType = res.config.authType || 1
  367. if(this.authType == 1) {
  368. this.code = ''
  369. this.goWXLogin()
  370. } else if(this.authType==2) {
  371. this.loginFsUserWx()
  372. }
  373. } else {
  374. uni.showToast({
  375. title: res.msg,
  376. icon: 'error'
  377. })
  378. }
  379. }).catch((err)=>{
  380. uni.showToast({
  381. title: JSON.stringify(err),
  382. icon: 'error'
  383. })
  384. })
  385. },
  386. async loginFsUserWx(data) {
  387. if(data){
  388. console.log('huoqu1222',data)
  389. uni.showLoading({
  390. title: '登录中'
  391. })
  392. uni.login({
  393. provider: "weixin",
  394. success: async loginRes => {
  395. console.log(loginRes)
  396. let code = loginRes.code // 获取开发code
  397. handleFsUserWx({
  398. code: code,
  399. appId:getApp().globalData.appId,
  400. userId:data.userId
  401. })
  402. .then( res => {
  403. uni.hideLoading();
  404. if(res.code==200){
  405. this.code = ''
  406. console.log("loginFsUserWx:",res)
  407. let token = uni.getStorageSync('TOKEN_WEXIN');
  408. let user = uni.getStorageSync('web_userInfo')
  409. this.$store.commit('setCoureLogin', 1);
  410. uni.setStorageSync('AppTokenmini_RTCourse', token);
  411. uni.setStorageSync('auto_userInfo', JSON.stringify(user));
  412. this.userId = user.userId || ''
  413. this.isLogin = true
  414. this.getMenuButton()
  415. this.getList()
  416. }else{
  417. uni.showToast({
  418. icon:'none',
  419. title: res.msg,
  420. });
  421. }
  422. })
  423. },
  424. })
  425. }else{
  426. await this.$store.dispatch('getWebviewUrl');
  427. uni.navigateTo({
  428. url:'/pages_course/webview?H5course='+uni.getStorageSync('H5course')
  429. })
  430. }
  431. }
  432. }
  433. };
  434. </script>
  435. <style scoped lang="scss">
  436. .container {
  437. background-color: #fff;
  438. }
  439. .formbox-title {
  440. padding-bottom: 30rpx;
  441. border-bottom: 1px solid #f4f4f4;
  442. }
  443. .formbox {
  444. border-top: 1px solid #f4f4f4;
  445. padding: 30rpx;
  446. }
  447. .box {
  448. padding-bottom: 24rpx;
  449. border-top: 1px solid #f4f4f4;
  450. .imgitem {
  451. padding-top: 20rpx;
  452. }
  453. }
  454. .footer-btn {
  455. margin-top: 50rpx;
  456. }
  457. .submit-btn {
  458. width: 50%;
  459. height: 88rpx;
  460. line-height: 88rpx;
  461. text-align: center;
  462. font-size: 30rpx;
  463. font-family: PingFang SC;
  464. color: #FFFFFF;
  465. background: rgb(0,178,106);
  466. border-radius: 16rpx;
  467. border: 1rpx solid ;
  468. margin-bottom: 30rpx;
  469. &::after {
  470. border: none;
  471. }
  472. }
  473. .back-btn {
  474. color: #bbb;
  475. background: transparent;
  476. border-radius: 16rpx;
  477. border: 1rpx solid #999;
  478. }
  479. .header-nav {
  480. height: 88rpx;
  481. display: flex;
  482. align-items: center;
  483. justify-content: center;
  484. overflow: hidden;
  485. background-color: #fff;
  486. box-sizing: border-box;
  487. width: 100%;
  488. position: fixed;
  489. top: 0;
  490. left: 0;
  491. .header-title {
  492. flex: 1;
  493. text-align: center;
  494. overflow: hidden;
  495. white-space: nowrap;
  496. text-overflow: ellipsis;
  497. font-family: PingFang SC,PingFang SC;
  498. font-weight: 500;
  499. font-size: 15px;
  500. color: #000;
  501. box-sizing: border-box;
  502. }
  503. }
  504. .arrow-left {
  505. position: absolute;
  506. left: 24rpx;
  507. height: 88rpx;
  508. display: flex;
  509. align-items: center;
  510. justify-content: center;
  511. overflow: hidden;
  512. }
  513. .list-item {
  514. background-color: #fff;
  515. padding: 24rpx;
  516. border-bottom: 1rpx solid #f4f4f4;
  517. font-size: 15px;
  518. color: #333;
  519. }
  520. .title {
  521. background-color: #f4f4f4;
  522. }
  523. </style>