advice.vue 5.5 KB

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