advice.vue 5.3 KB

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