index.js 8.0 KB

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