feedback.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <view class="container">
  3. <picker @change="bindPickerChange" :value="index" :range="array">
  4. <view class="picker">
  5. <view class="fb-type">
  6. <view class="type-label">{{ array[index] }}</view>
  7. <!-- <van-icon class="type-icon" name="arrow-down" /> -->
  8. </view>
  9. </view>
  10. </picker>
  11. <view class="fb-body">
  12. <textarea
  13. class="content"
  14. placeholder="对我们网站、商品、服务,你还有什么建议吗?你还希望在商城上买到什么?请告诉我们..."
  15. @input="contentInput"
  16. maxlength="500"
  17. :auto-focus="true"
  18. :value="content"
  19. />
  20. <view class="weui-uploader__files" id="uploaderFiles">
  21. <block v-for="(item, index) in files" :key="index">
  22. <view class="weui-uploader__file" @tap="previewImage" :id="item">
  23. <image class="weui-uploader__img" :src="item" mode="aspectFill" />
  24. </view>
  25. </block>
  26. <view class="weui-uploader__input-box" v-if="files.length < 5">
  27. <view class="weui-uploader__input" @tap="chooseImage"></view>
  28. </view>
  29. </view>
  30. <view class="text-count">{{ contentLength }}/500</view>
  31. </view>
  32. <view class="fb-mobile">
  33. <view class="label">手机号码</view>
  34. <view class="mobile-box">
  35. <input class="mobile" maxlength="11" type="number" placeholder="方便我们与你联系" @input="mobileInput" :value="mobile" />
  36. <!-- <van-icon class="clear-icon" name="close" v-if="mobile.length > 0" @tap.native.stop.prevent="clearMobile" /> -->
  37. </view>
  38. </view>
  39. <view class="fb-btn" @tap="submitFeedback">提交</view>
  40. </view>
  41. </template>
  42. <script>
  43. var util = require('../../../utils/util.js');
  44. var check = require('../../../utils/check.js');
  45. var api = require('../../../config/api.js');
  46. var app = getApp();
  47. export default {
  48. data() {
  49. return {
  50. array: ['请选择反馈类型', '商品相关', '功能异常', '优化建议', '其他'],
  51. index: 0,
  52. content: '',
  53. contentLength: 0,
  54. mobile: '',
  55. hasPicture: false,
  56. picUrls: [],
  57. files: []
  58. };
  59. },
  60. onLoad: function (options) {},
  61. onReady: function () {},
  62. onShow: function () {},
  63. onHide: function () {
  64. // 页面隐藏
  65. },
  66. onUnload: function () {
  67. // 页面关闭
  68. },
  69. methods: {
  70. chooseImage: function (e) {
  71. if (this.files.length >= 5) {
  72. util.showErrorToast('只能上传五张图片');
  73. return false;
  74. }
  75. var that = this;
  76. uni.chooseImage({
  77. count: 1,
  78. sizeType: ['original', 'compressed'],
  79. sourceType: ['album', 'camera'],
  80. success: function (res) {
  81. that.setData({
  82. files: that.files.concat(res.tempFilePaths)
  83. });
  84. that.upload(res);
  85. }
  86. });
  87. },
  88. upload: function (res) {
  89. var that = this;
  90. const uploadTask = uni.uploadFile({
  91. url: api.StorageUpload,
  92. filePath: res.tempFilePaths[0],
  93. name: 'file',
  94. success: function (res) {
  95. var _res = JSON.parse(res.data);
  96. if (_res.errno === 0) {
  97. var url = _res.data.url;
  98. that.picUrls.push(url);
  99. that.setData({
  100. hasPicture: true,
  101. picUrls: that.picUrls
  102. });
  103. }
  104. },
  105. fail: function (e) {
  106. uni.showModal({
  107. title: '错误',
  108. content: '上传失败',
  109. showCancel: false
  110. });
  111. }
  112. });
  113. uploadTask.onProgressUpdate((res) => {
  114. console.log('上传进度', res.progress);
  115. console.log('已经上传的数据长度', res.totalBytesSent);
  116. console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend);
  117. });
  118. },
  119. previewImage: function (e) {
  120. uni.previewImage({
  121. current: e.currentTarget.id,
  122. // 当前显示图片的http链接
  123. urls: this.files // 需要预览的图片http链接列表
  124. });
  125. },
  126. bindPickerChange: function (e) {
  127. this.setData({
  128. index: e.detail.value
  129. });
  130. },
  131. mobileInput: function (e) {
  132. this.setData({
  133. mobile: e.detail.value
  134. });
  135. },
  136. contentInput: function (e) {
  137. this.setData({
  138. contentLength: e.detail.cursor,
  139. content: e.detail.value
  140. });
  141. },
  142. clearMobile: function (e) {
  143. this.setData({
  144. mobile: ''
  145. });
  146. },
  147. submitFeedback: function (e) {
  148. if (!app.globalData.hasLogin) {
  149. uni.navigateTo({
  150. url: '/pages/auth/login/login'
  151. });
  152. }
  153. let that = this;
  154. if (that.index == 0) {
  155. util.showErrorToast('请选择反馈类型');
  156. return false;
  157. }
  158. if (that.content == '') {
  159. util.showErrorToast('请输入反馈内容');
  160. return false;
  161. }
  162. if (that.mobile == '') {
  163. util.showErrorToast('请输入手机号码');
  164. return false;
  165. }
  166. if (!check.isValidPhone(this.mobile)) {
  167. this.setData({
  168. mobile: ''
  169. });
  170. util.showErrorToast('请输入手机号码');
  171. return false;
  172. }
  173. uni.showLoading({
  174. title: '提交中...',
  175. mask: true,
  176. success: function () {}
  177. });
  178. util.request(
  179. api.FeedbackAdd,
  180. {
  181. mobile: that.mobile,
  182. feedType: that.array[that.index],
  183. content: that.content,
  184. hasPicture: that.hasPicture,
  185. picUrls: that.picUrls
  186. },
  187. 'POST'
  188. ).then(function (res) {
  189. uni.hideLoading();
  190. if (res.errno === 0) {
  191. uni.showToast({
  192. title: '感谢您的反馈!',
  193. icon: 'success',
  194. duration: 2000,
  195. complete: function () {
  196. that.setData({
  197. index: 0,
  198. content: '',
  199. contentLength: 0,
  200. mobile: '',
  201. hasPicture: false,
  202. picUrls: [],
  203. files: []
  204. });
  205. }
  206. });
  207. } else {
  208. util.showErrorToast(res.errmsg);
  209. }
  210. });
  211. }
  212. }
  213. };
  214. </script>
  215. <style>
  216. page {
  217. background: #f4f4f4;
  218. min-height: 100%;
  219. }
  220. .container {
  221. background: #f4f4f4;
  222. min-height: 100%;
  223. padding-top: 30rpx;
  224. }
  225. .fb-type {
  226. height: 104rpx;
  227. width: 100%;
  228. background: #fff;
  229. margin-bottom: 20rpx;
  230. display: flex;
  231. flex-direction: row;
  232. align-items: center;
  233. padding-left: 30rpx;
  234. padding-right: 30rpx;
  235. }
  236. .fb-type .type-label {
  237. height: 36rpx;
  238. flex: 1;
  239. color: #333;
  240. font-size: 28rpx;
  241. }
  242. .fb-type .type-icon {
  243. height: 36rpx;
  244. width: 36rpx;
  245. }
  246. .fb-body {
  247. width: 100%;
  248. background: #fff;
  249. height: 600rpx;
  250. padding: 18rpx 30rpx 64rpx 30rpx;
  251. }
  252. .fb-body .content {
  253. width: 100%;
  254. height: 400rpx;
  255. color: #333;
  256. line-height: 40rpx;
  257. font-size: 28rpx;
  258. }
  259. .weui-uploader__files {
  260. width: 100%;
  261. }
  262. .weui-uploader__file {
  263. float: left;
  264. margin-right: 9px;
  265. margin-bottom: 9px;
  266. }
  267. .weui-uploader__img {
  268. display: block;
  269. width: 50px;
  270. height: 50px;
  271. }
  272. .weui-uploader__input-box {
  273. float: left;
  274. position: relative;
  275. margin-right: 9px;
  276. margin-bottom: 9px;
  277. width: 50px;
  278. height: 50px;
  279. border: 1px solid #d9d9d9;
  280. }
  281. .weui-uploader__input-box:after,
  282. .weui-uploader__input-box:before {
  283. content: ' ';
  284. position: absolute;
  285. top: 50%;
  286. left: 50%;
  287. -webkit-transform: translate(-50%, -50%);
  288. transform: translate(-50%, -50%);
  289. background-color: #d9d9d9;
  290. }
  291. .weui-uploader__input-box:before {
  292. width: 2px;
  293. height: 39.5px;
  294. }
  295. .weui-uploader__input-box:after {
  296. width: 39.5px;
  297. height: 2px;
  298. }
  299. .weui-uploader__input-box:active {
  300. border-color: #999;
  301. }
  302. .weui-uploader__input-box:active:after,
  303. .weui-uploader__input-box:active:before {
  304. background-color: #999;
  305. }
  306. .weui-uploader__input {
  307. position: absolute;
  308. z-index: 1;
  309. top: 0;
  310. left: 0;
  311. width: 100%;
  312. height: 100%;
  313. opacity: 0;
  314. }
  315. .fb-body .text-count {
  316. line-height: 30rpx;
  317. float: right;
  318. color: #666;
  319. font-size: 24rpx;
  320. }
  321. .fb-mobile {
  322. height: 162rpx;
  323. width: 100%;
  324. }
  325. .fb-mobile .label {
  326. height: 58rpx;
  327. width: 100%;
  328. padding-top: 14rpx;
  329. padding-bottom: 11rpx;
  330. color: #7f7f7f;
  331. font-size: 24rpx;
  332. padding-left: 30rpx;
  333. padding-right: 30rpx;
  334. line-height: 33rpx;
  335. }
  336. .fb-mobile .mobile-box {
  337. height: 104rpx;
  338. width: 100%;
  339. color: #333;
  340. padding-left: 30rpx;
  341. padding-right: 30rpx;
  342. font-size: 24rpx;
  343. background: #fff;
  344. position: relative;
  345. }
  346. .fb-mobile .mobile {
  347. position: absolute;
  348. top: 27rpx;
  349. left: 30rpx;
  350. height: 50rpx;
  351. width: 100%;
  352. color: #333;
  353. line-height: 50rpx;
  354. font-size: 24rpx;
  355. }
  356. .fb-mobile .clear-icon {
  357. position: absolute;
  358. top: 27rpx;
  359. right: 30rpx;
  360. width: 48rpx;
  361. height: 48rpx;
  362. z-index: 2;
  363. }
  364. .fb-btn {
  365. right: 0;
  366. display: flex;
  367. justify-content: center;
  368. align-items: center;
  369. width: 90%;
  370. height: 90rpx;
  371. line-height: 98rpx;
  372. position: absolute;
  373. bottom: 25rpx;
  374. left: 0;
  375. border-radius: 0;
  376. padding: 0;
  377. margin: 0;
  378. margin-left: 5%;
  379. text-align: center;
  380. /* padding-left: -5rpx; */
  381. font-size: 25rpx;
  382. color: #f4f4f4;
  383. border-top-left-radius: 50rpx;
  384. border-bottom-left-radius: 50rpx;
  385. border-top-right-radius: 50rpx;
  386. border-bottom-right-radius: 50rpx;
  387. letter-spacing: 3rpx;
  388. background-image: linear-gradient(to right, #242a48 0%, #242a48 100%);
  389. }
  390. </style>