newAndChange.js 11 KB

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