newAndChange.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. checkboxShow: false, //多选
  21. fisspecifiedrange: 0, // 是否指定范围,0否 1 是
  22. include: [], //包含范围
  23. partnerList: [], //合作商列表
  24. coverFiles: [], //封面
  25. defaultFiles: [], //附件
  26. errTips: {
  27. ftitle: false,
  28. fsummary: false,
  29. fcontent: false,
  30. ftype: false
  31. }
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. //修改
  38. if (options.id) {
  39. _Http.basic({
  40. "accesstoken": wx.getStorageSync('userData').token,
  41. "classname": "customer.noticemag.noticemag",
  42. "method": "query_noticeMain",
  43. "content": {
  44. "tnoticeid": options.id
  45. }
  46. }).then(res => {
  47. console.log("详情", res)
  48. if (res.msg != '成功') return wx.showToast({
  49. title: res.data,
  50. icon: "none"
  51. });
  52. let data = res.data[0],
  53. attinfos = res.data[0].attinfos,
  54. coverFiles = [],
  55. defaultFiles = [],
  56. ftype = (data.ftype == '商户') ? '合作商通告' : '团队通告';
  57. for (let i = 0; i < attinfos.length; i++) {
  58. let img = {
  59. name: attinfos[i].serialnumber,
  60. url: attinfos[i].fobsurl,
  61. ownerid: attinfos[i].ownerid,
  62. tattachmentid: attinfos[i].tattachmentid,
  63. ftype: attinfos[i].ftype,
  64. ownertable: attinfos[i].ownertable
  65. };
  66. (img.ftype == "default") ? defaultFiles.push(img): coverFiles.push(img)
  67. }
  68. if (data.ftype == '商户' && data.fisspecifiedrange == 1) {
  69. //查询指定范围
  70. _Http.basic({
  71. "accesstoken": wx.getStorageSync('userData').token,
  72. "classname": "customer.noticemag.noticemag",
  73. "method": "query_noticeuserList",
  74. "content": {
  75. "tnoticeid": options.id
  76. }
  77. }).then(s => {
  78. console.log("查询范围", s)
  79. if (s.msg != '成功') return wx.showToast({
  80. title: res.data,
  81. icon: "none"
  82. });
  83. let include = [];
  84. for (let i = 0; i < s.data.length; i++) {
  85. include.push(s.data[i].tagentsid)
  86. }
  87. this.setData({
  88. include
  89. })
  90. })
  91. }
  92. this.setData({
  93. tnoticeid: data.tnoticeid,
  94. ftitle: data.ftitle,
  95. fsummary: data.fsummary,
  96. fcontent: data.fcontent,
  97. ftype: ftype,
  98. coverFiles,
  99. defaultFiles,
  100. fisspecifiedrange: data.fisspecifiedrange
  101. })
  102. })
  103. }
  104. },
  105. //范围选择回调
  106. scopeCallBack({
  107. detail
  108. }) {
  109. let data = JSON.parse(detail);
  110. console.log(data)
  111. if (data.isAll == 0) {
  112. this.setData({
  113. fisspecifiedrange: data.isAll,
  114. checkboxShow: false
  115. })
  116. } else {
  117. this.setData({
  118. deleteList: data.deleteItem,
  119. include: data.include,
  120. fisspecifiedrange: data.isAll,
  121. checkboxShow: false
  122. })
  123. }
  124. },
  125. /* 修改图片回调 */
  126. imageChange(e) {
  127. const {
  128. fileList
  129. } = e.detail;
  130. this.setData({
  131. coverFiles: fileList
  132. })
  133. },
  134. /* 修改附加回调 */
  135. filesChange(e) {
  136. const {
  137. fileList
  138. } = e.detail;
  139. this.setData({
  140. defaultFiles: fileList
  141. })
  142. },
  143. /* 提交 */
  144. submit() {
  145. if (!this.formVerify()) return wx.showToast({
  146. title: '请检查表单内容',
  147. icon: "error"
  148. });
  149. let ftype = (this.data.ftype == '团队通告') ? '团队' : '商户';
  150. _Http.basic({
  151. "accesstoken": wx.getStorageSync('userData').token,
  152. "classname": "customer.noticemag.noticemag",
  153. "method": "insertOrModify",
  154. "content": {
  155. "tnoticeid": this.data.tnoticeid,
  156. "ftype": ftype,
  157. "ftitle": this.data.ftitle,
  158. "fisspecifiedrange": this.data.fisspecifiedrange,
  159. "fsummary": this.data.fsummary,
  160. "fcontent": this.data.fcontent,
  161. }
  162. }).then(res => {
  163. console.log("新增或修改", res)
  164. if (res.msg != '成功') return wx.showToast({
  165. title: res.data,
  166. icon: "none"
  167. });
  168. if (this.data.tnoticeid == 0) _Http.basic({
  169. "accesstoken": wx.getStorageSync('userData').token,
  170. "classname": "customer.noticemag.noticemag",
  171. "method": "check",
  172. "content": {
  173. "tnoticeid": res.data[0].tnoticeid,
  174. "fischeck": 1
  175. }
  176. }).then(s => {
  177. console.log("修改上架", s)
  178. })
  179. //指定范围,删除
  180. if (ftype == '商户') {
  181. if (this.data.fisspecifiedrange == 1) {
  182. //默认新增
  183. let body = {
  184. "accesstoken": wx.getStorageSync('userData').token,
  185. "classname": "customer.noticemag.noticemag",
  186. "method": "adduser",
  187. "content": {
  188. "tnoticeid": res.data[0].tnoticeid,
  189. "tagentsid": this.data.include
  190. }
  191. }
  192. console.log(this.data.include)
  193. _Http.basic(body).then(res => {
  194. console.log("添加范围", res)
  195. });
  196. //删除
  197. let deleteList = this.data.deleteList;
  198. body.method = 'deleteuser';
  199. body.content.tagentsid = deleteList;
  200. if (deleteList.length >= 1) {
  201. _Http.basic(body).then(res => {
  202. console.log("删除范围", res)
  203. });
  204. }
  205. }
  206. }
  207. wx.showToast({
  208. title: '保存成功',
  209. });
  210. let content = {
  211. ownerid: res.data[0].tnoticeid,
  212. ownertable: "tnotice",
  213. tattachmentid: 0
  214. };
  215. this.selectComponent("#UploadFiles").saveTheChanges(content);
  216. this.selectComponent("#UpFiles").saveTheChanges(content);
  217. setTimeout(() => {
  218. wx.navigateBack()
  219. }, 500)
  220. })
  221. },
  222. /* 表单验证 */
  223. formVerify() {
  224. let errTips = this.data.errTips,
  225. verify = true;
  226. /* 验证标题 */
  227. if (!_Verify.required(this.data.ftitle)) {
  228. errTips.ftitle = true;
  229. verify = false;
  230. }
  231. /* 验证概述 */
  232. if (!_Verify.required(this.data.fsummary)) {
  233. errTips.fsummary = true;
  234. verify = false;
  235. }
  236. /* 验证内容 */
  237. if (!_Verify.required(this.data.fcontent)) {
  238. errTips.fcontent = true;
  239. verify = false;
  240. }
  241. /* 发布范围 */
  242. if (!_Verify.required(this.data.ftype)) {
  243. errTips.ftype = true;
  244. verify = false;
  245. }
  246. this.setData({
  247. errTips
  248. })
  249. return verify;
  250. },
  251. /* 获取焦点 */
  252. inputFocus(e) {
  253. const {
  254. name
  255. } = e.currentTarget.dataset;
  256. let errTips = this.data.errTips;
  257. errTips[name] = false;
  258. this.setData({
  259. errTips
  260. })
  261. },
  262. /* 失去焦点 */
  263. inputBlur(e) {
  264. const {
  265. name
  266. } = e.currentTarget.dataset;
  267. const {
  268. value
  269. } = e.detail;
  270. if (value.trim() == "") {
  271. let errTips = this.data.errTips;
  272. errTips[name] = true;
  273. this.setData({
  274. errTips
  275. })
  276. }
  277. },
  278. /* input事件剔除特殊字符 */
  279. eliminate(value) {
  280. const {
  281. name
  282. } = value.target.dataset;
  283. this.setData({
  284. [name]: _Verify.Eliminate(value.detail)
  285. })
  286. },
  287. /* 发布范围回调 */
  288. radioChange({
  289. detail
  290. }) {
  291. let ftype = (detail.length != 0) ? detail : this.data.ftype;
  292. console.log(ftype)
  293. this.setData({
  294. ftype,
  295. popups: false,
  296. 'errTips.ftype': false
  297. })
  298. },
  299. /* 打开类目选择 */
  300. showPop() {
  301. this.setData({
  302. popups: !this.data.popups
  303. })
  304. },
  305. checkboxShowPop() {
  306. this.setData({
  307. checkboxShow: !this.data.checkboxShow
  308. })
  309. },
  310. /* 跳转富文本 */
  311. toRichText() {
  312. const that = this;
  313. const fcontent = encodeURIComponent(this.data.fcontent);
  314. wx.navigateTo({
  315. url: '/pages/storeMessage/editor/editor?fintroduction=' + fcontent,
  316. events: {
  317. richTextCallBack: function (richText) {
  318. let fcontent = null;
  319. (richText.richText == '<p><br></p>') ? fcontent = "": fcontent = richText.richText;
  320. that.setData({
  321. fcontent: fcontent,
  322. 'errTips.fcontent': false
  323. })
  324. }
  325. }
  326. })
  327. },
  328. /**
  329. * 生命周期函数--监听页面初次渲染完成
  330. */
  331. onReady: function () {
  332. },
  333. /**
  334. * 生命周期函数--监听页面显示
  335. */
  336. onShow: function () {
  337. },
  338. /**
  339. * 生命周期函数--监听页面隐藏
  340. */
  341. onHide: function () {
  342. },
  343. /**
  344. * 生命周期函数--监听页面卸载
  345. */
  346. onUnload: function () {
  347. },
  348. /**
  349. * 页面相关事件处理函数--监听用户下拉动作
  350. */
  351. onPullDownRefresh: function () {
  352. },
  353. /**
  354. * 页面上拉触底事件的处理函数
  355. */
  356. onReachBottom: function () {
  357. },
  358. /**
  359. * 用户点击右上角分享
  360. */
  361. onShareAppMessage: function () {
  362. }
  363. })