submit_1.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. that.$emit('choseImg', true);
  79. uni.chooseImage({
  80. count: 1,
  81. sizeType: ['original', 'compressed'],
  82. sourceType: ['album', 'camera'],
  83. success: async function(res) {
  84. that.$emit('choseImg', true);
  85. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  86. const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
  87. if (arr.errcode == '0') {
  88. let filePaths = serverUrl + arr.uri
  89. that.send(filePaths, '1')
  90. } else {
  91. that.$emit('choseImg', false);
  92. uni.showToast({
  93. title: arr.errmsg,
  94. icon: 'none'
  95. })
  96. }
  97. }
  98. });
  99. },
  100. // 发送商品
  101. sendGoods() {
  102. this.$emit('sendGoods');
  103. },
  104. // 发送订单
  105. sendOrder() {
  106. this.$emit('sendOrder');
  107. },
  108. //发送
  109. send(msg, type) {
  110. let data = {
  111. message: msg,
  112. type: type
  113. }
  114. this.$emit('inputs', data);
  115. setTimeout(() => {
  116. this.msg = '';
  117. }, 0)
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. .displaynone {
  124. display: none;
  125. }
  126. .submit-chat {
  127. width: 100%;
  128. display: flex;
  129. align-items: center;
  130. box-sizing: border-box;
  131. padding: 14rpx 14rpx;
  132. .bt-img {
  133. margin: 0 0 0 10rpx;
  134. .iconfont {
  135. font-size: 65rpx;
  136. }
  137. }
  138. .btn {
  139. flex: auto;
  140. background-color: #fff;
  141. border-radius: 10rpx;
  142. padding: 20rpx;
  143. max-height: 160rpx;
  144. margin: 0 10rpx;
  145. }
  146. .chat-send {
  147. line-height: 44rpx;
  148. width: 300rpx;
  149. }
  150. }
  151. .more {
  152. width: 100%;
  153. height: 450rpx;
  154. background: #ecedee;
  155. box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
  156. bottom: env(safe-area-inset-bottom);
  157. padding: 8rpx;
  158. box-sizing: border-box;
  159. .more_1 {
  160. display: flex;
  161. flex-wrap: wrap;
  162. .more-list {
  163. width: 18%;
  164. text-align: center;
  165. margin: 10rpx;
  166. padding: 20rpx 15rpx 15rpx 15rpx;
  167. background-color: #ffffff;
  168. border-radius: 20rpx;
  169. .iconfont {
  170. font-size: 65rpx;
  171. }
  172. .more-list-title {
  173. margin: 10rpx 0;
  174. font-size: 30rpx;
  175. color: rgba(39, 40, 50, 0.5);
  176. line-height: 34rpx;
  177. }
  178. }
  179. }
  180. }
  181. </style>