feedback.vue 13 KB

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