post.js 9.5 KB

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