submit_1.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view>
  3. <view class="submit">
  4. <view class="submit-chat">
  5. <!-- 文本框 -->
  6. <textarea cursor-spacing='20' class="chat-send btn" :show-confirm-bar="false"
  7. disable-default-padding="true" auto-height="true" @focus="focus" v-model="msg"></textarea>
  8. <view class="bt-img" @tap="more">
  9. <text class="iconfont icon-gengduoneirong"></text>
  10. </view>
  11. <view class="bt-img" v-if="msg">
  12. <button @tap="inputs" type="primary" size="mini">发送</button>
  13. </view>
  14. </view>
  15. <!-- 更多 -->
  16. <view class="more" :class="{displaynone:!ismore}">
  17. <view class="more_1">
  18. <view class="more-list" @tap="sendImg('album')">
  19. <text class="iconfont icon-tupian"></text>
  20. <view class="more-list-title">图片</view>
  21. </view>
  22. <view class="more-list" @tap="sendGoods">
  23. <text class="iconfont icon-shangpin"></text>
  24. <view class="more-list-title">商品</view>
  25. </view>
  26. <view class="more-list" @tap="sendOrder">
  27. <text class="iconfont icon-quanbudingdan"></text>
  28. <view class="more-list-title">订单</view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. ismore: false,
  40. msg: "",
  41. };
  42. },
  43. methods: {
  44. //获取高度方法
  45. getElementHeight() {
  46. const query = uni.createSelectorQuery().in(this);
  47. query.select('.submit').boundingClientRect(data => {
  48. this.$emit('heights', data.height);
  49. }).exec();
  50. },
  51. //文字发送
  52. inputs() {
  53. if (this.msg.length > 0) {
  54. // 0为表情和文字
  55. let msg = this.msg.replace(/[\r\n]/g, "");
  56. this.send(msg, '0')
  57. }
  58. },
  59. // 输入框聚焦
  60. focus() {
  61. //关闭其他项
  62. this.ismore = false;
  63. setTimeout(() => {
  64. this.getElementHeight()
  65. }, 10)
  66. },
  67. //更多功能
  68. more() {
  69. this.ismore = !this.ismore;
  70. setTimeout(() => {
  71. this.getElementHeight();
  72. }, 10)
  73. },
  74. //图片发送
  75. sendImg(e) {
  76. const that = this;
  77. let serverUrl = that.$config.serverUrl;
  78. uni.chooseImage({
  79. count: 1,
  80. sizeType: ['original', 'compressed'],
  81. sourceType: ['album', 'camera'],
  82. success: async function(res) {
  83. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  84. const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
  85. if (arr.errcode == '0') {
  86. let filePaths = serverUrl + arr.uri
  87. that.send(filePaths, '1')
  88. } else {
  89. uni.showToast({
  90. title: arr.errmsg,
  91. icon: 'none'
  92. })
  93. }
  94. }
  95. });
  96. },
  97. // 发送商品
  98. sendGoods() {
  99. this.$emit('sendGoods');
  100. },
  101. // 发送订单
  102. sendOrder() {
  103. this.$emit('sendOrder');
  104. },
  105. //发送
  106. send(msg, type) {
  107. let data = {
  108. message: msg,
  109. type: type
  110. }
  111. this.$emit('inputs', data);
  112. setTimeout(() => {
  113. this.msg = '';
  114. }, 0)
  115. }
  116. }
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. .displaynone {
  121. display: none;
  122. }
  123. .submit-chat {
  124. width: 100%;
  125. display: flex;
  126. align-items: center;
  127. box-sizing: border-box;
  128. padding: 14rpx 14rpx;
  129. .bt-img {
  130. margin: 0 0 0 10rpx;
  131. .iconfont {
  132. font-size: 65rpx;
  133. }
  134. }
  135. .btn {
  136. flex: auto;
  137. background-color: #fff;
  138. border-radius: 10rpx;
  139. padding: 20rpx;
  140. max-height: 160rpx;
  141. margin: 0 10rpx;
  142. }
  143. .chat-send {
  144. line-height: 44rpx;
  145. width: 300rpx;
  146. }
  147. }
  148. .more {
  149. width: 100%;
  150. height: 450rpx;
  151. background: #ecedee;
  152. box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
  153. bottom: env(safe-area-inset-bottom);
  154. padding: 8rpx;
  155. box-sizing: border-box;
  156. .more_1 {
  157. display: flex;
  158. flex-wrap: wrap;
  159. .more-list {
  160. width: 18%;
  161. text-align: center;
  162. margin: 10rpx;
  163. padding: 20rpx 15rpx 15rpx 15rpx;
  164. background-color: #ffffff;
  165. border-radius: 20rpx;
  166. .iconfont {
  167. font-size: 65rpx;
  168. }
  169. .more-list-title {
  170. margin: 10rpx 0;
  171. font-size: 30rpx;
  172. color: rgba(39, 40, 50, 0.5);
  173. line-height: 34rpx;
  174. }
  175. }
  176. }
  177. }
  178. </style>