newAndChange.js 11 KB

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