index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="addEvalute">
  3. <!-- header -->
  4. <cu-custom isBack bgColor="bg-gradual-blue"><view slot="content">评价</view></cu-custom>
  5. <!-- section -->
  6. <view class="margin-bottom padding flex bg-white">
  7. <image class="radius margin-right-sm" style="width: 160upx;height: 160upx;min-width: 160upx;" lazy-load="true" src="https://gd-hbimg.huaban.com/1f50f2135ba51e4b9aa20caef41860b15005c9386f0b-LxqWsh_fw658/format/webp" mode="aspectFit"></image>
  8. <view style="flex: auto;" class="padding-tb text-black cut">商品名称</view>
  9. </view>
  10. <view class="flex bg-white padding-lr padding-top align-center">
  11. <view class="text-bold text-black margin-right">商品评价</view>
  12. <cu-rate :value="3" />
  13. </view>
  14. <view class="cu-form-group">
  15. <textarea
  16. :value="content"
  17. style="min-height: 250rpx;"
  18. auto-focus
  19. auto-height
  20. maxlength="300"
  21. @input="textareaAInput"
  22. placeholder="产品性价比 / 版型风格 / 尺码大小"
  23. ></textarea>
  24. </view>
  25. <view class="bg-white text-right padding">{{ content.length }}/300</view>
  26. <view class="bg-white padding-lr padding-bottom flex justify-between">
  27. <view class="text-black">添加图片 / 视频</view>
  28. <view class="">{{ imgList.length }}/5</view>
  29. </view>
  30. <view class="cu-form-group">
  31. <view class="grid col-4 grid-square flex-sub">
  32. <view class="bg-img" v-for="(item, index) in imgList" :key="index" @click="ViewImage(item)">
  33. <image :src="item" mode="aspectFill"></image>
  34. <view class="cu-tag bg-red" @click.stop="DelImg(index)"><text class="cuIcon-close"></text></view>
  35. </view>
  36. <view class="solids" @click="ChooseImage" v-if="imgList.length < 5"><text class="cuIcon-cameraadd"></text></view>
  37. </view>
  38. </view>
  39. <!-- <view class="cu-form-group">
  40. <view class="title">同意遵守平台约定</view>
  41. <checkbox-group @change="checboxFunc"><checkbox value="root" class="round blue" :checked="'root' | checkboxFilter(checkbox)"></checkbox></checkbox-group>
  42. </view> -->
  43. <button @click="submitFunc" style="height: 100rpx;" class="margin cu-btn bg-blue block " :loading="loading">提交评论</button>
  44. <!-- 工具 -->
  45. <cu-modalA title="提示" :show.sync="err_show" content="帖子描述不能为空,并且必须遵守平台约定." />
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. filters: {
  51. checkboxFilter(value, checkbox) {
  52. var itemOptions = checkbox.filter(item => item.name == value);
  53. if (itemOptions.length == 0) return false;
  54. return itemOptions[0].value;
  55. }
  56. },
  57. computed: {},
  58. data() {
  59. return {
  60. loading: false,
  61. root: false,
  62. // 表单
  63. checkbox: [
  64. {
  65. name: 'root',
  66. value: false
  67. }
  68. ],
  69. content: '',
  70. imgList: [],
  71. err_show: false
  72. };
  73. },
  74. methods: {
  75. // 多行文本框输入
  76. textareaAInput(e) {
  77. this.content = e.detail.value;
  78. },
  79. // 挑选图片
  80. ChooseImage() {
  81. uni.chooseMedia({
  82. count: 5,
  83. mediaType: ['image', 'video'],
  84. sourceType: ['album', 'camera'],
  85. success: res => {
  86. let len = res.tempFiles.length + this.imgList.length;
  87. if (len <= 5) this.imgList = this.imgList.concat(res.tempFiles);
  88. }
  89. });
  90. },
  91. // 预览
  92. ViewImage(value) {
  93. uni.previewImage({
  94. urls: this.imgList,
  95. current: value
  96. });
  97. },
  98. // 删除指定图片
  99. DelImg(value) {
  100. var imgList = JSON.parse(JSON.stringify(this.imgList));
  101. imgList.splice(value, 1);
  102. this.imgList = imgList;
  103. },
  104. // 提交
  105. async submitFunc() {
  106. this.loading = true;
  107. try {
  108. if (!this.content || !this.checkbox[0].value) {
  109. this.err_show = true;
  110. return false;
  111. }
  112. // 上传图片
  113. var imgList = this.imgList.map(item => {
  114. // 文件名称
  115. let fileName = item.lastIndexOf('/');
  116. fileName = item.substring(fileName + 1, item.length);
  117. fileName = new Date().getDate() + '_' + fileName;
  118. return uniCloud.uploadFile({
  119. filePath: item,
  120. cloudPath: fileName,
  121. fileType: 'image'
  122. });
  123. });
  124. var result = await Promise.all(imgList);
  125. // 处理远程图片路径
  126. // https://vkceyugu.cdn.bspapp.com/VKCEYUGU-1ae627f1-d0fe-43cf-a7a6-6f30c5e8aadc/XXX.png
  127. result = result.map(item => item.fileID.substring(item.fileID.lastIndexOf('/') + 1, item.fileID.length));
  128. var inviation = this.$store.state.inviation || [];
  129. // var res=await api.uploadItem({imgList:result,content:this.content,_id:this.$store.state._id,inviation});
  130. if (res.result.code == 1) throw res.result.msg;
  131. if (res.result.inviation_id) {
  132. inviation.unshift(res.result.inviation_id);
  133. this.$store.dispatch('userInfo', { inviation });
  134. }
  135. uni.navigateBack({
  136. delta: 1
  137. });
  138. } catch (err) {
  139. console.log(err);
  140. } finally {
  141. this.loading = false;
  142. }
  143. }
  144. }
  145. };
  146. </script>
  147. <style lang="scss" scoped>
  148. .addEvalute{
  149. .cut{
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. display:-webkit-box;
  153. -webkit-box-orient: vertical;
  154. -webkit-line-clamp: 2;
  155. }
  156. }
  157. </style>