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