feedback.vue 13 KB

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