feedback.vue 13 KB

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