publish.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template name="publish">
  2. <view class="cu-modal show">
  3. <view class="cu-dialog">
  4. <view class="cu-bar bg-white justify-end">
  5. <view class="content">{{title}}</view>
  6. <view class="action" @tap="hideModal">
  7. <text class="cuIcon-close text-red"></text>
  8. </view>
  9. </view>
  10. <view class="padding-xls">
  11. <view class="publish-wrap bg-white">
  12. <view class="input-box padding-sm">
  13. <textarea class="area-top" placeholder="写点啥..." v-model="content"></textarea>
  14. </view>
  15. <view class="cu-form-group img-box" v-if="is_upload">
  16. <view class="next-title">上传图片(最多{{total}}张)</view>
  17. <view class="margin-none margin-left">
  18. <view class="grid col-5 grid-square flex-sub padding-top-lg">
  19. <view class="bg-img" v-for="(item,index) in pic" :key="index">
  20. <image :src="item" mode="aspectFill" @tap="Dever.viewPic(pic, item)" class="img-item"></image>
  21. <image src="@/static/img/publish/img_close.png" @tap.stop="del" :data-index="index" mode="widthFix" class="close-img"></image>
  22. </view>
  23. <view class="add-img" @tap="choose" v-if="pic.length<total">
  24. <text class='cuIcon-add link-color'></text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="cu-bar bg-white">
  32. <view class="action margin-0 flex-sub text-green" @tap="hideModal" v-if="is_upload" style="display: none;">
  33. <text class="cuIcon-moneybag"></text>藏点钱
  34. </view>
  35. <view class="action margin-0 flex-sub text-green solid-left" @tap="save">发布</view>
  36. <view class="action margin-0 flex-sub solid-left" @tap="hideModal">取消</view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. name : 'publish',
  44. props: {
  45. title : '',
  46. cate_id : null,
  47. type : null,
  48. type_id : 0,
  49. to_id : 0,
  50. to_uid : 0,
  51. index : 0,
  52. is_upload : true,
  53. seconds : 0,
  54. api : {
  55. type : String,
  56. default : 'app/community/?l=api.add'
  57. },
  58. },
  59. data() {
  60. return {
  61. pic : [],
  62. content : '',
  63. upload : 'img',
  64. total : 9,
  65. };
  66. },
  67. mounted() {
  68. // 初始化上传数据
  69. this.Dever.getUpload().data = {};
  70. this.Dever.getUpload().data[this.upload] = [];
  71. this.pic = [];
  72. },
  73. methods: {
  74. // 保存数据
  75. save : function() {
  76. var self = this;
  77. var data = {};
  78. data.content = this.content;
  79. if (this.pic.length > 0) {
  80. data.pic = this.pic.join(',');
  81. }
  82. if (this.cate_id) {
  83. data.cate_id = this.cate_id;
  84. }
  85. if (this.seconds) {
  86. data.seconds = this.seconds;
  87. }
  88. data.type = this.type;
  89. data.type_id = this.type_id;
  90. data.to_id = this.to_id;
  91. data.to_uid = this.to_uid;
  92. this.Dever.post(this.api, data, function(t) {
  93. self.getRefresh(data.content);
  94. });
  95. },
  96. // 选择图片
  97. choose: function() {
  98. var self = this;
  99. var upload = this.Dever.upload(this.upload, this.total, function(type, img) {
  100. self.pic = img;
  101. });
  102. },
  103. // 删除图片
  104. del : function(e) {
  105. var self = this;
  106. self.pic.splice(e.currentTarget.dataset.index, 1)
  107. },
  108. hideModal : function() {
  109. this.$emit('hideModal');
  110. },
  111. getRefresh : function(content) {
  112. this.$emit('getRefresh', this.cate_id, this.type, this.type_id, content);
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="less" scoped>
  118. .textarea-placeholder {
  119. text-align: left;;
  120. }
  121. .grid.grid-square {
  122. overflow: visible;
  123. }
  124. .margin-left {
  125. width: 100%;
  126. font-size: 13px;
  127. line-height: 21px;
  128. margin-left: -60rpx;
  129. }
  130. .publish-wrap {
  131. .input-box {
  132. .area-top {
  133. width: 100%;
  134. box-shadow: inset 0 -1px 0 0 #ECECEC;
  135. min-height: 280rpx;
  136. text-align: left;
  137. }
  138. }
  139. .img-box {
  140. padding: 30rpx;
  141. display: flex;
  142. flex-direction: column;
  143. margin-top: 20rpx;
  144. margin-bottom: 160rpx;
  145. .next-title {
  146. width: 100%;
  147. font-size: 36rpx;
  148. color: var(--mainColor);
  149. }
  150. .font-red {
  151. color: #ff0000;
  152. }
  153. .img-wrap {
  154. width: 100%;
  155. font-size: 28rpx;
  156. line-height: 44rpx;
  157. color: #999999;
  158. margin: 20rpx 0;
  159. }
  160. .add-img {
  161. left: 60rpx;
  162. border: 4rpx dashed #999;
  163. font-size: 40rpx;
  164. }
  165. }
  166. .bottom-btn {
  167. position: fixed;
  168. bottom: 0;
  169. width: 100%;
  170. padding: 20rpx 0;
  171. .btn {
  172. border-radius: 40rpx;
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. color: #FFFFFF;
  177. border: 1rpx solid var(--activeColor);
  178. background-color: var(--activeColor);
  179. box-shadow: 0 1px 10px 0px var(--activeColor);
  180. width: 400rpx;
  181. height: 80rpx;
  182. }
  183. }
  184. }
  185. .bg-img {
  186. overflow: visible !important;
  187. .img-item {
  188. border-radius: 20rpx;
  189. }
  190. .close-img {
  191. position: absolute;
  192. width: 36rpx !important;
  193. top: -18rpx;
  194. right: -18rpx;
  195. }
  196. }
  197. </style>