complaintList.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view>
  3. <view class="title">请选择投诉原因</view>
  4. <view class="list">
  5. <view class="item">
  6. <view>{{item}}</view>
  7. <image class="w30 h30" src="/static/images/arrow_gray.png"></image>
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import { mapGetters } from 'vuex';
  14. // complaintRecord
  15. import{ getTypeTree,loginByMp } from "@/api/course.js"
  16. export default {
  17. data() {
  18. return {
  19. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  20. menuButtonH: 45,
  21. pageIndex: 0,
  22. list: [],
  23. feedbackItems: [],
  24. userId: '',
  25. // courseId: '',
  26. // videoId: '',
  27. formdata: {
  28. complaintContent: ""
  29. },
  30. rules: {
  31. complaintContent:[{
  32. required: true,
  33. message: '投诉反馈内容不能为空',
  34. trigger: ["change", "blur"]
  35. }]
  36. },
  37. text: '',
  38. templateId: 0,
  39. user: {},
  40. isLastChild: 0,
  41. isLogin: false,
  42. fileList1: [],
  43. // projectCode:'',
  44. code:''
  45. };
  46. },
  47. computed: {
  48. ...mapGetters(['coureLogin']),
  49. },
  50. watch: {
  51. coureLogin: {
  52. immediate: true, // 页面一进入就检查一次
  53. handler(val) {
  54. if (val == 2) {
  55. console.log("AppToken失效,请重新登录")
  56. this.isLogin = false
  57. this.goLogin()
  58. }
  59. }
  60. }
  61. },
  62. onLoad(option) {
  63. this.userId = option.userId || ''
  64. // this.courseId = option.courseId || ''
  65. // this.videoId = option.videoId || ''
  66. // this.projectCode = option.projectCode || ''
  67. uni.$on('usercode',(data)=>{
  68. if(data) {
  69. this.code=data.code
  70. this.goLogin(data)
  71. }
  72. })
  73. // this.utils.getDomain({projectCode:this.projectCode}).then(res=>{
  74. // if(res.code == 200) {
  75. // uni.setStorageSync('addressUrl',res.addressUrl)
  76. // this.utils.isLoginCourseAuto().then(
  77. // res => {
  78. // if(res){
  79. // this.isLogin = true
  80. // this.getMenuButton()
  81. // this.getList()
  82. // } else{
  83. // this.isLogin = false
  84. // this.goLogin()
  85. // }
  86. // },
  87. // rej => {}
  88. // );
  89. // }
  90. // })
  91. },
  92. onUnload() {
  93. uni.$off('usercode')
  94. },
  95. methods: {
  96. getMenuButton(){
  97. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  98. this.menuButtonH = menuButtonInfo.height
  99. },
  100. goBack() {
  101. // 返回上一层逻辑
  102. if (this.pageIndex == 0) {
  103. uni.navigateBack();
  104. } else {
  105. this.pageIndex--;
  106. this.formdata = {
  107. complaintContent: ""
  108. }
  109. if (this.isLastChild == 1) {
  110. this.isLastChild = 0
  111. } else {
  112. if (this.pageIndex == 0) {
  113. this.feedbackItems = this.list
  114. this.templateId = 0
  115. } else {
  116. const list = this.findGrandparentOrAllData(this.list, this.templateId)
  117. this.feedbackItems = list.childrenType
  118. this.templateId = list.complaintTypeId
  119. }
  120. }
  121. }
  122. },
  123. findGrandparentOrAllData(data, targetId) {
  124. // 递归函数,用于查找目标节点的父级节点
  125. function findParent(node, targetId) {
  126. if (!node || !node.childrenType) return null;
  127. for (let child of node.childrenType) {
  128. if (child.complaintTypeId === targetId) {
  129. return node; // 找到目标节点的父级节点
  130. }
  131. const result = findParent(child, targetId); // 递归查找子节点
  132. if (result) return result;
  133. }
  134. return null;
  135. }
  136. // 遍历顶层节点,查找目标节点的父级和祖父级节点
  137. for (let root of data) {
  138. if (root.complaintTypeId === targetId) {
  139. return data; // 如果目标节点是顶层节点,返回所有数据
  140. }
  141. const parent = findParent(root, targetId); // 查找目标节点的父级节点
  142. if (parent) {
  143. const grandparent = findParent(root, parent.complaintTypeId); // 查找父级节点的父级节点
  144. return grandparent || data; // 如果找到祖父节点返回祖父节点,否则返回所有数据
  145. }
  146. }
  147. return data; // 如果没有找到目标节点,返回所有数据
  148. },
  149. handleClick(item,index) {
  150. if (this.isLastChild == 1) return
  151. if (this.pageIndex >= 0) {
  152. this.pageIndex++
  153. let children = this.feedbackItems[index].childrenType || [];
  154. this.templateId = this.feedbackItems[index].complaintTypeId
  155. this.formdata = {
  156. complaintContent: ""
  157. }
  158. this.text = this.feedbackItems[index].complaintTypeName
  159. if (children.length > 0) {
  160. this.isLastChild = 0
  161. this.feedbackItems = children
  162. this.templateId = this.feedbackItems[0].complaintTypeId
  163. } else {
  164. this.isLastChild = 1
  165. this.formdata = {
  166. complaintContent: ""
  167. }
  168. setTimeout(() => {
  169. this.$refs.uForm.setRules(this.rules)
  170. }, 200)
  171. }
  172. }
  173. },
  174. getList(){
  175. getTypeTree().then(res=>{
  176. if(res.code == 200) {
  177. this.list = res.data
  178. this.pageIndex = 0
  179. this.feedbackItems = this.list
  180. }
  181. })
  182. },
  183. submit() {
  184. if(this.fileList1.some(item=>item.status == 'uploading')) {
  185. uni.showToast({
  186. title: '等待图片上传中',
  187. icon: 'none'
  188. })
  189. return
  190. }
  191. var images=[];
  192. this.fileList1.forEach(function(element) {
  193. images.push(element.url)
  194. });
  195. this.$refs.uForm.validate().then(res => {
  196. if (res) {
  197. uni.showModal({
  198. title: '',
  199. content: '我们已收到您的反馈,谢谢',
  200. showCancel: false,
  201. success: function (res) {
  202. if (res.confirm) {
  203. uni.navigateBack()
  204. } else if (res.cancel) {
  205. uni.navigateBack()
  206. }
  207. }
  208. });
  209. }
  210. })
  211. },
  212. deletePic(event) {
  213. this[`fileList${event.name}`].splice(event.index, 1)
  214. },
  215. async afterRead(event) {
  216. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  217. let lists = [].concat(event.file)
  218. let fileListLen = this[`fileList${event.name}`].length
  219. lists.map((item) => {
  220. this[`fileList${event.name}`].push({
  221. ...item,
  222. status: 'uploading',
  223. message: '上传中'
  224. })
  225. })
  226. for (let i = 0; i < lists.length; i++) {
  227. const result = await this.uploadFilePromise(lists[i].url)
  228. let item = this[`fileList${event.name}`][fileListLen]
  229. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  230. status: 'success',
  231. message: '',
  232. url: result
  233. }))
  234. fileListLen++
  235. }
  236. },
  237. uploadFilePromise(url) {
  238. const projectCode = uni.getStorageSync('projectCode')
  239. return new Promise((resolve, reject) => {
  240. let a = uni.uploadFile({
  241. url: uni.getStorageSync('addressUrl_'+projectCode)+ '/app/common/uploadOSS', // 仅为示例,非真实的接口地址
  242. filePath: url,
  243. name: 'file',
  244. success: (res) => {
  245. setTimeout(() => {
  246. console.log(JSON.parse(res.data).url)
  247. resolve(JSON.parse(res.data).url)
  248. }, 1000)
  249. }
  250. });
  251. })
  252. },
  253. goLogin(data) {
  254. if(!this.projectCode){
  255. uni.showToast({
  256. title: '链接有误',
  257. icon: 'none'
  258. });
  259. return
  260. }
  261. this.loginFsUserWx(data)
  262. return
  263. this.utils.getProvider().then(provider=>{
  264. console.log('当前的环境商',provider)
  265. if (!provider) {
  266. reject()
  267. }
  268. uni.login({
  269. provider: provider,
  270. success: async loginRes => {
  271. console.log(loginRes)
  272. uni.getUserInfo({
  273. provider: provider,
  274. success: (infoRes)=> {
  275. uni.showToast({
  276. title: '处理中...',
  277. icon: 'loading'
  278. });
  279. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId:getApp().globalData.appId}).then(res=>{
  280. uni.hideLoading();
  281. if (res.code == 200) {
  282. this.$store.commit('setCoureLogin', 1);
  283. uni.setStorageSync(this.utils.TOKEN_KEYAuto, res.token);
  284. uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  285. this.userId = res.user.userId || ''
  286. this.isLogin = true
  287. this.getMenuButton()
  288. this.getList()
  289. } else {
  290. uni.showToast({
  291. title: res.msg,
  292. icon: 'none'
  293. });
  294. }
  295. }).catch(err=>{
  296. uni.hideLoading();
  297. uni.showToast({
  298. icon:'none',
  299. title: "登录失败,请重新登录",
  300. });
  301. });
  302. }
  303. });
  304. }
  305. })
  306. }).catch(err => {})
  307. },
  308. // H5授权绑定关系
  309. async loginFsUserWx(data){
  310. if(data){
  311. let token = uni.getStorageSync('TOKEN_WEXIN');
  312. let user = uni.getStorageSync('userInfo')
  313. uni.setStorageSync(this.utils.TOKEN_KEYAuto, token);
  314. uni.setStorageSync('auto_userInfo', JSON.stringify(user));
  315. this.userId = user.userId || ''
  316. this.isLogin = true
  317. this.getMenuButton()
  318. this.getList()
  319. }else{
  320. uni.setStorageSync('H5course',{
  321. companyId: this.urlOption.companyId,
  322. companyUserId:this.urlOption.companyUserId,
  323. type: 1, //1自动,其他手动
  324. })
  325. uni.showLoading({ title: '加载中' });
  326. try {
  327. await this.utils.getDomain({ projectCode: this.projectCode}); // code 换成你的业务标识
  328. await this.utils.getConfigKey();
  329. uni.navigateTo({
  330. url:'/pages_course/webview?H5course='+uni.getStorageSync('H5course')
  331. })
  332. } catch (err) {
  333. console.error('初始化失败', err);
  334. uni.showToast({ title: '请求失败', icon: 'none' });
  335. } finally {
  336. uni.hideLoading();
  337. }
  338. }
  339. }
  340. }
  341. };
  342. </script>
  343. <style scoped lang="scss">
  344. .title {
  345. text-align: center;
  346. font-size: 40rpx;
  347. font-weight: 500;
  348. }
  349. .list{
  350. padding: 24rpx;
  351. .item{
  352. display: flex;
  353. justify-content: space-between;
  354. align-items: center;
  355. }
  356. }
  357. </style>