complaint.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view>
  3. <view class="mt60 p34">
  4. <view class="color#{$5} ">投诉对象</view>
  5. <view class="align-center mt30 mb50">
  6. <image class="w98 h98 mr30" style="border-radius: 50%;" src="/static/logo.png"></image>
  7. <text>百域承品</text>
  8. </view>
  9. </view>
  10. <view class="container" >
  11. <view class="formbox">
  12. <view class="formbox-title">{{ text }}</view>
  13. <view class="form">
  14. <u-form labelPosition="top" labelWidth='auto' :model="formdata" :rules="rules" ref="uForm"
  15. errorType="toast">
  16. <u-form-item label=" " prop="complaintContent">
  17. <u--textarea v-model="formdata.complaintContent" border="none" :clearable="true"
  18. placeholder="请填写反馈内容" count maxlength='200'></u--textarea>
  19. </u-form-item>
  20. <view class="box">
  21. <u-form-item label="图片(最多9张)">
  22. <view class="imgitem">
  23. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1"
  24. :maxCount="9"></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. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. mapGetters
  40. } from 'vuex';
  41. export default {
  42. data() {
  43. return {
  44. menuButtonH: 45,
  45. pageIndex: 0,
  46. list: [],
  47. feedbackItems: [],
  48. userId: '',
  49. // courseId: '',
  50. // videoId: '',
  51. formdata: {
  52. complaintContent: ""
  53. },
  54. rules: {
  55. complaintContent: [{
  56. required: true,
  57. message: '投诉反馈内容不能为空',
  58. trigger: ["change", "blur"]
  59. }]
  60. },
  61. text: '',
  62. templateId: 0,
  63. user: {},
  64. isLastChild: 0,
  65. isLogin: false,
  66. fileList1: [],
  67. code: ''
  68. };
  69. },
  70. // computed: {
  71. // ...mapGetters(['coureLogin']),
  72. // },
  73. // watch: {
  74. // coureLogin: {
  75. // immediate: true, // 页面一进入就检查一次
  76. // handler(val) {
  77. // if (val == 2) {
  78. // console.log("AppToken失效,请重新登录")
  79. // this.isLogin = false
  80. // this.goLogin()
  81. // }
  82. // }
  83. // }
  84. // },
  85. onLoad(option) {
  86. this.text=option.selectText
  87. // this.userId = option.userId || ''
  88. // this.courseId = option.courseId || ''
  89. // this.videoId = option.videoId || ''
  90. // this.projectCode = option.projectCode || ''
  91. // uni.$on('usercode', (data) => {
  92. // if (data) {
  93. // this.code = data.code
  94. // this.goLogin(data)
  95. // }
  96. // })
  97. // this.utils.getDomain({projectCode:this.projectCode}).then(res=>{
  98. // if(res.code == 200) {
  99. // uni.setStorageSync('addressUrl',res.addressUrl)
  100. // this.utils.isLoginCourseAuto().then(
  101. // res => {
  102. // if(res){
  103. // this.isLogin = true
  104. // this.getMenuButton()
  105. // this.getList()
  106. // } else{
  107. // this.isLogin = false
  108. // this.goLogin()
  109. // }
  110. // },
  111. // rej => {}
  112. // );
  113. // }
  114. // })
  115. },
  116. onUnload() {
  117. uni.$off('usercode')
  118. },
  119. methods: {
  120. getMenuButton() {
  121. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  122. this.menuButtonH = menuButtonInfo.height
  123. },
  124. goBack() {
  125. // 返回上一层逻辑
  126. if (this.pageIndex == 0) {
  127. uni.navigateBack();
  128. } else {
  129. this.pageIndex--;
  130. this.formdata = {
  131. complaintContent: ""
  132. }
  133. if (this.isLastChild == 1) {
  134. this.isLastChild = 0
  135. } else {
  136. if (this.pageIndex == 0) {
  137. this.feedbackItems = this.list
  138. this.templateId = 0
  139. } else {
  140. const list = this.findGrandparentOrAllData(this.list, this.templateId)
  141. this.feedbackItems = list.childrenType
  142. this.templateId = list.complaintTypeId
  143. }
  144. }
  145. }
  146. },
  147. findGrandparentOrAllData(data, targetId) {
  148. // 递归函数,用于查找目标节点的父级节点
  149. function findParent(node, targetId) {
  150. if (!node || !node.childrenType) return null;
  151. for (let child of node.childrenType) {
  152. if (child.complaintTypeId === targetId) {
  153. return node; // 找到目标节点的父级节点
  154. }
  155. const result = findParent(child, targetId); // 递归查找子节点
  156. if (result) return result;
  157. }
  158. return null;
  159. }
  160. // 遍历顶层节点,查找目标节点的父级和祖父级节点
  161. for (let root of data) {
  162. if (root.complaintTypeId === targetId) {
  163. return data; // 如果目标节点是顶层节点,返回所有数据
  164. }
  165. const parent = findParent(root, targetId); // 查找目标节点的父级节点
  166. if (parent) {
  167. const grandparent = findParent(root, parent.complaintTypeId); // 查找父级节点的父级节点
  168. return grandparent || data; // 如果找到祖父节点返回祖父节点,否则返回所有数据
  169. }
  170. }
  171. return data; // 如果没有找到目标节点,返回所有数据
  172. },
  173. // handleClick(item, index) {
  174. // if (this.isLastChild == 1) return
  175. // if (this.pageIndex >= 0) {
  176. // this.pageIndex++
  177. // let children = this.feedbackItems[index].childrenType || [];
  178. // this.templateId = this.feedbackItems[index].complaintTypeId
  179. // this.formdata = {
  180. // complaintContent: ""
  181. // }
  182. // this.text = this.feedbackItems[index].complaintTypeName
  183. // if (children.length > 0) {
  184. // this.isLastChild = 0
  185. // this.feedbackItems = children
  186. // this.templateId = this.feedbackItems[0].complaintTypeId
  187. // } else {
  188. // this.isLastChild = 1
  189. // this.formdata = {
  190. // complaintContent: ""
  191. // }
  192. // setTimeout(() => {
  193. // this.$refs.uForm.setRules(this.rules)
  194. // }, 200)
  195. // }
  196. // }
  197. // },
  198. // getList() {
  199. // getTypeTree().then(res => {
  200. // if (res.code == 200) {
  201. // this.list = res.data
  202. // this.pageIndex = 0
  203. // this.feedbackItems = this.list
  204. // }
  205. // })
  206. // },
  207. submit() {
  208. if (this.fileList1.some(item => item.status == 'uploading')) {
  209. uni.showToast({
  210. title: '等待图片上传中',
  211. icon: 'none'
  212. })
  213. return
  214. }
  215. var images = [];
  216. this.fileList1.forEach(function(element) {
  217. images.push(element.url)
  218. });
  219. this.$refs.uForm.validate().then(res => {
  220. if (res) {
  221. uni.showModal({
  222. title: '',
  223. content: '我们已收到您的反馈,谢谢',
  224. showCancel: false,
  225. success: function(res) {
  226. if (res.confirm) {
  227. uni.navigateBack()
  228. } else if (res.cancel) {
  229. uni.navigateBack()
  230. }
  231. }
  232. });
  233. }
  234. })
  235. },
  236. deletePic(event) {
  237. this[`fileList${event.name}`].splice(event.index, 1)
  238. },
  239. async afterRead(event) {
  240. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  241. let lists = [].concat(event.file)
  242. let fileListLen = this[`fileList${event.name}`].length
  243. lists.map((item) => {
  244. this[`fileList${event.name}`].push({
  245. ...item,
  246. status: 'uploading',
  247. message: '上传中'
  248. })
  249. })
  250. for (let i = 0; i < lists.length; i++) {
  251. const result = await this.uploadFilePromise(lists[i].url)
  252. let item = this[`fileList${event.name}`][fileListLen]
  253. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  254. status: 'success',
  255. message: '',
  256. url: result
  257. }))
  258. fileListLen++
  259. }
  260. },
  261. uploadFilePromise(url) {
  262. const projectCode = uni.getStorageSync('projectCode')
  263. // 添加日志检查关键参数
  264. // console.log('上传参数检查:', {
  265. // projectCode: projectCode,
  266. // addressUrl: uni.getStorageSync('addressUrl_' + projectCode),
  267. // url: url
  268. // })
  269. return new Promise((resolve, reject) => {
  270. let a = uni.uploadFile({
  271. url: uni.getStorageSync('requestPath')+ '/app/common/uploadOSS',
  272. filePath: url,
  273. name: 'file',
  274. formData: {
  275. // 可以添加其他必要参数
  276. 'user': 'test' // 上传附带参数
  277. },
  278. success: (res) => {
  279. console.log('上传成功响应:', res)
  280. if (res.statusCode === 200) {
  281. try {
  282. const data = JSON.parse(res.data)
  283. if (data.code === 200) {
  284. resolve(data.url)
  285. } else {
  286. reject(new Error(data.msg || '上传失败'))
  287. }
  288. } catch (e) {
  289. reject(new Error('解析响应数据失败'))
  290. }
  291. } else {
  292. reject(new Error(`HTTP错误: ${res.statusCode}`))
  293. }
  294. },
  295. fail: (err) => {
  296. console.error('上传失败:', err)
  297. reject(err)
  298. }
  299. });
  300. })
  301. },
  302. }
  303. };
  304. </script>
  305. <style scoped lang="scss">
  306. .container {
  307. background-color: #fff;
  308. }
  309. .formbox-title {
  310. padding-bottom: 30rpx;
  311. border-bottom: 1px solid #f4f4f4;
  312. }
  313. .formbox {
  314. border-top: 1px solid #f4f4f4;
  315. padding: 30rpx;
  316. }
  317. .box {
  318. padding-bottom: 24rpx;
  319. border-top: 1px solid #f4f4f4;
  320. .imgitem {
  321. padding-top: 20rpx;
  322. }
  323. }
  324. .footer-btn {
  325. margin-top: 50rpx;
  326. }
  327. .submit-btn {
  328. width: 50%;
  329. height: 88rpx;
  330. line-height: 88rpx;
  331. text-align: center;
  332. font-size: 30rpx;
  333. font-family: PingFang SC;
  334. color: #FFFFFF;
  335. background: rgb(0, 178, 106);
  336. border-radius: 16rpx;
  337. border: 1rpx solid;
  338. margin-bottom: 30rpx;
  339. &::after {
  340. border: none;
  341. }
  342. }
  343. .back-btn {
  344. color: #bbb;
  345. background: transparent;
  346. border-radius: 16rpx;
  347. border: 1rpx solid #999;
  348. }
  349. .header-nav {
  350. height: 88rpx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. overflow: hidden;
  355. background-color: #fff;
  356. box-sizing: border-box;
  357. width: 100%;
  358. position: fixed;
  359. top: 0;
  360. left: 0;
  361. .header-title {
  362. flex: 1;
  363. text-align: center;
  364. overflow: hidden;
  365. white-space: nowrap;
  366. text-overflow: ellipsis;
  367. font-family: PingFang SC, PingFang SC;
  368. font-weight: 500;
  369. font-size: 15px;
  370. color: #000;
  371. box-sizing: border-box;
  372. }
  373. }
  374. .arrow-left {
  375. position: absolute;
  376. left: 24rpx;
  377. height: 88rpx;
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. overflow: hidden;
  382. }
  383. .list-item {
  384. background-color: #fff;
  385. padding: 24rpx;
  386. border-bottom: 1rpx solid #f4f4f4;
  387. font-size: 15px;
  388. color: #333;
  389. }
  390. .title {
  391. background-color: #f4f4f4;
  392. }
  393. </style>