post.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. // pages/post/post.js
  2. const app = getApp()
  3. const host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. sexArray: ["男","女"], //性别
  10. recordArray: ["小学", "初中", "高中", "大专", "本科","硕士","博士"], //学历
  11. categoryArray: [{ label: '电工', id: 0 }, { label: '水工', id: 1 }], //作业类别
  12. subjectArray: [{name:'请选择'}], //准操项目
  13. trainArray: [{ name: '新办', intro: '第一次取证;或者以前取证了没有按规定的时间复审、换证' },
  14. { name: '复审', intro: '已取证;复审日期一天都不超最好提前3个月' },
  15. { name: '换证', intro: '有效期满提前三个月' }], //培训类型
  16. receiveArray: ['自取','邮寄(将产生邮寄费用)'], //领取类型
  17. sex:0,
  18. record:0,
  19. category:-1,
  20. subject:-1,
  21. train:-1,
  22. receive:0,
  23. area: ['四川省', '成都市', '锦江区'],
  24. time:'2020-01-01',
  25. price:'0.00',
  26. classList:[],
  27. class_:-1,
  28. class_id:0,
  29. data:{}
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. if(options.id){
  36. wx.request({
  37. url: host+'/api/wx/signup',
  38. method:'GET',
  39. data:{id:options.id},
  40. success:res=>{
  41. this.setData({
  42. data: res.data.data
  43. })
  44. }
  45. })
  46. }
  47. if(options.class_id){
  48. this.setData({
  49. class_id: options.class_id,
  50. price: options.price
  51. })
  52. }else{
  53. wx.request({
  54. url: host + '/api/wx/sujectitem',
  55. success: res => {
  56. let list = res.data.data.filter(item => item.name == options.name)
  57. this.setData({
  58. categoryArray: list[0].children,
  59. z_type: options.id
  60. })
  61. }
  62. })
  63. wx.request({
  64. url: host + '/api/wx/class/list',
  65. method: 'GET',
  66. success: res => {
  67. let list = res.data.data.filter(item => item.type == options.name)
  68. this.setData({
  69. classList: list[0].classes
  70. })
  71. }
  72. })
  73. }
  74. },
  75. pickerChange:function(e){
  76. if(e.target.dataset.name == 'sex'){
  77. this.setData({
  78. sex: e.detail.value
  79. })
  80. };
  81. if (e.target.dataset.name == 'record') {
  82. this.setData({
  83. record: e.detail.value
  84. })
  85. };
  86. if (e.target.dataset.name == 'category') {
  87. let list = this.data.categoryArray[e.detail.value].children
  88. this.setData({
  89. category: e.detail.value,
  90. subjectArray: list,
  91. subject:-1,
  92. train:-1
  93. })
  94. };
  95. if (e.target.dataset.name == 'subject') {
  96. this.setData({
  97. subject: e.detail.value,
  98. train: -1
  99. })
  100. };
  101. if (e.target.dataset.name == 'time') {
  102. this.setData({
  103. time: e.detail.value
  104. })
  105. };
  106. if (e.target.dataset.name == 'train') {
  107. var price=this.data.price
  108. if(!this.data.class_id && this.data.category>=0 && this.data.subject>=0){
  109. if (e.detail.value == 0){
  110. price = this.data.categoryArray[this.data.category].price_new
  111. }
  112. if (e.detail.value == 1) {
  113. price = this.data.categoryArray[this.data.category].price_re
  114. }
  115. if (e.detail.value == 2) {
  116. price = this.data.categoryArray[this.data.category].price_change
  117. }
  118. }
  119. this.setData({
  120. train: e.detail.value,
  121. price: price
  122. })
  123. };
  124. if (e.target.dataset.name == 'area') {
  125. this.setData({
  126. area: e.detail.value
  127. })
  128. };
  129. if (e.target.dataset.name == 'receive') {
  130. this.setData({
  131. receive: e.detail.value
  132. })
  133. };
  134. if (e.target.dataset.name == 'class_') {
  135. this.setData({
  136. class_: e.detail.value
  137. })
  138. };
  139. },
  140. next:function(e){
  141. var formData = e.detail.value,data=this.data
  142. if (formData.name == '') {
  143. wx.showToast({
  144. title: '姓名不能为空!',
  145. icon: 'none',
  146. duration: 2000
  147. })
  148. return false
  149. }
  150. if (formData.idno == '') {
  151. wx.showToast({
  152. title: '身份证不能为空!',
  153. icon: 'none',
  154. duration: 2000
  155. })
  156. return false
  157. }
  158. if (formData.phone == '') {
  159. wx.showToast({
  160. title: '手机号不能为空!',
  161. icon: 'none',
  162. duration: 2000
  163. })
  164. return false
  165. }
  166. if(!this.data.class_id){
  167. if (this.data.category == -1) {
  168. wx.showToast({
  169. title: '请选择作业类别',
  170. icon: 'none',
  171. duration: 2000
  172. })
  173. return false
  174. }
  175. if (this.data.subject == -1) {
  176. wx.showToast({
  177. title: '请选择准操项目或资格类型',
  178. icon: 'none',
  179. duration: 2000
  180. })
  181. return false
  182. }
  183. if (this.data.train == -1) {
  184. wx.showToast({
  185. title: '请选择培训类型',
  186. icon: 'none',
  187. duration: 2000
  188. })
  189. return false
  190. }
  191. if (this.data.class_ == -1) {
  192. wx.showToast({
  193. title: '请选择班级',
  194. icon: 'none',
  195. duration: 2000
  196. })
  197. return false
  198. }
  199. }
  200. if (!this.data.class_id) {
  201. formData.subject_item = data.z_type+"|"+data.categoryArray[data.category].name+"|"+data.subjectArray[data.subject].name
  202. formData.subject_id = data.subjectArray[data.subject].id
  203. formData.sex=data.sexArray[data.sex]
  204. formData.education = data.recordArray[data.record]
  205. formData.receive_card = data.receiveArray[data.receive]
  206. formData.class_id = data.classList[data.class_].id
  207. }else{
  208. formData.class_id = this.data.class_id
  209. }
  210. formData.train_type = data.trainArray[data.train].name
  211. formData.price=this.data.price
  212. formData.area=this.data.area.join('')
  213. wx.showLoading({
  214. title: '',
  215. })
  216. wx.request({
  217. url: host + '/api/wx/signup',
  218. method: 'POST',
  219. header: {
  220. openid: this.data.openid
  221. },
  222. data: formData,
  223. success: res => {
  224. wx.hideLoading()
  225. wx.navigateTo({
  226. url: '../upload/upload?id='+res.data.data.id,
  227. })
  228. }
  229. })
  230. },
  231. /**
  232. * 生命周期函数--监听页面初次渲染完成
  233. */
  234. onReady: function () {
  235. },
  236. /**
  237. * 生命周期函数--监听页面显示
  238. */
  239. onShow: function () {
  240. },
  241. /**
  242. * 生命周期函数--监听页面隐藏
  243. */
  244. onHide: function () {
  245. },
  246. /**
  247. * 生命周期函数--监听页面卸载
  248. */
  249. onUnload: function () {
  250. },
  251. /**
  252. * 页面相关事件处理函数--监听用户下拉动作
  253. */
  254. onPullDownRefresh: function () {
  255. },
  256. /**
  257. * 页面上拉触底事件的处理函数
  258. */
  259. onReachBottom: function () {
  260. },
  261. /**
  262. * 用户点击右上角分享
  263. */
  264. onShareAppMessage: function () {
  265. }
  266. })