index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="page">
  3. <navBar title="用户反馈" :back="true" color="black" background="white" />
  4. <view class="content">
  5. <view class="title">
  6. 意见反馈
  7. </view>
  8. <u--textarea maxlength="100" :focus="false" v-model="content" :disabled="false" placeholder="请描述您遇到的问题"
  9. count border="none" height="256rpx"></u--textarea>
  10. <view class="picTop">
  11. <view class="title" style="margin-top: 52rpx;margin-bottom: 18px;">
  12. 问题图片
  13. </view>
  14. <view class="count">
  15. <text style="color: #161717;">{{pic_url.length}}</text>/9
  16. </view>
  17. </view>
  18. <!-- 图片上传区域 -->
  19. <!-- 选择要上传的图片区域 -->
  20. <view class="chooscontainer">
  21. <view class="addpicall" v-for="(item,index) in pic_url" :key="index">
  22. <image style="width: 184rpx;height:186rpx;border-radius: 15rpx;" @click="previewImg(item)"
  23. :src="item" mode="aspectFill">
  24. </image>
  25. <view @click="delectImg(index)" class="del_btn">×</view>
  26. </view>
  27. <view class="addpic" @click="addquesPic" v-if="pic_url.length<9">
  28. <view class="addPicBox">
  29. <image :src="picUrl+'/static/my/add.png'"></image>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="title" style="margin-top: 0rpx;">
  34. 联系方式
  35. </view>
  36. <input type="number" class="phone" placeholder="电话" v-model="phone" style="">
  37. </view>
  38. <view class="btn_bottom" @click="post()" v-if="showCBtn">
  39. 确定
  40. </view>
  41. <privacy-popup @confirmP="confirmP" @cancleP="cancleP" :showPrivateBox="showPop"></privacy-popup>
  42. </view>
  43. </template>
  44. <script>
  45. import uploadUrl from '@/common/config.js'
  46. import {
  47. submitFeedbackReq,
  48. } from '@/api/test/index.js'
  49. import PrivacyPopup from "@/components/privacyPopup/index.vue";
  50. export default {
  51. components: {
  52. PrivacyPopup
  53. },
  54. data() {
  55. return {
  56. showPop: false,
  57. showCBtn: false,
  58. picUrl: this.$picUrl,
  59. content: '',
  60. phone: '',
  61. pic_url: [],
  62. }
  63. },
  64. onLoad(options) {},
  65. onShow() {
  66. this.handlePrivate()
  67. },
  68. methods: {
  69. cancleP() {
  70. this.showPop = false
  71. this.showCBtn = true
  72. },
  73. handlePrivate() {
  74. let _this = this
  75. if (getApp().globalData.showPrivacy) {
  76. _this.showPop = true
  77. } else {
  78. _this.showPop = false
  79. this.showCBtn = true
  80. }
  81. },
  82. // 用户同意隐私内容
  83. confirmP() {
  84. this.showPop = false
  85. this.showCBtn = true
  86. this.handleUpImg()
  87. },
  88. async post() {
  89. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  90. if (this.content == '') {
  91. return this.$toast('请输入反馈内容')
  92. }
  93. if (this.phone == '') {
  94. return this.$toast('请输入联系方式')
  95. }
  96. if (!phoneReg.test(this.phone)) {
  97. return this.$toast('请输入合法的手机号')
  98. }
  99. let image = ''
  100. this.pic_url.forEach((item, index) => {
  101. if (index == this.pic_url.length - 1) {
  102. image += item
  103. } else {
  104. image += (item + ',')
  105. }
  106. })
  107. let res = await submitFeedbackReq({
  108. phone: this.phone,
  109. content: this.content,
  110. image
  111. })
  112. if (res.code == 0) {
  113. console.log('反馈返回值', res);
  114. this.$toast('提交成功')
  115. setTimeout(() => {
  116. uni.navigateBack()
  117. }, 1500)
  118. } else {
  119. uni.showToast({
  120. title: res.message,
  121. icon: 'none'
  122. })
  123. }
  124. },
  125. //删除图片
  126. delectImg(i) {
  127. this.pic_url.splice(i, 1)
  128. },
  129. //点击预览图片
  130. previewImg() {
  131. uni.previewImage({
  132. current: this.current,
  133. urls: this.formData.pic_url, //存放图片的数组
  134. loop: true,
  135. indicator: 'default'
  136. })
  137. },
  138. // 新增图片
  139. addquesPic() {
  140. if (getApp().globalData.showPrivacy) {
  141. this.showPop = true
  142. this.showCBtn = false
  143. return
  144. }
  145. this.handleUpImg()
  146. },
  147. handleUpImg() {
  148. let _this = this
  149. let imgList = []
  150. uni.chooseImage({
  151. count: 9 - _this.pic_url.length, //默认9
  152. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  153. sourceType: ['album'], //从相册选择
  154. success: function(res) {
  155. if (_this.pic_url.length >= 9) {
  156. _this.$toast("只能选择9张照片")
  157. return
  158. }
  159. if (res.tempFilePaths.length > 0) {
  160. imgList = res.tempFilePaths
  161. imgList.forEach((item, index) => {
  162. uni.uploadFile({
  163. //后端接口地址
  164. url: uploadUrl.baseUrl + '/api/upload',
  165. //图片临时地址
  166. filePath: imgList[index],
  167. //上传文件类型
  168. name: 'file',
  169. formData: {
  170. // tag: 'avatar',
  171. 'tag': 'lamp'
  172. },
  173. success: (uploadRes) => {
  174. let result = JSON.parse(uploadRes.data)
  175. if (result.code == 0) {
  176. _this.pic_url = _this.pic_url
  177. .concat(result.data.file)
  178. console.log('上传后的头像url地址', result.data.file)
  179. }
  180. },
  181. })
  182. })
  183. }
  184. }
  185. })
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. @import "./index.scss";
  192. </style>