feedback.vue 12 KB

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