newAndChange.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel;
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. tnoticeid: 0, //通告id
  15. ftitle: "", //通告标题
  16. fsummary: "", //概述
  17. fcontent: "", //通告内容
  18. ftype: "", //通告类型
  19. popups: false,
  20. errTips: {
  21. ftitle: false,
  22. fsummary: false,
  23. fcontent: false
  24. }
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. },
  31. /* 提交代码 */
  32. submit() {
  33. if (!this.formVerify()) return wx.showToast({
  34. title: '请检查表单内容',
  35. icon: "error"
  36. });
  37. _Http.basic({
  38. "accesstoken": wx.getStorageSync('userData').token,
  39. "classname": "customer.noticemag.noticemag",
  40. "method": "insertOrModify",
  41. "content": {
  42. "tnoticeid": this.data.tnoticeid,
  43. "ftype": this.data.ftype,
  44. "ftitle": this.data.ftitle,
  45. "fsummary": this.data.fsummary,
  46. "fcontent": this.data.fcontent,
  47. }
  48. }).then(res => {
  49. console.log(res)
  50. if (res.msg != '成功') return wx.showToast({
  51. title: res.data,
  52. icon: "none"
  53. });
  54. wx.showToast({
  55. title: '保存成功',
  56. });
  57. let content = {
  58. ownerid: res.data[0].tnoticeid,
  59. ownertable: "tnotice",
  60. tattachmentid: 0
  61. };
  62. this.selectComponent("#UploadFiles").saveTheChanges(content);
  63. this.selectComponent("#UpFiles").saveTheChanges(content);
  64. setTimeout(() => {
  65. wx.navigateBack()
  66. }, 500)
  67. })
  68. },
  69. /* 表单验证 */
  70. formVerify() {
  71. let errTips = this.data.errTips,
  72. verify = true;
  73. /* 验证标题 */
  74. if (!_Verify.required(this.data.ftitle)) {
  75. errTips.ftitle = true;
  76. verify = false;
  77. }
  78. /* 验证概述 */
  79. if (!_Verify.required(this.data.fsummary)) {
  80. errTips.fsummary = true;
  81. verify = false;
  82. }
  83. /* 验证内容 */
  84. if (!_Verify.required(this.data.fcontent)) {
  85. errTips.fcontent = true;
  86. verify = false;
  87. }
  88. this.setData({
  89. errTips
  90. })
  91. return verify;
  92. },
  93. /* 获取焦点 */
  94. inputFocus(e) {
  95. const {
  96. name
  97. } = e.currentTarget.dataset;
  98. let errTips = this.data.errTips;
  99. errTips[name] = false;
  100. this.setData({
  101. errTips
  102. })
  103. },
  104. /* 失去焦点 */
  105. inputBlur(e) {
  106. const {
  107. name
  108. } = e.currentTarget.dataset;
  109. const {
  110. value
  111. } = e.detail;
  112. if (value.trim() == "") {
  113. let errTips = this.data.errTips;
  114. errTips[name] = true;
  115. this.setData({
  116. errTips
  117. })
  118. }
  119. },
  120. /* input事件剔除特殊字符 */
  121. eliminate(value) {
  122. const {
  123. name
  124. } = value.target.dataset;
  125. this.setData({
  126. [name]: _Verify.Eliminate(value.detail)
  127. })
  128. },
  129. /* 发布范围回调 */
  130. radioChange({
  131. detail
  132. }) {
  133. this.setData({
  134. ftype: detail,
  135. popups: false
  136. })
  137. },
  138. /* 打开类目选择 */
  139. showPop() {
  140. this.setData({
  141. popups: !this.data.popups
  142. })
  143. },
  144. /* 跳转富文本 */
  145. toRichText() {
  146. const that = this;
  147. const fcontent = encodeURIComponent(this.data.fcontent);
  148. wx.navigateTo({
  149. url: '/pages/storeMessage/editor/editor?fintroduction=' + fcontent,
  150. events: {
  151. richTextCallBack: function (richText) {
  152. let fcontent = null;
  153. (richText.richText == '<p><br></p>') ? fcontent = "": fcontent = richText.richText;
  154. that.setData({
  155. fcontent: fcontent,
  156. 'errTips.fcontent': false
  157. })
  158. }
  159. }
  160. })
  161. },
  162. /**
  163. * 生命周期函数--监听页面初次渲染完成
  164. */
  165. onReady: function () {
  166. },
  167. /**
  168. * 生命周期函数--监听页面显示
  169. */
  170. onShow: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面隐藏
  174. */
  175. onHide: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面卸载
  179. */
  180. onUnload: function () {
  181. },
  182. /**
  183. * 页面相关事件处理函数--监听用户下拉动作
  184. */
  185. onPullDownRefresh: function () {
  186. },
  187. /**
  188. * 页面上拉触底事件的处理函数
  189. */
  190. onReachBottom: function () {
  191. },
  192. /**
  193. * 用户点击右上角分享
  194. */
  195. onShareAppMessage: function () {
  196. }
  197. })