feedback.vue 11 KB

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