feedback.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <view class="wrap">
  3. <view class="header">
  4. <view :class="['header_item',active === index?'active':'']" @tap="changeActive(item,index)" v-for="item,index in header" :key="index">
  5. <view class="header_title">{{item.title}}</view>
  6. <!-- 下划线 -->
  7. <view class="line"></view>
  8. <!-- 回复数量 -->
  9. <view class="message_num" v-if="item.news === 1">{{replyNumber}}</view>
  10. </view>
  11. </view>
  12. <view class="my_message" v-if="active == 0">
  13. <!-- 输入框 -->
  14. <view class="inp">
  15. <input class="inp_title"v-model="from.title" placeholder="输入您的留言标题" placeholder-class="inp_title_place"></input>
  16. <textarea class="inp_text" v-model="from.content" placeholder="输入您的留言信息" placeholder-class="inp_title_place"></textarea>
  17. <!-- 按钮 -->
  18. <view class="inp_btn clear">
  19. <view class="btn_submit" @tap="submit">提交</view>
  20. <view class="btn_reset" @tap="reset">重置</view>
  21. </view>
  22. </view>
  23. <!-- 留言列表 -->
  24. <view class="message_list">
  25. <view class="message_list_item" v-for="item,index in allData.reedback" :key="index">
  26. <view class="message_list_item_wrap">
  27. <view class="content" :style="item.txtStyle" @touchstart="touchS" @touchmove="touchM" @touchend="touchE" :data-index="index">
  28. <view class="message_list_item_header clear">
  29. <view class="item_header_lf">{{item.title}}</view>
  30. <view class="item_header_rg">{{item.date}}</view>
  31. </view>
  32. <view class="item_content">{{item.content}}</view>
  33. </view>
  34. <!-- 删除按钮 -->
  35. <view class="delete">删除</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="feedback" v-else>
  41. <view class="message_list">
  42. <view class="message_list_item" v-for="item,index in message" :key="index">
  43. <view class="message_list_item_header clear">
  44. <view class="item_header_lf">{{item.tips}}
  45. <view class="logo"><view class="logo_white"></view> </view>
  46. </view>
  47. <view class="item_header_rg">{{item.date}}</view>
  48. </view>
  49. <view class="item_content">{{item.reply}}</view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import api from "../../../../api.js";
  57. import schema from 'async-validator';
  58. let app = getApp();
  59. export default {
  60. data() {
  61. return {
  62. header:[
  63. { id: 1, news:0,title:'我的留言'},
  64. { id: 2, news:1,title:'留言回复'}
  65. ],
  66. active:0, //导航栏点击
  67. replyNumber:'',//留言回复个数
  68. from:{
  69. title:'',//留言标题
  70. content:'',//留言内容
  71. },
  72. allData:null,//页面数据
  73. descriptor:{
  74. title:{
  75. type: "string",
  76. required: true,
  77. message:'请输入留言标题'
  78. },
  79. content: {
  80. type: "string",
  81. required: true,
  82. message:'请输入留言内容'
  83. },
  84. },
  85. delBtnWidth: 87, //删除按钮的宽度单位
  86. startX: '' ,//收支触摸开始滑动的位置
  87. message:[],//回复内容
  88. }
  89. },
  90. onLoad() {
  91. this.getData();
  92. this.getReply();
  93. },
  94. methods: {
  95. //加载数据
  96. getData(){
  97. let data = {
  98. token:app.globalData.token
  99. }
  100. api.getUserFeedBack(data).then((res)=>{
  101. console.log(res);
  102. this.allData = res.data.data;
  103. })
  104. },
  105. //导航栏点击切换
  106. changeActive(item,index){
  107. this.active = index;
  108. },
  109. //重置按钮
  110. reset(){
  111. this.from.title = '';
  112. this.from.content = '';
  113. },
  114. //提交按钮
  115. submit(){
  116. let data = {
  117. token:app.globalData.token,
  118. ...this.from
  119. }
  120. let validator = new schema(this.descriptor);
  121. validator.validate(data).then(() => {
  122. api.submitUserFeenBack(data).then((res)=>{
  123. console.log(res);
  124. if(res.is){
  125. uni.showToast({
  126. title:res.data.msg,
  127. icon:'none',
  128. duration:2000,
  129. })
  130. }else{
  131. uni.showToast({
  132. title:res.data.msg,
  133. icon:'none',
  134. duration:2000,
  135. })
  136. }
  137. })
  138. }).catch(({ errors, fields }) => {
  139. uni.showToast({
  140. icon: 'none',
  141. duration:2000,
  142. title:errors[0].message
  143. })
  144. })
  145. },
  146. //手指触摸开始
  147. touchS:function(e){
  148. if (e.touches.length == 1) {
  149. this.startX = e.touches[0].clientX;
  150. }
  151. },
  152. //手指触摸移动
  153. touchM:function(e){
  154. if (e.touches.length == 1) {
  155. let moveX = e.touches[0].clientX;
  156. let disX = this.startX - moveX; //计算移动的距离
  157. let delBtnWidth = this.delBtnWidth; //删除按钮的宽度
  158. let txtStyle = '';
  159. if (disX === 0 || disX < 0) {//如果移动距离小于等于0,说明向右滑动,文本层位置不变
  160. txtStyle = 'left:0';
  161. } else if (disX > 0) { //移动距离大于0,文本层left值等于手指移动距离
  162. txtStyle = 'left-:' + disX + "px";
  163. if (disX > delBtnWidth){ //删除按钮完全展示出来
  164. txtStyle = "left-" + delBtnWidth + "px"
  165. }
  166. }
  167. //获取手指触摸的是哪一项
  168. let index = e.currentTarget.dataset.index;
  169. //更新列表的状态;
  170. this.$set(this.allData.reedback[index],'txtStyle',txtStyle);
  171. }
  172. },
  173. //手指触摸结束
  174. touchE:function(e){
  175. if (e.changedTouches.length == 1) {
  176. //手指移动结束后水平位置
  177. let endX = e.changedTouches[0].clientX;
  178. //触摸开始与结束,手指移动的距离
  179. let disX = this.startX - endX;
  180. let delBtnWidth = this.delBtnWidth;
  181. //如果距离小于删除按钮的1/2,不显示删除按钮
  182. let txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
  183. //获取手指触摸的是哪一项
  184. let index = e.currentTarget.dataset.index;
  185. //更新列表的状态
  186. this.$set(this.allData.reedback[index],'txtStyle',txtStyle);
  187. }
  188. },
  189. //加载留言反馈内容
  190. getReply(){
  191. let data = {
  192. token:app.globalData.token,
  193. status:2
  194. }
  195. api.getUserFeedReply(data).then((res)=>{
  196. this.message = res.data.data;
  197. this.replyNumber = res.data.data.length;
  198. console.log(this.message)
  199. })
  200. }
  201. }
  202. }
  203. </script>
  204. <style>
  205. page{
  206. width:100%;
  207. height:100%;
  208. background-color: #f9f9f9;
  209. }
  210. .header{
  211. height:86rpx;
  212. line-height: 86rpx;
  213. border-top:1px solid #f2f2f2;
  214. box-sizing: border-box;
  215. display: flex;
  216. background-color: #ffffff;
  217. }
  218. .header_item{
  219. flex:1;
  220. text-align: center;
  221. position: relative;
  222. }
  223. .header_title{
  224. font-size: 30rpx;
  225. color:#222222;
  226. }
  227. .line{
  228. width:38rpx;
  229. height:4rpx;
  230. background:linear-gradient(270deg,rgba(254,107,21,1) 0%,rgba(254,163,48,1) 100%);
  231. position: absolute;
  232. bottom:0rpx;
  233. left:50%;
  234. transform: translateX(-50%);
  235. display: none;
  236. }
  237. .active .header_title{
  238. font-size:34rpx;
  239. font-weight:600;
  240. background:linear-gradient(270deg, rgba(254,107,21,1) 0%, rgba(254,163,48,1) 100%);
  241. -webkit-background-clip:text;
  242. -webkit-text-fill-color:transparent;
  243. }
  244. .active .line{
  245. display: block;
  246. }
  247. .message_num{
  248. width:28rpx;
  249. height:28rpx;
  250. background:rgba(225,21,33,1);
  251. text-align: center;
  252. line-height: 28rpx;
  253. font-size: 18rpx;
  254. color:#ffffff;
  255. border-radius: 50%;
  256. position: absolute;
  257. right:106rpx;
  258. top:10rpx;
  259. }
  260. .clear:after{
  261. content: "";
  262. display: block;
  263. clear: both;
  264. }
  265. .inp{
  266. margin-top:20rpx;
  267. padding:0 30rpx;
  268. box-sizing: border-box;
  269. overflow: hidden;
  270. background-color: #ffffff;
  271. }
  272. .inp_title{
  273. width:100%;
  274. height:88rpx;
  275. background:rgba(249,249,249,1);
  276. border-radius:6rpx;
  277. border:1px solid rgba(202,202,202,1);
  278. margin-top:30rpx;
  279. padding-left: 20rpx;
  280. box-sizing: border-box;
  281. }
  282. .inp_title_place{
  283. font-size: 26rpx;
  284. color:#999999;
  285. }
  286. .inp_text{
  287. width:100%;
  288. height:200rpx;
  289. background:rgba(249,249,249,1);
  290. border-radius:6rpx;
  291. border:1px solid rgba(202,202,202,1);
  292. padding:14rpx 0 0 20rpx;
  293. box-sizing: border-box;
  294. margin-top:20rpx;
  295. position: relative;
  296. }
  297. .inp_text_num{
  298. font-size: 24rpx;
  299. color:#999999;
  300. position: absolute;
  301. right:12rpx;
  302. bottom:10rpx;
  303. }
  304. .inp_btn{
  305. margin-top:30rpx;
  306. margin-bottom: 40rpx;
  307. }
  308. .btn_submit{
  309. width:96rpx;
  310. height:44rpx;
  311. background:linear-gradient(270deg,rgba(254,107,21,1) 0%,rgba(254,163,48,1) 100%);
  312. border-radius:2rpx;
  313. text-align: center;
  314. line-height: 44rpx;
  315. font-size: 22rpx;
  316. color:#ffffff;
  317. float:right;
  318. }
  319. .btn_reset{
  320. width:96rpx;
  321. height:44rpx;
  322. border-radius:2rpx;
  323. border:1px solid rgba(231,120,23,1);
  324. text-align: center;
  325. line-height: 44rpx;
  326. box-sizing: border-box;
  327. font-size: 22rpx;
  328. color:#E77817;
  329. float:right;
  330. margin-right: 20rpx;
  331. }
  332. .message_list{
  333. width:100%;
  334. margin-top:20rpx;
  335. }
  336. .message_list_item{
  337. width:100%;
  338. height:130rpx;
  339. padding:0 30rpx;
  340. box-sizing: border-box;
  341. background-color: #ffffff;
  342. margin-bottom: 20rpx;
  343. overflow: hidden;
  344. }
  345. .message_list_item_wrap{
  346. width:100%;
  347. height:100%;
  348. position: relative;
  349. }
  350. .content{
  351. width:100%;
  352. height:130rpx;
  353. background-color: #ffffff;
  354. overflow: hidden;
  355. position: absolute;
  356. top:0;
  357. left:0;
  358. z-index:10;
  359. transition: left 0.2s ease-in-out;
  360. }
  361. .delete{
  362. width:174rpx;
  363. height:134rpx;
  364. background:rgba(225,21,33,1);
  365. text-align: center;
  366. line-height: 134rpx;
  367. font-size: 30rpx;
  368. color:#ffffff;
  369. position: absolute;
  370. top:0;
  371. right:0;
  372. z-index:5;
  373. }
  374. .message_list_item_header{
  375. margin-top:24rpx;
  376. }
  377. .item_header_lf{
  378. font-size: 30rpx;
  379. color:#222222;
  380. font-weight: bold;
  381. float:left;
  382. }
  383. .item_header_rg{
  384. font-size: 22rpx;
  385. color:#cccccc;
  386. float:right;
  387. margin-top:6rpx;
  388. }
  389. .item_content{
  390. font-size: 24rpx;
  391. color:#999999;
  392. margin-top:10rpx;
  393. margin-bottom:24rpx;
  394. }
  395. </style>