newAndChange.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. coverFiles: [], //封面
  21. defaultFiles: [], //附件
  22. errTips: {
  23. ftitle: false,
  24. fsummary: false,
  25. fcontent: false,
  26. ftype: false
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. //修改
  34. if (options.id) {
  35. _Http.basic({
  36. "accesstoken": wx.getStorageSync('userData').token,
  37. "classname": "customer.noticemag.noticemag",
  38. "method": "query_noticeMain",
  39. "content": {
  40. "tnoticeid": options.id
  41. }
  42. }).then(res => {
  43. console.log(res)
  44. if (res.msg != '成功') return wx.showToast({
  45. title: res.data,
  46. icon: "none"
  47. });
  48. let data = res.data[0],
  49. attinfos = res.data[0].attinfos,
  50. coverFiles = [],
  51. defaultFiles = [],
  52. ftype = (data.ftype == '商户') ? '商户公告' : '团队公告';
  53. for (let i = 0; i < attinfos.length; i++) {
  54. let img = {
  55. name: attinfos[i].serialnumber,
  56. url: attinfos[i].fobsurl,
  57. ownerid: attinfos[i].ownerid,
  58. tattachmentid: attinfos[i].tattachmentid,
  59. ftype: attinfos[i].ftype,
  60. ownertable: attinfos[i].ownertable
  61. };
  62. (img.ftype == "default") ? defaultFiles.push(img): coverFiles.push(img)
  63. }
  64. this.setData({
  65. tnoticeid: data.tnoticeid,
  66. ftitle: data.ftitle,
  67. fsummary: data.fsummary,
  68. fcontent: data.fcontent,
  69. ftype: ftype,
  70. coverFiles,
  71. defaultFiles
  72. })
  73. })
  74. }
  75. },
  76. /* 修改图片回调 */
  77. imageChange(e) {
  78. const {
  79. fileList
  80. } = e.detail;
  81. this.setData({
  82. coverFiles: fileList
  83. })
  84. },
  85. /* 修改附加回调 */
  86. filesChange(e) {
  87. const {
  88. fileList
  89. } = e.detail;
  90. this.setData({
  91. defaultFiles: fileList
  92. })
  93. },
  94. /* 提交代码 */
  95. submit() {
  96. if (!this.formVerify()) return wx.showToast({
  97. title: '请检查表单内容',
  98. icon: "error"
  99. });
  100. let ftype = (this.data.ftype == '团队公告') ? '团队' : '商户';
  101. _Http.basic({
  102. "accesstoken": wx.getStorageSync('userData').token,
  103. "classname": "customer.noticemag.noticemag",
  104. "method": "insertOrModify",
  105. "content": {
  106. "tnoticeid": this.data.tnoticeid,
  107. "ftype": ftype,
  108. "ftitle": this.data.ftitle,
  109. "fsummary": this.data.fsummary,
  110. "fcontent": this.data.fcontent,
  111. }
  112. }).then(res => {
  113. console.log(res)
  114. if (res.msg != '成功') return wx.showToast({
  115. title: res.data,
  116. icon: "none"
  117. });
  118. wx.showToast({
  119. title: '保存成功',
  120. });
  121. let content = {
  122. ownerid: res.data[0].tnoticeid,
  123. ownertable: "tnotice",
  124. tattachmentid: 0
  125. };
  126. this.selectComponent("#UploadFiles").saveTheChanges(content);
  127. this.selectComponent("#UpFiles").saveTheChanges(content);
  128. setTimeout(() => {
  129. wx.navigateBack()
  130. }, 500)
  131. })
  132. },
  133. /* 表单验证 */
  134. formVerify() {
  135. let errTips = this.data.errTips,
  136. verify = true;
  137. /* 验证标题 */
  138. if (!_Verify.required(this.data.ftitle)) {
  139. errTips.ftitle = true;
  140. verify = false;
  141. }
  142. /* 验证概述 */
  143. if (!_Verify.required(this.data.fsummary)) {
  144. errTips.fsummary = true;
  145. verify = false;
  146. }
  147. /* 验证内容 */
  148. if (!_Verify.required(this.data.fcontent)) {
  149. errTips.fcontent = true;
  150. verify = false;
  151. }
  152. /* 发布范围 */
  153. if (!_Verify.required(this.data.ftype)) {
  154. errTips.ftype = true;
  155. verify = false;
  156. }
  157. this.setData({
  158. errTips
  159. })
  160. return verify;
  161. },
  162. /* 获取焦点 */
  163. inputFocus(e) {
  164. const {
  165. name
  166. } = e.currentTarget.dataset;
  167. let errTips = this.data.errTips;
  168. errTips[name] = false;
  169. this.setData({
  170. errTips
  171. })
  172. },
  173. /* 失去焦点 */
  174. inputBlur(e) {
  175. const {
  176. name
  177. } = e.currentTarget.dataset;
  178. const {
  179. value
  180. } = e.detail;
  181. if (value.trim() == "") {
  182. let errTips = this.data.errTips;
  183. errTips[name] = true;
  184. this.setData({
  185. errTips
  186. })
  187. }
  188. },
  189. /* input事件剔除特殊字符 */
  190. eliminate(value) {
  191. const {
  192. name
  193. } = value.target.dataset;
  194. this.setData({
  195. [name]: _Verify.Eliminate(value.detail)
  196. })
  197. },
  198. /* 发布范围回调 */
  199. radioChange({
  200. detail
  201. }) {
  202. this.setData({
  203. ftype: detail,
  204. popups: false,
  205. 'errTips.ftype': false
  206. })
  207. },
  208. /* 打开类目选择 */
  209. showPop() {
  210. this.setData({
  211. popups: !this.data.popups
  212. })
  213. },
  214. /* 跳转富文本 */
  215. toRichText() {
  216. const that = this;
  217. const fcontent = encodeURIComponent(this.data.fcontent);
  218. wx.navigateTo({
  219. url: '/pages/storeMessage/editor/editor?fintroduction=' + fcontent,
  220. events: {
  221. richTextCallBack: function (richText) {
  222. let fcontent = null;
  223. (richText.richText == '<p><br></p>') ? fcontent = "": fcontent = richText.richText;
  224. that.setData({
  225. fcontent: fcontent,
  226. 'errTips.fcontent': false
  227. })
  228. }
  229. }
  230. })
  231. },
  232. /**
  233. * 生命周期函数--监听页面初次渲染完成
  234. */
  235. onReady: function () {
  236. },
  237. /**
  238. * 生命周期函数--监听页面显示
  239. */
  240. onShow: function () {
  241. },
  242. /**
  243. * 生命周期函数--监听页面隐藏
  244. */
  245. onHide: function () {
  246. },
  247. /**
  248. * 生命周期函数--监听页面卸载
  249. */
  250. onUnload: function () {
  251. },
  252. /**
  253. * 页面相关事件处理函数--监听用户下拉动作
  254. */
  255. onPullDownRefresh: function () {
  256. },
  257. /**
  258. * 页面上拉触底事件的处理函数
  259. */
  260. onReachBottom: function () {
  261. },
  262. /**
  263. * 用户点击右上角分享
  264. */
  265. onShareAppMessage: function () {
  266. }
  267. })