noteadd.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="page">
  3. <view class="group_note">
  4. <div class="menu">
  5. <block v-if="noteinfo.id>0">编辑公告</block>
  6. <block v-else>发布公告</block>
  7. <div class="btn" @tap="back()"><uni-icons type="undo"
  8. style="color:#fff;margin-right: 3px;;"></uni-icons>返回</div>
  9. </div>
  10. <div class="group_note" style="background-color: #fff;">
  11. <div class="contentadd">
  12. <textarea placeholder="请输入通知内容" v-model="noteinfo.content" :maxlength="-1"></textarea>
  13. <view style="margin-top: 15px;">
  14. <block v-for="(m,index) in imglist" :key="index">
  15. <view :class="{'images':true,'uploading':index>=images.length}">
  16. <image :src="imgshow(m)"></image>
  17. <uni-icons class="close" type="close" @tap="delimg(index)"></uni-icons>
  18. <view class="status">上传中</view>
  19. </view>
  20. </block>
  21. <view class="images">
  22. <image src="../static/img/icon-plus.png" @tap="uploadImage"></image>
  23. </view>
  24. </view>
  25. </div>
  26. <view style="width: 80%;margin: 15px auto;display: block">
  27. <div class="button1" @tap="click_add()">确认<block v-if="noteinfo.id>0">编辑</block>
  28. <block v-else>发布</block>
  29. </div>
  30. </view>
  31. </div>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import uniIcons from './uni-icons/uni-icons.vue'
  37. import config from "../config.js"
  38. import http from "../library/http.js"
  39. import helper from "../library/helper.js"
  40. export default {
  41. components: {
  42. uniIcons,
  43. },
  44. props: {
  45. group: {
  46. required: true
  47. },
  48. noteinfo: {
  49. default: {
  50. id: 0,
  51. content: '',
  52. imgs: ''
  53. }
  54. },
  55. },
  56. data() {
  57. return {
  58. imglist: [],
  59. images: [],
  60. action: 'noteadd'
  61. };
  62. },
  63. methods: {
  64. click_add() {
  65. // if (this.noteinfo.content.length < 10) {
  66. // uni.showToast({
  67. // title: '公告内容最少10个字符',
  68. // icon: 'none'
  69. // })
  70. // return false;
  71. // }
  72. if (this.images.length != this.imglist.length) {
  73. ni.showToast({
  74. title: '图片正在上传中,请稍后',
  75. icon: 'none'
  76. })
  77. return false;
  78. }
  79. var postdata = {
  80. id: this.noteinfo.id,
  81. group_id: this.group.id,
  82. content: this.noteinfo.content,
  83. imgs: this.images.join('|'),
  84. userid: uni.getStorageSync('access_token')
  85. };
  86. http.setWait(true).post('group.php?act=' + this.action, postdata).then(res => {
  87. if (res.code == 200) {
  88. if (this.action == 'noteadd') {
  89. uni.showToast({
  90. title: '发布成功'
  91. })
  92. } else {
  93. uni.showToast({
  94. title: '编辑成功'
  95. })
  96. }
  97. this.$emit('getnoteinfo');
  98. this.back();
  99. } else {
  100. uni.showToast({
  101. title: '网络错误,请稍后再试',
  102. icon: 'none'
  103. })
  104. }
  105. })
  106. },
  107. uploadImage() {
  108. if (this.imglist.length >= 1) {
  109. uni.showToast({
  110. title: '只能上传一张图片',
  111. icon: 'none'
  112. })
  113. return false;
  114. }
  115. uni.chooseImage({
  116. count: 1,
  117. success: (chooseImageRes) => {
  118. for (var i = 0; i < chooseImageRes.tempFilePaths.length; i++) {
  119. var tempFilePaths = chooseImageRes.tempFilePaths[i];
  120. this.imglist.push(tempFilePaths);
  121. helper.uploadFiles([tempFilePaths], 'images', {
  122. type: 'avatar'
  123. }).then(res => {
  124. this.images.push(res.replace(config.imgUri, ''));
  125. })
  126. }
  127. }
  128. });
  129. },
  130. delimg(num) {
  131. this.images.splice(num, 1);
  132. this.imglist.splice(num, 1);
  133. },
  134. back() {
  135. this.$emit('back');
  136. },
  137. imgshow(image_url) {
  138. if (image_url.indexOf('http') <= -1) image_url = config.imgUri + image_url;
  139. if (this.noteinfo.id > 0)
  140. return image_url;
  141. else
  142. return this.image_cache(image_url)
  143. }
  144. },
  145. mounted() {
  146. if (this.noteinfo.id > 0) {
  147. this.images = this.noteinfo.imgs.split('|')
  148. this.imglist = this.noteinfo.imgs.split('|')
  149. this.action = 'noteedit';
  150. }
  151. }
  152. }
  153. </script>
  154. <style>
  155. @import "@/static/css/group.css";
  156. .page {
  157. background-color: #fff;
  158. }
  159. .images {
  160. display: inline-block;
  161. width: 50px;
  162. ;
  163. height: 50px;
  164. text-align: center;
  165. margin: 0px 5px;
  166. position: relative;
  167. }
  168. .images image {
  169. height: 50px;
  170. width: 50px;
  171. ;
  172. vertical-align: middle;
  173. border-radius: 5px;
  174. ;
  175. }
  176. .images .close {
  177. position: absolute;
  178. top: -7px;
  179. right: -7px;
  180. color: #666 !important;
  181. font-size: 18px !important;
  182. z-index: 1;
  183. font-weight: 700;
  184. }
  185. .images .status {
  186. position: absolute;
  187. z-index: 2;
  188. left: 0px;
  189. top: 0px;
  190. width: 100%;
  191. height: 50px;
  192. line-height: 50px;
  193. background-color: rgba(0, 0, 0, 0.7);
  194. color: #fff;
  195. font-size: 12px;
  196. text-align: center;
  197. display: none;
  198. }
  199. .images.uploading .close {
  200. display: none;
  201. }
  202. .images.uploading .status {
  203. display: block;
  204. }
  205. </style>