newAndChange.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. if (this.data.tnoticeid == 0) _Http.basic({
  119. "accesstoken": wx.getStorageSync('userData').token,
  120. "classname": "customer.noticemag.noticemag",
  121. "method": "check",
  122. "content": {
  123. "tnoticeid": res.data[0].tnoticeid,
  124. "fischeck": 1
  125. }
  126. }).then(s => {
  127. console.log("修改上架", s)
  128. })
  129. wx.showToast({
  130. title: '保存成功',
  131. });
  132. let content = {
  133. ownerid: res.data[0].tnoticeid,
  134. ownertable: "tnotice",
  135. tattachmentid: 0
  136. };
  137. this.selectComponent("#UploadFiles").saveTheChanges(content);
  138. this.selectComponent("#UpFiles").saveTheChanges(content);
  139. setTimeout(() => {
  140. wx.navigateBack()
  141. }, 500)
  142. })
  143. },
  144. /* 表单验证 */
  145. formVerify() {
  146. let errTips = this.data.errTips,
  147. verify = true;
  148. /* 验证标题 */
  149. if (!_Verify.required(this.data.ftitle)) {
  150. errTips.ftitle = true;
  151. verify = false;
  152. }
  153. /* 验证概述 */
  154. if (!_Verify.required(this.data.fsummary)) {
  155. errTips.fsummary = true;
  156. verify = false;
  157. }
  158. /* 验证内容 */
  159. if (!_Verify.required(this.data.fcontent)) {
  160. errTips.fcontent = true;
  161. verify = false;
  162. }
  163. /* 发布范围 */
  164. if (!_Verify.required(this.data.ftype)) {
  165. errTips.ftype = true;
  166. verify = false;
  167. }
  168. this.setData({
  169. errTips
  170. })
  171. return verify;
  172. },
  173. /* 获取焦点 */
  174. inputFocus(e) {
  175. const {
  176. name
  177. } = e.currentTarget.dataset;
  178. let errTips = this.data.errTips;
  179. errTips[name] = false;
  180. this.setData({
  181. errTips
  182. })
  183. },
  184. /* 失去焦点 */
  185. inputBlur(e) {
  186. const {
  187. name
  188. } = e.currentTarget.dataset;
  189. const {
  190. value
  191. } = e.detail;
  192. if (value.trim() == "") {
  193. let errTips = this.data.errTips;
  194. errTips[name] = true;
  195. this.setData({
  196. errTips
  197. })
  198. }
  199. },
  200. /* input事件剔除特殊字符 */
  201. eliminate(value) {
  202. const {
  203. name
  204. } = value.target.dataset;
  205. this.setData({
  206. [name]: _Verify.Eliminate(value.detail)
  207. })
  208. },
  209. /* 发布范围回调 */
  210. radioChange({
  211. detail
  212. }) {
  213. this.setData({
  214. ftype: detail,
  215. popups: false,
  216. 'errTips.ftype': false
  217. })
  218. },
  219. /* 打开类目选择 */
  220. showPop() {
  221. this.setData({
  222. popups: !this.data.popups
  223. })
  224. },
  225. /* 跳转富文本 */
  226. toRichText() {
  227. const that = this;
  228. const fcontent = encodeURIComponent(this.data.fcontent);
  229. wx.navigateTo({
  230. url: '/pages/storeMessage/editor/editor?fintroduction=' + fcontent,
  231. events: {
  232. richTextCallBack: function (richText) {
  233. let fcontent = null;
  234. (richText.richText == '<p><br></p>') ? fcontent = "": fcontent = richText.richText;
  235. that.setData({
  236. fcontent: fcontent,
  237. 'errTips.fcontent': false
  238. })
  239. }
  240. }
  241. })
  242. },
  243. /**
  244. * 生命周期函数--监听页面初次渲染完成
  245. */
  246. onReady: function () {
  247. },
  248. /**
  249. * 生命周期函数--监听页面显示
  250. */
  251. onShow: function () {
  252. },
  253. /**
  254. * 生命周期函数--监听页面隐藏
  255. */
  256. onHide: function () {
  257. },
  258. /**
  259. * 生命周期函数--监听页面卸载
  260. */
  261. onUnload: function () {
  262. },
  263. /**
  264. * 页面相关事件处理函数--监听用户下拉动作
  265. */
  266. onPullDownRefresh: function () {
  267. },
  268. /**
  269. * 页面上拉触底事件的处理函数
  270. */
  271. onReachBottom: function () {
  272. },
  273. /**
  274. * 用户点击右上角分享
  275. */
  276. onShareAppMessage: function () {
  277. }
  278. })