newAndChange.js 9.2 KB

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