post.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. type:0
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. this.setData({
  37. type: options.type
  38. })
  39. var sub_list=[],user={}
  40. wx.request({
  41. url: host + '/api/wx/authinfo',
  42. header: {
  43. openid: app.globalData.openid
  44. },
  45. success: res => {
  46. user = res.data.data
  47. console.log(user)
  48. if(options.type != 2){
  49. this.setData({
  50. name:user.name,
  51. company: user.company,
  52. phone:user.phone,
  53. idno: user.idno,
  54. sex:user.sex==1?0:1,
  55. record: this.data.recordArray.indexOf(user.education),
  56. })
  57. }
  58. }
  59. })
  60. wx.request({
  61. url: host + '/api/wx/sujectitem',
  62. success: res => {
  63. sub_list = res.data.data
  64. // options:s_name 分类名称 s_id 分类id class_id 班级id
  65. //新增报名
  66. if (options.type == 1){
  67. //班级列表
  68. wx.request({
  69. url: host + '/api/wx/class/list?subject_item0=' + options.s_id,
  70. method: 'GET',
  71. success: res => {
  72. // 过滤分类
  73. let list = sub_list.filter(item => item.id == options.s_id)
  74. this.setData({
  75. categoryArray: list[0].children,
  76. z_type: list[0].name, //提交时拼接subject_item
  77. classList: res.data.data[0].classes
  78. })
  79. }
  80. })
  81. }
  82. //修改报名
  83. if(options.type == 2){
  84. wx.request({
  85. url: host+'/api/wx/signup',
  86. method:'GET',
  87. data:{id:options.id},
  88. success:res=>{
  89. let data = res.data.data, subject_item = data.subject_item.split('|');
  90. let list = sub_list.filter(item => item.name == subject_item[0]);
  91. let categoryArray = list[0].children, subject = 0,
  92. subjectArray = [], category = 0, train=0;
  93. //定位分类下拉选项
  94. for(let i=0;i<categoryArray.length;i++){
  95. if (categoryArray[i].name == subject_item[1]){
  96. category=i
  97. subjectArray = categoryArray[i].children
  98. for(let j=0;j<subjectArray.length;j++){
  99. if (subjectArray[j].name == subject_item[2]){
  100. subject=j
  101. }
  102. }
  103. }
  104. }
  105. for(let i=0;i<this.data.trainArray.length;i++){
  106. if (this.data.trainArray[i].name == data.train_type){
  107. train=i
  108. }
  109. }
  110. //获取班级列表
  111. wx.request({
  112. url: host + '/api/wx/class/list?subject_item0=' + list[0].id,
  113. method: 'GET',
  114. success: res => {
  115. let classes = res.data.data[0].classes, class_=0
  116. for(let i=0;i<classes.length;i++){
  117. if (classes[i].cid == data.class_id){
  118. class_=i
  119. }
  120. }
  121. this.setData({
  122. classList: classes,
  123. class_: class_
  124. })
  125. }
  126. })
  127. this.setData({
  128. z_type: subject_item[0],
  129. sex:data.sex=='男' ? 0 :1,
  130. record: this.data.recordArray.indexOf(data.education),
  131. receive: data.receive_card == '自取' ? 0 : 1,
  132. categoryArray: categoryArray,
  133. subjectArray: subjectArray,
  134. category: category,
  135. subject: subject,
  136. train: train,
  137. area:data.area.split(' ')
  138. })
  139. this.setData({
  140. data: res.data.data
  141. })
  142. }
  143. })
  144. }
  145. //班级报名
  146. if(options.type == 3){
  147. this.setData({
  148. parice_list: options.price.split('_'),
  149. class_id: options.class_id
  150. })
  151. }
  152. }
  153. })
  154. },
  155. pickerChange:function(e){
  156. if(e.target.dataset.name == 'sex'){
  157. this.setData({
  158. sex: e.detail.value
  159. })
  160. };
  161. if (e.target.dataset.name == 'record') {
  162. this.setData({
  163. record: e.detail.value
  164. })
  165. };
  166. if (e.target.dataset.name == 'category') {
  167. let list = this.data.categoryArray[e.detail.value].children
  168. this.setData({
  169. category: e.detail.value,
  170. subjectArray: list,
  171. subject:-1,
  172. train:-1
  173. })
  174. };
  175. if (e.target.dataset.name == 'subject') {
  176. this.setData({
  177. subject: e.detail.value,
  178. train: -1
  179. })
  180. };
  181. if (e.target.dataset.name == 'time') {
  182. this.setData({
  183. time: e.detail.value
  184. })
  185. };
  186. if (e.target.dataset.name == 'train') {
  187. var price=this.data.price
  188. if(this.data.type == 3){
  189. price = this.data.parice_list[e.detail.value]
  190. }else if(this.data.category>=0 && this.data.subject>=0){
  191. if (e.detail.value == 0){
  192. price = this.data.categoryArray[this.data.category].price_new
  193. }
  194. if (e.detail.value == 1) {
  195. price = this.data.categoryArray[this.data.category].price_re
  196. }
  197. if (e.detail.value == 2) {
  198. price = this.data.categoryArray[this.data.category].price_change
  199. }
  200. }
  201. this.setData({
  202. train: e.detail.value,
  203. price: price
  204. })
  205. };
  206. if (e.target.dataset.name == 'area') {
  207. this.setData({
  208. area: e.detail.value
  209. })
  210. };
  211. if (e.target.dataset.name == 'receive') {
  212. this.setData({
  213. receive: e.detail.value
  214. })
  215. };
  216. if (e.target.dataset.name == 'class_') {
  217. this.setData({
  218. class_: e.detail.value
  219. })
  220. };
  221. },
  222. next:function(e){
  223. var formData = e.detail.value,data=this.data
  224. if (formData.name == '') {
  225. wx.showToast({
  226. title: '姓名不能为空!',
  227. icon: 'none',
  228. duration: 2000
  229. })
  230. return false
  231. }
  232. if (formData.idno == '') {
  233. wx.showToast({
  234. title: '身份证不能为空!',
  235. icon: 'none',
  236. duration: 2000
  237. })
  238. return false
  239. }
  240. if (formData.phone == '') {
  241. wx.showToast({
  242. title: '手机号不能为空!',
  243. icon: 'none',
  244. duration: 2000
  245. })
  246. return false
  247. }
  248. if(data.type != 3){
  249. if (this.data.category == -1) {
  250. wx.showToast({
  251. title: '请选择作业类别',
  252. icon: 'none',
  253. duration: 2000
  254. })
  255. return false
  256. }
  257. if (this.data.subject == -1) {
  258. wx.showToast({
  259. title: '请选择准操项目或资格类型',
  260. icon: 'none',
  261. duration: 2000
  262. })
  263. return false
  264. }
  265. if (this.data.class_ == -1) {
  266. wx.showToast({
  267. title: '请选择班级',
  268. icon: 'none',
  269. duration: 2000
  270. })
  271. return false
  272. }
  273. formData.subject_item = data.z_type + "|" + data.categoryArray[data.category].name + "|" + data.subjectArray[data.subject].name
  274. formData.subject_id = data.subjectArray[data.subject].id
  275. formData.class_id = data.classList[data.class_].cid
  276. }else{
  277. formData.class_id = data.class_id
  278. }
  279. if (this.data.train == -1) {
  280. wx.showToast({
  281. title: '请选择培训类型',
  282. icon: 'none',
  283. duration: 2000
  284. })
  285. return false
  286. }
  287. formData.sex=data.sexArray[data.sex]
  288. formData.education = data.recordArray[data.record]
  289. formData.receive_card = data.receiveArray[data.receive]
  290. formData.train_type = data.trainArray[data.train].name
  291. formData.price=this.data.price
  292. formData.area=this.data.area.join(' ')
  293. var method = 'POST', post_data = formData
  294. if (this.data.type == 2) {
  295. method = 'PUT'
  296. var new_data=this.data.data
  297. for(let key in formData){
  298. new_data[key]=formData[key]
  299. }
  300. post_data = new_data
  301. }
  302. wx.showLoading({
  303. title: '',
  304. })
  305. wx.request({
  306. url: host + '/api/wx/signup',
  307. method: method,
  308. header: {
  309. openid: this.data.openid
  310. },
  311. data: post_data,
  312. success: res => {
  313. wx.hideLoading()
  314. if(res.data.status == 'suc'){
  315. let id = (data.type == 2) ? new_data.id : res.data.data.id
  316. wx.navigateTo({
  317. url: '../upload/upload?id='+id,
  318. })
  319. }else{
  320. wx.showToast({
  321. title: res.data.message,
  322. icon: 'none',
  323. duration: 2000
  324. })
  325. }
  326. }
  327. })
  328. },
  329. /**
  330. * 生命周期函数--监听页面初次渲染完成
  331. */
  332. onReady: function () {
  333. },
  334. /**
  335. * 生命周期函数--监听页面显示
  336. */
  337. onShow: function () {
  338. },
  339. /**
  340. * 生命周期函数--监听页面隐藏
  341. */
  342. onHide: function () {
  343. },
  344. /**
  345. * 生命周期函数--监听页面卸载
  346. */
  347. onUnload: function () {
  348. },
  349. /**
  350. * 页面相关事件处理函数--监听用户下拉动作
  351. */
  352. onPullDownRefresh: function () {
  353. },
  354. /**
  355. * 页面上拉触底事件的处理函数
  356. */
  357. onReachBottom: function () {
  358. },
  359. /**
  360. * 用户点击右上角分享
  361. */
  362. onShareAppMessage: function () {
  363. }
  364. })