post.js 10 KB

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