add.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view>
  3. <textarea v-model="content" class="text-white text-df flex-sub" placeholder="请输入信息内容" maxlength="100"
  4. placeholder-style="text-align: left;"
  5. style="height: 300upx;width: 95%;margin: 20rpx;text-align: left;background: #FFFFFF;padding: 20rpx;border-radius: 15rpx;"></textarea>
  6. <view class="padding-lr-sm" v-if="type == 0">
  7. <u-button :custom-style="customStyle1" :hair-line="false" @click="save()">
  8. 添加
  9. </u-button>
  10. </view>
  11. <view class="padding-lr-sm" style="margin-top: 100rpx;display: flex;" v-if="type == 1">
  12. <u-button style="width: 48%;margin-right: 20rpx;" :custom-style="customStyle2" :hair-line="false"
  13. @click="deleteMsg()">
  14. 删除
  15. </u-button>
  16. <u-button style="width: 48%;" :custom-style="customStyle1" :hair-line="false" @click="updateMsg()">
  17. 保存
  18. </u-button>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. customStyle1: {
  27. backgroundColor: "#00B88F",
  28. border: 0,
  29. color: "#FFF",
  30. height: '98rpx'
  31. },
  32. customStyle2: {
  33. backgroundColor: "#ffffff",
  34. border: 0,
  35. color: "#000",
  36. height: '98rpx'
  37. },
  38. id: '',
  39. type1: 0, //0,常用语,1,自动回复
  40. type: 0, //0,添加 1,编辑
  41. content: ''
  42. }
  43. },
  44. onLoad(d) {
  45. this.type = d.type;
  46. if (d.type == 1) {
  47. uni.setNavigationBarTitle({
  48. title: '编辑信息'
  49. })
  50. }
  51. this.type1 = d.type1;
  52. if (this.type1 == 1) {
  53. this.getDetailMsg();
  54. }
  55. if (d.id) {
  56. this.id = d.id;
  57. this.getDetailMsg();
  58. }
  59. },
  60. methods: {
  61. deleteMsg() {
  62. let userId = this.$queue.getData('userId');
  63. uni.showModal({
  64. title: '温馨提示',
  65. content: '您确认要删除当前信息吗?',
  66. showCancel: true,
  67. cancelText: '取消',
  68. confirmText: '确认',
  69. success: res => {
  70. if (res.confirm) {
  71. if (this.type1 == 0) {
  72. this.$Request.postT('/app/message/deleteMessage?id=' + this.id).then(res => {
  73. if (res.code == 0) {
  74. uni.hideLoading();
  75. this.$queue.showToast('删除成功!')
  76. this.content = '';
  77. setTimeout(d => {
  78. uni.navigateBack();
  79. }, 1000);
  80. } else {
  81. uni.hideLoading();
  82. this.$queue.showToast(res.msg)
  83. }
  84. });
  85. } else {
  86. let data = {
  87. msg: ''
  88. }
  89. this.$Request.postJson('/app/user/updateUser', data).then(res => {
  90. if (res.code == 0) {
  91. uni.hideLoading();
  92. this.$queue.showToast('删除成功!')
  93. this.content = '';
  94. setTimeout(d => {
  95. uni.navigateBack();
  96. }, 1000);
  97. } else {
  98. uni.hideLoading();
  99. this.$queue.showToast(res.msg)
  100. }
  101. });
  102. }
  103. }
  104. }
  105. });
  106. },
  107. updateMsg() {
  108. let userId = this.$queue.getData('userId');
  109. let data = {
  110. state: 20,
  111. userId: userId,
  112. content: this.content,
  113. id: this.id
  114. }
  115. uni.showModal({
  116. title: '温馨提示',
  117. content: '您确认要修改当前信息吗?',
  118. showCancel: true,
  119. cancelText: '取消',
  120. confirmText: '确认',
  121. success: res => {
  122. if (res.confirm) {
  123. if (this.type1 == 0) {
  124. this.$Request.postJson('/app/message/updateMessage', data).then(res => {
  125. if (res.code == 0) {
  126. uni.hideLoading();
  127. this.$queue.showToast('修改成功!')
  128. this.content = '';
  129. setTimeout(d => {
  130. uni.navigateBack();
  131. }, 1000);
  132. } else {
  133. uni.hideLoading();
  134. this.$queue.showToast(res.msg)
  135. }
  136. });
  137. } else {
  138. let data = {
  139. msg: this.content
  140. }
  141. this.$Request.postJson('/app/user/updateUser', data).then(res => {
  142. if (res.code == 0) {
  143. uni.hideLoading();
  144. this.$queue.showToast('修改成功!')
  145. this.content = '';
  146. setTimeout(d => {
  147. uni.navigateBack();
  148. }, 1000);
  149. } else {
  150. uni.hideLoading();
  151. this.$queue.showToast(res.msg)
  152. }
  153. });
  154. }
  155. }
  156. }
  157. });
  158. },
  159. getDetailMsg() {
  160. if (this.type1 == 1) {
  161. this.$Request.get("/app/user/selectUserById").then(res => {
  162. if (res.code == 0) {
  163. this.content = res.data.msg ? res.data.msg : '';
  164. }
  165. });
  166. } else {
  167. this.$Request.getT('/app/message/selectMessageById?id=' + this.id).then(res => {
  168. if (res.code == 0) {
  169. this.content = res.data.content;
  170. }
  171. });
  172. }
  173. },
  174. save() {
  175. let that = this;
  176. this.$queue.showLoading('上传中...')
  177. if (this.content == '') {
  178. uni.hideLoading();
  179. this.$queue.showToast('请输入信息内容!')
  180. return;
  181. }
  182. // 添加常用语 分类传个20吧 state ,再传userId content内容应该就行
  183. let userId = this.$queue.getData('userId');
  184. let data = {
  185. state: 20,
  186. userId: userId,
  187. content: this.content
  188. }
  189. if (this.type1 == 0) {
  190. this.$Request.postJson('/app/message/insertMessage', data).then(res => {
  191. if (res.code == 0) {
  192. uni.hideLoading();
  193. this.$queue.showToast('添加成功!')
  194. this.content = '';
  195. setTimeout(d => {
  196. uni.navigateBack();
  197. }, 1000);
  198. } else {
  199. uni.hideLoading();
  200. this.$queue.showToast(res.msg)
  201. }
  202. });
  203. } else {
  204. let data = {
  205. msg: this.content
  206. }
  207. this.$Request.postJson('/app/user/updateUser', data).then(res => {
  208. if (res.code == 0) {
  209. uni.hideLoading();
  210. this.$queue.showToast('添加成功!')
  211. this.content = '';
  212. setTimeout(d => {
  213. uni.navigateBack();
  214. }, 1000);
  215. } else {
  216. uni.hideLoading();
  217. this.$queue.showToast(res.msg)
  218. }
  219. });
  220. }
  221. }
  222. }
  223. }
  224. </script>
  225. <style lang="scss">
  226. page {
  227. background-color: #F5F5F5;
  228. }
  229. .bg {
  230. background-color: #FFFFFF;
  231. }
  232. </style>