advice.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="container advice-container">
  3. <view class="advice-ipt-cont">
  4. <u-input
  5. v-model="advice_content"
  6. type="textarea"
  7. maxlength="100"
  8. :clearable="false"
  9. placeholder="您有任何使用建议,可以提供给我们,以便为您提供更好的产品服务。"
  10. height="300"
  11. class="ipt"/>
  12. <text class="num-tag">{{advice_content.length}}/100</text>
  13. </view>
  14. <view class="upload-cont">
  15. <block v-if="fileList.length">
  16. <view class="add_icon" v-for="(item,index) in fileList" :key="item">
  17. <image class=" img" :src="item" @click="viewImage(item, fileList)">
  18. </image>
  19. <icon type="clear" size="16" class="del-ico" color="#f00" @click.stop="delImg(index)"/>
  20. </view>
  21. </block>
  22. <view class="add_icon upload-ico" v-if="fileList.length < 3" @click="ChooseFile">
  23. <u-icon name="plus" color="#9C9C9C" size="48"></u-icon>
  24. <text class="add-tip">上传图片</text>
  25. </view>
  26. </view>
  27. <view class="btn-cont" @click="submitHandle">
  28. 提交
  29. <!-- <image src="@/static/img/btn_bg.png" class="btn_bg"></image> -->
  30. <!-- <text class="btn-txt">提交</text> -->
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import { uploadurl,Mine } from '@/config/api.js'
  36. export default {
  37. data() {
  38. return {
  39. fileList:[],//上传的图片地址
  40. uploadIndex:0,
  41. advice_content:'',
  42. };
  43. },
  44. methods:{
  45. init() {
  46. this.fileList = [],
  47. this.uploadIndex = 0;
  48. this.advice_content = '';
  49. },
  50. /* 提交 */
  51. submitHandle() {
  52. if(this.advice_content) {
  53. Mine.advice({
  54. Advice: this.advice_content,
  55. AdviceImgUrl: this.fileList.join('#')
  56. }).then(res => {
  57. if(res.Ret === 200) {
  58. this.$util.toast('提交成功')
  59. this.init();
  60. }
  61. })
  62. }else {
  63. this.$util.toast('请填写内容')
  64. }
  65. },
  66. // 选择图片
  67. ChooseFile() {
  68. uni.chooseImage({
  69. count: 3, // 上传选择图片张数
  70. sizeType: ['original', 'compressed'],
  71. sourceType: ['album', 'camera'],
  72. success: (res) => {
  73. this.uploadIndex = 0;
  74. let tempFilePaths = res.tempFilePaths;
  75. this.upload(tempFilePaths,tempFilePaths.length)
  76. }
  77. })
  78. },
  79. // 上传图片到服务器
  80. upload(imgs,len){
  81. let token = this.$db.get("access_token");
  82. let authHeader = token || '';
  83. let that = this;
  84. // loading 模态框
  85. uni.uploadFile({
  86. url: uploadurl,
  87. filePath: imgs[that.uploadIndex], // 要上传文件的路径
  88. header: {
  89. "Content-Type": "multipart/form-data",
  90. 'Authorization':authHeader
  91. },
  92. name: 'file',
  93. success(res){
  94. let data = JSON.parse(res.data)
  95. if(data.Ret === 200) {
  96. that.uploadIndex ++;
  97. that.fileList = that.fileList.concat(data.Data.ResourceUrl)
  98. if(that.uploadIndex === len){
  99. that.$util.toast('上传成功')
  100. } else {
  101. that.upload(imgs,len)
  102. }
  103. }
  104. },
  105. fail(err) {
  106. uni.hideToast();
  107. uni.showModal({
  108. title: '错误提示',
  109. content: '上传图片失败'+err,
  110. showCancel: false,
  111. success: function (res) { }
  112. })
  113. }
  114. })
  115. },
  116. //预览图片
  117. viewImage(path, imgList) {
  118. uni.previewImage({
  119. current: path, // 当前显示图片的http链接
  120. urls: imgList // 需要预览的图片http链接列表
  121. });
  122. },
  123. // 删除图片
  124. delImg(index) {
  125. uni.showModal({
  126. title: '',
  127. content: '确定要删除图片吗 ?',
  128. success: (res)=> {
  129. if (res.confirm) {
  130. console.log('del')
  131. this.fileList.splice(index, 1);
  132. }
  133. }
  134. })
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .advice-container {
  141. background-color: #fff;
  142. padding: 30rpx 34rpx;
  143. .advice-ipt-cont {
  144. height: 420rpx;
  145. border: 1rpx solid #D0CFD5;
  146. border-radius: 8rpx;
  147. padding: 30rpx;
  148. position: relative;
  149. font-size: 28rpx;
  150. color: #D0CFD5;
  151. .num-tag {
  152. position: absolute;
  153. bottom: 30rpx;
  154. right: 30rpx;
  155. }
  156. }
  157. .upload-cont {
  158. margin: 40rpx 0 160rpx;
  159. display: flex;
  160. align-items: center;
  161. .add_icon {
  162. width: 194rpx;
  163. height: 194rpx;
  164. margin-right: 50rpx;
  165. position: relative;
  166. .del-ico {
  167. position: absolute;
  168. right: 20rpx;
  169. top: 20rpx;
  170. }
  171. &:last-child {
  172. margin-right: 0;
  173. }
  174. .img {
  175. width: 194rpx;
  176. height: 194rpx;
  177. box-shadow: 3rpx 3rpx 3rpx rgba(158, 158, 158, 0.16);
  178. }
  179. &.upload-ico {
  180. padding-top: 50rpx;
  181. text-align: center;
  182. background-color: #F7F7F7;
  183. color: #4A4A4A;
  184. .add-tip {
  185. margin-top: 10rpx;
  186. }
  187. }
  188. }
  189. }
  190. .btn-cont {
  191. width: 368rpx;
  192. height: 80rpx;
  193. // position: relative;
  194. background-color: #3385FF;
  195. color: #fff;
  196. font-size: 34rpx;
  197. margin: 0 auto;
  198. text-align: center;
  199. line-height: 80rpx;
  200. .btn_bg {
  201. width: 100%;
  202. height: 80rpx;
  203. position: absolute;
  204. left: 0;
  205. top: 0;
  206. }
  207. .btn-txt {
  208. width: 100%;
  209. // position: absolute;
  210. z-index: 1;
  211. }
  212. }
  213. }
  214. </style>