add.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view>
  3. <!-- 顶部自定义导航栏 -->
  4. <view class="nav-header">
  5. <view class="nav-left" @click="goBack">
  6. <u-icon name="arrow-leftward" color="rgba(56, 58, 63, 1)" size="38"></u-icon>
  7. </view>
  8. <view class="nav-center">
  9. <text class="nav-title">{{ pageTitle }}</text>
  10. </view>
  11. <view class="nav-right" @click="save()">
  12. <text class="save-text">保存</text>
  13. </view>
  14. </view>
  15. <!-- 文本框容器 -->
  16. <view class="textarea-container">
  17. <textarea v-model="content" class="content-textarea" placeholder="请输入你的常用语回复,请不要填写任何联系方式或广告信息,否则系统将会封禁您的账号" maxlength="120"
  18. placeholder-style="color: #999999; font-size: 14px; line-height: 1.4;"
  19. style="height: 300upx;width: 100%;text-align: left;background: transparent;padding: 20rpx;border: none;outline: none;"></textarea>
  20. <!-- 文本框内底部文字计数 -->
  21. <view class="inner-counter">
  22. <text class="counter-text">{{content.length}}/120</text>
  23. </view>
  24. </view>
  25. <view class="padding-lr-sm" v-if="type == 0">
  26. <u-button :custom-style="customStyle1" :hair-line="false" @click="save()">
  27. 添加
  28. </u-button>
  29. </view>
  30. <view class="padding-lr-sm" style="margin-top: 100rpx;display: flex;" v-if="type == 1">
  31. <u-button style="width: 48%;margin-right: 20rpx;" :custom-style="customStyle2" :hair-line="false"
  32. @click="deleteMsg()">
  33. 删除
  34. </u-button>
  35. <u-button style="width: 48%;" :custom-style="customStyle1" :hair-line="false" @click="updateMsg()">
  36. 保存
  37. </u-button>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. customStyle1: {
  46. backgroundColor: "#00B88F",
  47. border: 0,
  48. color: "#FFF",
  49. height: '98rpx'
  50. },
  51. customStyle2: {
  52. backgroundColor: "#ffffff",
  53. border: 0,
  54. color: "#000",
  55. height: '98rpx'
  56. },
  57. id: '',
  58. type1: 0, //0,常用语,1,自动回复
  59. type: 0, //0,添加 1,编辑
  60. content: '',
  61. pageTitle: '自定义招呼语' // 页面标题
  62. }
  63. },
  64. onLoad(d) {
  65. this.type = d.type;
  66. // 处理页面标题
  67. if (d.title) {
  68. // 如果有自定义标题,使用自定义标题
  69. this.pageTitle = d.title;
  70. } else if (d.type == 1) {
  71. // 如果是编辑模式且没有自定义标题,使用默认编辑标题
  72. this.pageTitle = '编辑信息';
  73. }
  74. this.type1 = d.type1;
  75. if (this.type1 == 1) {
  76. this.getDetailMsg();
  77. }
  78. if (d.id) {
  79. this.id = d.id;
  80. this.getDetailMsg();
  81. }
  82. },
  83. methods: {
  84. // 返回上一页
  85. goBack() {
  86. uni.navigateBack()
  87. },
  88. deleteMsg() {
  89. let userId = this.$queue.getData('userId');
  90. uni.showModal({
  91. title: '温馨提示',
  92. content: '您确认要删除当前信息吗?',
  93. showCancel: true,
  94. cancelText: '取消',
  95. confirmText: '确认',
  96. success: res => {
  97. if (res.confirm) {
  98. if (this.type1 == 0) {
  99. this.$Request.postT('/app/message/deleteMessage?id=' + this.id).then(res => {
  100. if (res.code == 0) {
  101. uni.hideLoading();
  102. this.$queue.showToast('删除成功!')
  103. this.content = '';
  104. setTimeout(d => {
  105. uni.navigateBack();
  106. }, 1000);
  107. } else {
  108. uni.hideLoading();
  109. this.$queue.showToast(res.msg)
  110. }
  111. });
  112. } else {
  113. let data = {
  114. msg: ''
  115. }
  116. this.$Request.postJson('/app/user/updateUser', data).then(res => {
  117. if (res.code == 0) {
  118. uni.hideLoading();
  119. this.$queue.showToast('删除成功!')
  120. this.content = '';
  121. setTimeout(d => {
  122. uni.navigateBack();
  123. }, 1000);
  124. } else {
  125. uni.hideLoading();
  126. this.$queue.showToast(res.msg)
  127. }
  128. });
  129. }
  130. }
  131. }
  132. });
  133. },
  134. updateMsg() {
  135. let userId = this.$queue.getData('userId');
  136. let data = {
  137. state: 20,
  138. userId: userId,
  139. content: this.content,
  140. id: this.id
  141. }
  142. uni.showModal({
  143. title: '温馨提示',
  144. content: '您确认要修改当前信息吗?',
  145. showCancel: true,
  146. cancelText: '取消',
  147. confirmText: '确认',
  148. success: res => {
  149. if (res.confirm) {
  150. if (this.type1 == 0) {
  151. this.$Request.postJson('/app/message/updateMessage', data).then(res => {
  152. if (res.code == 0) {
  153. uni.hideLoading();
  154. this.$queue.showToast('修改成功!')
  155. this.content = '';
  156. setTimeout(d => {
  157. uni.navigateBack();
  158. }, 1000);
  159. } else {
  160. uni.hideLoading();
  161. this.$queue.showToast(res.msg)
  162. }
  163. });
  164. } else {
  165. let data = {
  166. msg: this.content
  167. }
  168. this.$Request.postJson('/app/user/updateUser', data).then(res => {
  169. if (res.code == 0) {
  170. uni.hideLoading();
  171. this.$queue.showToast('修改成功!')
  172. this.content = '';
  173. setTimeout(d => {
  174. uni.navigateBack();
  175. }, 1000);
  176. } else {
  177. uni.hideLoading();
  178. this.$queue.showToast(res.msg)
  179. }
  180. });
  181. }
  182. }
  183. }
  184. });
  185. },
  186. getDetailMsg() {
  187. if (this.type1 == 1) {
  188. this.$Request.get("/app/user/selectUserById").then(res => {
  189. if (res.code == 0) {
  190. this.content = res.data.msg ? res.data.msg : '';
  191. }
  192. });
  193. } else {
  194. this.$Request.getT('/app/message/selectMessageById?id=' + this.id).then(res => {
  195. if (res.code == 0) {
  196. this.content = res.data.content;
  197. }
  198. });
  199. }
  200. },
  201. save() {
  202. let that = this;
  203. this.$queue.showLoading('上传中...')
  204. if (this.content == '') {
  205. uni.hideLoading();
  206. this.$queue.showToast('请输入信息内容!')
  207. return;
  208. }
  209. // 添加常用语 分类传个20吧 state ,再传userId content内容应该就行
  210. let userId = this.$queue.getData('userId');
  211. let data = {
  212. state: 20,
  213. userId: userId,
  214. content: this.content
  215. }
  216. if (this.type1 == 0) {
  217. this.$Request.postJson('/app/message/insertMessage', data).then(res => {
  218. if (res.code == 0) {
  219. uni.hideLoading();
  220. this.$queue.showToast('添加成功!')
  221. this.content = '';
  222. setTimeout(d => {
  223. uni.navigateBack();
  224. }, 1000);
  225. } else {
  226. uni.hideLoading();
  227. this.$queue.showToast(res.msg)
  228. }
  229. });
  230. } else {
  231. let data = {
  232. msg: this.content
  233. }
  234. this.$Request.postJson('/app/user/updateUser', data).then(res => {
  235. if (res.code == 0) {
  236. uni.hideLoading();
  237. this.$queue.showToast('添加成功!')
  238. this.content = '';
  239. setTimeout(d => {
  240. uni.navigateBack();
  241. }, 1000);
  242. } else {
  243. uni.hideLoading();
  244. this.$queue.showToast(res.msg)
  245. }
  246. });
  247. }
  248. }
  249. }
  250. }
  251. </script>
  252. <style lang="scss">
  253. page {
  254. padding-top: 80rpx;
  255. }
  256. // 顶部自定义导航栏样式
  257. .nav-header {
  258. height: 80rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. padding: 0 20rpx;
  263. background: #FFFFFF;
  264. }
  265. .nav-left {
  266. width: 60rpx;
  267. display: flex;
  268. justify-content: flex-start;
  269. }
  270. .nav-center {
  271. flex: 1;
  272. display: flex;
  273. justify-content: center;
  274. }
  275. .nav-title {
  276. color: rgba(51, 51, 51, 1);
  277. font-family: DM Sans;
  278. font-size: 18px;
  279. font-weight: 700;
  280. line-height: 26px;
  281. letter-spacing: 0%;
  282. text-align: center;
  283. }
  284. .nav-right {
  285. width: 60rpx;
  286. display: flex;
  287. justify-content: flex-end;
  288. align-items: center;
  289. }
  290. .save-text {
  291. color: rgba(51, 51, 51, 1);
  292. font-family: DM Sans;
  293. font-size: 14px;
  294. font-weight: 400;
  295. line-height: 26px;
  296. letter-spacing: 0%;
  297. text-align: center;
  298. }
  299. // 文本框容器样式
  300. .textarea-container {
  301. position: relative;
  302. width: 95%;
  303. margin: 20rpx;
  304. background: rgba(240, 240, 240, 1);
  305. border-radius: 15rpx;
  306. height: 300upx;
  307. }
  308. .content-textarea {
  309. width: 100%;
  310. height: 100%;
  311. background: transparent;
  312. border: none;
  313. outline: none;
  314. font-size: 28rpx;
  315. color: #333333;
  316. line-height: 1.5;
  317. box-sizing: border-box;
  318. padding: 20rpx;
  319. padding-bottom: 60rpx; /* 为底部计数器留出空间 */
  320. }
  321. // 文本框内底部文字计数样式
  322. .inner-counter {
  323. position: absolute;
  324. bottom: 20rpx;
  325. right: 20rpx;
  326. pointer-events: none; /* 防止影响文本输入 */
  327. }
  328. .counter-text {
  329. color: #999999;
  330. font-size: 24rpx;
  331. font-weight: 400;
  332. }
  333. .bg {
  334. background-color: #FFFFFF;
  335. }
  336. </style>