index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. showCalendar: false, //日历显示
  15. tsupplyanddemandid: 0, //ID 0为新增
  16. popups: false, //弹出层控制
  17. ftype: "", //供需类型
  18. ftitle: "", //供需标题
  19. fcontent: "", //需求内容
  20. fenddate: "", //截止日期
  21. throttle:false,//节流阀
  22. /* 必填 */
  23. errTips: {
  24. ftype: false,
  25. ftitle: false,
  26. fcontent: false
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. if (options.data != undefined) {
  34. const data = JSON.parse(options.data);
  35. let attinfos = [];
  36. for (let i = 0; i < data.attinfos.length; i++) {
  37. let arr = {
  38. url: data.attinfos[i].fobsurl,
  39. ownerid: data.attinfos[i].ownerid,
  40. tattachmentid: data.attinfos[i].tattachmentid,
  41. ownertable: data.attinfos[i].ownertable,
  42. fdocument: data.attinfos[i].fdocument
  43. }
  44. attinfos.push(arr)
  45. };
  46. this.setData({
  47. ftype: data.ftype, //供需类型
  48. ftitle: data.ftitle, //供需标题
  49. fcontent: data.fcontent, //需求内容
  50. fenddate: data.fenddate, //截止日期
  51. attinfos, //附件列表
  52. tsupplyanddemandid: data.tsupplyanddemandid, //ID 0为新增
  53. })
  54. }
  55. },
  56. /* 添加图片 */
  57. imageChange(data) {
  58. this.setData({
  59. attinfos: data.detail.fileList
  60. })
  61. },
  62. /* 打开时间选择器 */
  63. setDate() {
  64. this.selectComponent("#SetDate").dateOnClose()
  65. },
  66. /* 设置下架 */
  67. setSoldOut(date) {
  68. this.setData({
  69. fenddate: date.detail
  70. })
  71. },
  72. /* 表单验证 */
  73. formVerify() {
  74. let errTips = this.data.errTips,
  75. verify = true;
  76. /* 验证分类 */
  77. if (!_Verify.required(this.data.ftype)) {
  78. errTips.ftype = true;
  79. verify = false;
  80. }
  81. /* 验证标题 */
  82. if (!_Verify.required(this.data.ftitle)) {
  83. errTips.ftitle = true;
  84. verify = false;
  85. }
  86. /* 验证内容 */
  87. if (!_Verify.required(this.data.fcontent)) {
  88. errTips.fcontent = true;
  89. verify = false;
  90. }
  91. this.setData({
  92. errTips
  93. })
  94. return verify;
  95. },
  96. /* 提交 */
  97. submit() {
  98. if (!this.formVerify()) return wx.showToast({
  99. title: '请检查表单内容',
  100. icon: "error"
  101. });
  102. if(this.data.throttle) return;
  103. this.addOrModify()
  104. },
  105. /* 新增或修改 */
  106. addOrModify() {
  107. /* 发送请求 */
  108. _Http.basic({
  109. "accesstoken": wx.getStorageSync('userData').token,
  110. "classname": "customer.supplyanddemand.supplyanddemand",
  111. "method": "insertormodify",
  112. "content": {
  113. "tsupplyanddemandid": this.data.tsupplyanddemandid,
  114. "ftype": this.data.ftype,
  115. "ftitle": this.data.ftitle,
  116. "fcontent": this.data.fcontent,
  117. "fenddate": this.data.fenddate,
  118. "fissupply": 0
  119. }
  120. }).then(res => {
  121. console.log(res)
  122. if (res.msg != "成功") return wx.showToast({
  123. title: res.data,
  124. icon: "none"
  125. });
  126. this.setData({
  127. throttle:true
  128. })
  129. let content = {
  130. ownerid: res.data[0].tsupplyanddemandid,
  131. ownertable: "tsupplyanddemand",
  132. tattachmentid: 0
  133. };
  134. this.selectComponent("#UploadFiles").saveTheChanges(content);
  135. if (res.data[0].fstatus == '新建') {
  136. _Http.basic({
  137. "accesstoken": wx.getStorageSync('userData').token,
  138. "classname": "customer.supplyanddemand.supplyanddemand",
  139. "method": "updatesupplyanddemandstatus",
  140. "content": {
  141. "tsupplyanddemandid": res.data[0].tsupplyanddemandid,
  142. "fstatus": "发布"
  143. }
  144. }).then(res => {
  145. console.log(res)
  146. })
  147. }
  148. wx.showToast({
  149. title: '保存成功',
  150. })
  151. setTimeout(() => {
  152. wx.navigateBack({
  153. delta: 1,
  154. })
  155. }, 500)
  156. })
  157. },
  158. /* 弹出层 */
  159. showPop() {
  160. this.setData({
  161. popups: !this.data.popups
  162. })
  163. },
  164. /* 单选改变 */
  165. radioChange(value) {
  166. this.setData({
  167. ftype: value.detail,
  168. popups: false,
  169. "errTips.ftype": false
  170. })
  171. },
  172. /* 获取焦点 */
  173. inputFocus(e) {
  174. const {
  175. name
  176. } = e.currentTarget.dataset;
  177. let errTips = this.data.errTips;
  178. errTips[name] = false;
  179. this.setData({
  180. errTips
  181. })
  182. },
  183. /* 失去焦点 */
  184. inputBlur(e) {
  185. const {
  186. name
  187. } = e.currentTarget.dataset;
  188. const {
  189. value
  190. } = e.detail;
  191. if (value.trim() == "") {
  192. let errTips = this.data.errTips;
  193. errTips[name] = true;
  194. this.setData({
  195. errTips
  196. })
  197. }
  198. },
  199. /**
  200. * 生命周期函数--监听页面初次渲染完成
  201. */
  202. onReady: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload: function () {},
  218. /**
  219. * 页面相关事件处理函数--监听用户下拉动作
  220. */
  221. onPullDownRefresh: function () {
  222. },
  223. /**
  224. * 页面上拉触底事件的处理函数
  225. */
  226. onReachBottom: function () {
  227. },
  228. /**
  229. * 用户点击右上角分享
  230. */
  231. onShareAppMessage: function () {
  232. }
  233. })