complaint.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="container">
  3. <u-form labelPosition="top" labelWidth='0' :model="formdata" :rules="rules" ref="uForm" errorType="toast">
  4. <u-form-item label=" " prop="type">
  5. <view class="form-item">
  6. <view class="form-item-title">投诉类型</view>
  7. <view class="tagbox">
  8. <view :class="formdata.type == 1?'tagitem active':'tagitem'" @click="formdata.type = 1">店铺</view>
  9. <view :class="formdata.type == 2?'tagitem active':'tagitem'" @click="formdata.type = 2">商品</view>
  10. <view :class="formdata.type == 0?'tagitem active':'tagitem'" @click="formdata.type = 0">其他</view>
  11. </view>
  12. </view>
  13. </u-form-item>
  14. <u-form-item label=" " prop="title">
  15. <view class="form-item">
  16. <view class="form-item-title">投诉标题</view>
  17. <u--input v-model="formdata.title" placeholder="请输入投诉标题" maxlength='100'></u--input>
  18. </view>
  19. </u-form-item>
  20. <u-form-item label=" " prop="content">
  21. <view class="form-item">
  22. <view class="form-item-title">投诉内容</view>
  23. <u--textarea v-model="formdata.content" placeholder="请详细描述您遇到的问题,我们会认真处理您的投诉" count maxlength='200'></u--textarea>
  24. </view>
  25. </u-form-item>
  26. <u-form-item label=" " prop="images">
  27. <view class="form-item">
  28. <view class="form-item-title">上传凭证</view>
  29. <u-upload
  30. :fileList="fileList1"
  31. @afterRead="afterRead"
  32. @delete="deletePic"
  33. name="1"
  34. :maxCount="3"
  35. ></u-upload>
  36. </view>
  37. </u-form-item>
  38. </u-form>
  39. <view class="btn-box">
  40. <view class="sub-btn" @click="submit()">提交</view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {storeComplaint} from '@/api/user.js'
  46. export default {
  47. data() {
  48. return {
  49. fileList1:[],
  50. formdata: {
  51. title:'',
  52. type:0,//0默认1店铺2商品
  53. content: '',
  54. images: ''
  55. },
  56. rules: {
  57. title: [{required: true, message: '请输入投诉标题'}],
  58. content: [{required: true, message: '请输入投诉内容'}],
  59. images: [{required: true, message: '请上传凭证'}],
  60. }
  61. }
  62. },
  63. methods: {
  64. submit(){
  65. var that=this;
  66. if(this.fileList1.length>0){
  67. this.formdata.images=this.fileList1[0].url
  68. }
  69. this.$refs.uForm.validate().then(res => {
  70. if(res) {
  71. storeComplaint(this.formdata).then(res=>{
  72. if(res.code == 200) {
  73. uni.showModal({
  74. title: '',
  75. content: '我们已收到您的反馈,谢谢',
  76. showCancel: false,
  77. success: function (res) {
  78. if (res.confirm) {
  79. uni.navigateBack()
  80. } else if (res.cancel) {
  81. uni.navigateBack()
  82. }
  83. }
  84. });
  85. } else {
  86. uni.showToast({
  87. title: res.msg,
  88. icon:'none'
  89. })
  90. }
  91. })
  92. }
  93. })
  94. },
  95. deletePic(event) {
  96. this[`fileList${event.name}`].splice(event.index, 1)
  97. },
  98. async afterRead(event) {
  99. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  100. let lists = [].concat(event.file)
  101. let fileListLen = this[`fileList${event.name}`].length
  102. lists.map((item) => {
  103. this[`fileList${event.name}`].push({
  104. ...item,
  105. status: 'uploading',
  106. message: '上传中'
  107. })
  108. })
  109. for (let i = 0; i < lists.length; i++) {
  110. const result = await this.uploadFilePromise(lists[i].url)
  111. let item = this[`fileList${event.name}`][fileListLen]
  112. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  113. status: 'success',
  114. message: '',
  115. url: result
  116. }))
  117. fileListLen++
  118. }
  119. },
  120. uploadFilePromise(url) {
  121. return new Promise((resolve, reject) => {
  122. let a = uni.uploadFile({
  123. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS',
  124. filePath: url,
  125. name: 'file',
  126. formData: {
  127. user: 'test'
  128. },
  129. success: (res) => {
  130. setTimeout(() => {
  131. console.log(JSON.parse(res.data).url)
  132. resolve(JSON.parse(res.data).url)
  133. }, 1000)
  134. }
  135. });
  136. })
  137. },
  138. }
  139. }
  140. </script>
  141. <style scoped lang="scss">
  142. .container{
  143. padding: 24rpx;
  144. }
  145. ::v-deep .u-form-item__body {
  146. padding: 0 !important;
  147. }
  148. .btn-box{
  149. width: 100%;
  150. height: 120upx;
  151. padding: 0 30upx;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. .sub-btn{
  156. width: 100%;
  157. height: 88upx;
  158. line-height: 88upx;
  159. text-align: center;
  160. font-size: 30upx;
  161. font-family: PingFang SC;
  162. font-weight: bold;
  163. color: #FFFFFF;
  164. background: #2583EB;
  165. border-radius: 44upx;
  166. }
  167. }
  168. .tagbox {
  169. display: flex;
  170. align-items: center;
  171. flex-wrap: wrap;
  172. .tagitem {
  173. min-width: 100rpx;
  174. box-sizing: border-box;
  175. font-family: PingFang SC, PingFang SC;
  176. font-weight: 400;
  177. font-size: 30rpx;
  178. padding: 8rpx 12rpx;
  179. background: #FFF;
  180. border: 1rpx solid #2583EB;
  181. color: #2583EB;
  182. border-radius: 4rpx 4rpx 4rpx 4rpx;
  183. margin-right: 24rpx;
  184. text-align: center;
  185. }
  186. .active {
  187. color: #FFFFFF;
  188. border: 1rpx solid #2583EB;
  189. background: #2583EB;
  190. }
  191. }
  192. .form-item {
  193. background-color: #fff;
  194. border-radius: 16rpx;
  195. padding: 0 24rpx 24rpx 24rpx;
  196. margin-bottom: 24rpx;
  197. &-title {
  198. font-family: PingFang SC, PingFang SC;
  199. font-weight: 600;
  200. font-size: 32rpx;
  201. color: #222222;
  202. padding: 24rpx 0;
  203. }
  204. }
  205. </style>