健康同学微信公众号h5项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.0KB

  1. <template>
  2. <div class="sendMessage">
  3. <van-nav-bar title="留言" left-arrow :border="true" @click-left="onNavBack"></van-nav-bar>
  4. <div class="mt20"></div>
  5. <div class="textArea">
  6. <textarea
  7. placeholder="请输入内容"
  8. v-model.trim="inputVal"
  9. @input="inputChange"
  10. maxlength="70"
  11. @blur="fixScroll"
  12. />
  13. <span class="text">{{ this.num }}/70</span>
  14. </div>
  15. <div :class="[{ active: inputVal.length > 0 }, 'next']" @click="onSendCommand">发送</div>
  16. </div>
  17. </template>
  18. <script>
  19. import { DeviceCommandModel } from '../../config/models';
  20. import ToastService from '../../services/toast-service';
  21. import DialogService from '../../services/dialog-service';
  22. import APICommand from '@/api/command';
  23. export default {
  24. data() {
  25. return {
  26. inputVal: '',
  27. num: 0,
  28. isSending: false
  29. };
  30. },
  31. methods: {
  32. //返回
  33. onNavBack() {
  34. this.$router.push({ name: this.$route.query.from ? this.$route.query.from : 'Myself' });
  35. },
  36. inputChange() {
  37. this.num = this.inputVal.length;
  38. },
  39. fixScroll() {
  40. let u = navigator.userAgent;
  41. let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  42. if (isiOS) {
  43. window.scrollTo(0, 0);
  44. }
  45. },
  46. onSendCommand() {
  47. // TODO 修改按钮的触发形式:输入字符串为空时,不可提交
  48. // if (this.inputVal === '') return;
  49. ToastService.loading();
  50. if (this.inputVal === '' && this.isSending == false) {
  51. console.log('not ok');
  52. ToastService.clear();
  53. DialogService.confirm({ title: '请输入内容' });
  54. }
  55. // if (this.isSending) {
  56. // return;
  57. // }
  58. this.isSending = false;
  59. /* let url = `/api/Command/SendCommand`; */
  60. let cmdValue = {
  61. Username: this.longName,
  62. Parameter: this.inputVal
  63. };
  64. /* let jsonData = {
  65. deviceId: this.$store.getters.deviceId,
  66. userId: this.$store.getters.userId,
  67. serialNo: this.$store.getters.serialNo,
  68. cmdCode: DeviceCommandModel.sendMsg,
  69. cmdValue: JSON.stringify(cmdValue)
  70. }; */
  71. if (this.inputVal.length > 0) {
  72. /* this.$axios
  73. .post(url, jsonData) */
  74. APICommand.sendCommand({
  75. deviceId: this.$store.getters.deviceId,
  76. userId: this.$store.getters.userId,
  77. serialNo: this.$store.getters.serialNo,
  78. cmdCode: DeviceCommandModel.sendMsg,
  79. cmdValue: JSON.stringify(cmdValue)
  80. })
  81. .then(res => {
  82. ToastService.clear();
  83. let item = res.data;
  84. if (item.stateCode == 1) {
  85. console.log(item);
  86. ToastService.clear();
  87. ToastService.success({ message: '发送成功' });
  88. this.inputVal = '';
  89. this.inputChange();
  90. } else {
  91. ToastService.clear();
  92. DialogService.confirm({
  93. title: '发送失败,请重新设置'
  94. });
  95. this.inputVal = '';
  96. }
  97. })
  98. .catch(err => console.log(err))
  99. .finally(() => (this.isSending = false));
  100. }
  101. }
  102. },
  103. created() {
  104. this.idCode = this.$route.query.code;
  105. this.longName = this.$route.query.longName;
  106. }
  107. };
  108. </script>
  109. <style lang="scss" scoped>
  110. .sendMessage {
  111. background-color: $background;
  112. .mt20 {
  113. height: 20px;
  114. background-color: $background;
  115. }
  116. .textArea {
  117. position: relative;
  118. .text {
  119. position: absolute;
  120. right: 30px;
  121. bottom: 30px;
  122. @include colorAndFont(#999, 24);
  123. }
  124. }
  125. .next {
  126. @include center();
  127. margin: 100px auto 0;
  128. width: 550px;
  129. height: 80px;
  130. border-radius: 10px;
  131. background: $next_green;
  132. color: #fff;
  133. font-size: 36px;
  134. &.active {
  135. background: $green;
  136. }
  137. &.res {
  138. margin: 140px auto 0;
  139. }
  140. }
  141. textarea {
  142. padding: 20px 30px;
  143. width: 100%;
  144. height: 354px;
  145. box-sizing: border-box;
  146. @include colorAndFont(#666, 34);
  147. }
  148. }
  149. </style>