complaint.vue 13 KB

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