myStudy.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. // pages/my/myStudy/myStudy.js
  2. const App = getApp();
  3. var util = require("../../../utils/util.js");
  4. let CityArray0 = [];
  5. let CityArray1 = [];
  6. let CityArray2 = [];
  7. let g1 = [];
  8. let g2 = [];
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. facultyName: "",
  15. professionalTitle: "",
  16. appAssetsUrl2: App.appAssetsUrl2,
  17. userName: "",
  18. areaList: [],
  19. schoolList: [],
  20. bottomLeft: App.bottomLeft,
  21. schoolIndex: 0,
  22. sexIndex: null,
  23. sexArray: App.sexList,
  24. userphoto: "",
  25. region: [],
  26. multiArray: [0, 0, 0],
  27. multiIndex: [0, 0, 0],
  28. u: [],
  29. allData: {},
  30. load: true,
  31. identityNumber: "",
  32. college: null,
  33. sexCode: null,
  34. disabled: false,
  35. disabled1: true,
  36. obj: {
  37. auditStatus: null,
  38. },
  39. index0: null,
  40. index1: null,
  41. schoolPopup: false,
  42. pickMove: false,
  43. sname: "",
  44. searchName: "",
  45. tipHeight: 0,
  46. consultingTeacher: "",
  47. inviteTeacher: "",
  48. },
  49. facultyInput (e) {
  50. this.setData({
  51. facultyName: e.detail.value,
  52. });
  53. },
  54. proInput (e) {
  55. this.setData({
  56. professionalTitle: e.detail.value,
  57. });
  58. },
  59. messageInput (e) {
  60. this.setData({
  61. consultingTeacher: e.detail.value,
  62. });
  63. },
  64. guidanceInput (e) {
  65. this.setData({
  66. inviteTeacher: e.detail.value,
  67. });
  68. },
  69. schoolInput (e) {
  70. this.setData({
  71. searchName: e.detail.value,
  72. });
  73. this.searchSchool();
  74. console.log(e.detail.value);
  75. },
  76. userNameInput (e) {
  77. this.setData({
  78. userName: e.detail.value,
  79. });
  80. },
  81. idInput (e) {
  82. this.setData({
  83. identityNumber: e.detail.value,
  84. });
  85. },
  86. //搜索学校
  87. searchSchool () {
  88. App._get(
  89. "areainfo/selectSchoolInfoByParams/",
  90. {
  91. region: this.data.allData.region,
  92. schoolName: this.data.searchName,
  93. },
  94. (res) => {
  95. if (res.code === 0) {
  96. console.log(res);
  97. console.log(this.data.searchName, "this.data.searchName");
  98. this.setData({
  99. schoolList: res.dictList,
  100. });
  101. if (res.dictList.length == 0) {
  102. App.showError("暂无相关学校!");
  103. }
  104. // this.data.schoolList.forEach((v,k) => {
  105. // if(v.itemcode == res.data.college) {
  106. // return this.setData({
  107. // schoolIndex: k
  108. // })
  109. // }
  110. // })
  111. }
  112. }
  113. );
  114. },
  115. submit () {
  116. // return this.popup2.showPopup()
  117. if (!this.data.allData.region) {
  118. return App.showError("请选择地址!");
  119. }
  120. if (this.data.college === null) {
  121. return App.showError("请选择学校!");
  122. }
  123. console.log(this.data.facultyName);
  124. if (this.data.facultyName === "") {
  125. return App.showError("请输入所属院系!");
  126. }
  127. if (this.data.professionalTitle === "") {
  128. return App.showError("请输入所学专业!");
  129. }
  130. if (this.data.consultingTeacher === "") {
  131. return App.showError("请输入邀约老师!");
  132. }
  133. if (this.data.inviteTeacher === "") {
  134. return App.showError("请输入指导老师!");
  135. }
  136. if (this.data.userName === "") {
  137. return App.showError("请输入真实姓名!");
  138. }
  139. if (this.data.sexIndex === null) {
  140. return App.showError("请选择性别!");
  141. }
  142. if (this.data.identityNumber === "") {
  143. return App.showError("请输入身份证号!");
  144. }
  145. if (this.data.identityNumber) {
  146. let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  147. if (!reg.test(this.data.identityNumber)) {
  148. return App.showError("请输入正确身份证号!");
  149. }
  150. }
  151. let that = this;
  152. if (that.data.obj.auditStatus == 2) {
  153. App._put_form(
  154. "studentstatus/update",
  155. "",
  156. {
  157. city: this.data.allData.region,
  158. college: this.data.college,
  159. faculty: this.data.facultyName,
  160. identityNumber: this.data.identityNumber,
  161. proofOfQualifications: this.data.userphoto,
  162. province: this.data.allData.province,
  163. realName: this.data.userName,
  164. sex: this.data.sexCode,
  165. specialized: this.data.professionalTitle,
  166. consultingTeacher: this.data.consultingTeacher,
  167. inviteTeacher: this.data.inviteTeacher,
  168. memberId: util.getUserId(),
  169. id: that.data.obj.id,
  170. auditId: that.data.obj.auditId,
  171. },
  172. (res) => {
  173. if (res.code === 0) {
  174. that.popup2.showPopup();
  175. }
  176. }
  177. );
  178. } else {
  179. App._post_form(
  180. "studentstatus/save",
  181. "",
  182. {
  183. city: this.data.allData.region,
  184. college: this.data.college,
  185. faculty: this.data.facultyName,
  186. identityNumber: this.data.identityNumber,
  187. proofOfQualifications: this.data.userphoto,
  188. province: this.data.allData.province,
  189. realName: this.data.userName,
  190. sex: this.data.sexCode,
  191. specialized: this.data.professionalTitle,
  192. consultingTeacher: this.data.consultingTeacher,
  193. inviteTeacher: this.data.inviteTeacher,
  194. memberId: util.getUserId(),
  195. },
  196. function (res) {
  197. if (res.code == 0) {
  198. // wx.navigateTo({
  199. // url: '/expert/success/success'
  200. // })
  201. that.popup2.showPopup();
  202. }
  203. },
  204. function (res) { }
  205. );
  206. }
  207. },
  208. getInfo () {
  209. let that = this;
  210. App._get(`studentstatus/info/${util.getUserId()}`, {}, (res) => {
  211. if (res.code === 0) {
  212. this.setData({
  213. ["allData.region"]: res.data.city,
  214. ["allData.province"]: res.data.province,
  215. ["u.province"]: res.data.province,
  216. ["u.region"]: res.data.city,
  217. college: res.data.college,
  218. facultyName: res.data.faculty,
  219. identityNumber: res.data.identityNumber,
  220. userphoto: res.data.proofOfQualifications,
  221. userName: res.data.realName,
  222. sexCode: res.data.sex,
  223. professionalTitle: res.data.specialized,
  224. obj: res.data,
  225. sname: res.data.schoolName,
  226. consultingTeacher: res.data.consultingTeacher,
  227. inviteTeacher: res.data.inviteTeacher,
  228. });
  229. console.log(res);
  230. this.searchProvince();
  231. if (res.data.city) {
  232. App._get("areainfo/Schoolinfo/" + res.data.city, {}, (res2) => {
  233. if (res2.code === 0) {
  234. this.setData({
  235. schoolList: res2.dictList,
  236. });
  237. this.data.schoolList.forEach((v, k) => {
  238. if (v.itemcode == res.data.college) {
  239. return this.setData({
  240. schoolIndex: k,
  241. });
  242. }
  243. });
  244. console.log(this.data.schoolIndex, "schoolIndex");
  245. }
  246. });
  247. }
  248. this.data.sexArray.forEach((v, k) => {
  249. if (v.itemcode == res.data.sex) {
  250. return this.setData({
  251. sexIndex: k,
  252. });
  253. }
  254. });
  255. if (res.data.auditStatus == 0 || res.data.auditStatus == 1) {
  256. this.setData({
  257. disabled: true,
  258. disabled1: true,
  259. });
  260. }
  261. console.log("省市:", this.data.multiArray);
  262. let query = wx.createSelectorQuery();
  263. query
  264. .select("#bot-box")
  265. .boundingClientRect((rect) => {
  266. let height = rect.height;
  267. that.setData({
  268. tipHeight: height,
  269. });
  270. })
  271. .exec();
  272. } else {
  273. let query = wx.createSelectorQuery();
  274. query
  275. .select("#bot-box")
  276. .boundingClientRect((rect) => {
  277. let height = rect.height;
  278. that.setData({
  279. tipHeight: height,
  280. });
  281. })
  282. .exec();
  283. this.searchProvince();
  284. }
  285. });
  286. },
  287. _error () {
  288. console.log("返回");
  289. this.popup2.hidePopup();
  290. wx.navigateBack({
  291. delta: 1,
  292. });
  293. },
  294. _success () {
  295. console.log("查看");
  296. this.popup2.hidePopup();
  297. this.getInfo();
  298. },
  299. /**
  300. * 生命周期函数--监听页面加载
  301. */
  302. onLoad (options) {
  303. // this.getSchool()
  304. console.log("options", App.sexList)
  305. this.data.sexArray = App.sexList
  306. this.setData({
  307. sexArray: this.data.sexArray,
  308. });
  309. this.getInfo();
  310. },
  311. // 上传学籍
  312. upImg () {
  313. if (this.data.disabled) {
  314. return;
  315. }
  316. let _this = this;
  317. var tempFile;
  318. wx.showActionSheet({
  319. itemList: ["拍照上传", "从相册中选择"],
  320. success (res) {
  321. if (res.tapIndex === 0) {
  322. wx.chooseImage({
  323. count: 1,
  324. sizeType: ["original", "compressed"],
  325. sourceType: ["camera"],
  326. success (res) {
  327. const tempFilePaths = res.tempFilePaths;
  328. wx.uploadFile({
  329. url: App.apiRoot + "file/upload",
  330. filePath: tempFilePaths[0],
  331. name: "file",
  332. success: function (res) {
  333. if (res.errMsg === "uploadFile:ok") {
  334. wx.showToast({
  335. title: "上传成功",
  336. image: "",
  337. duration: 1500,
  338. mask: false,
  339. });
  340. let data = JSON.parse(res.data);
  341. _this.setData({
  342. userphoto: data.data,
  343. });
  344. }
  345. },
  346. function () {
  347. wx.showToast({
  348. title: "上传失败",
  349. icon: "none",
  350. image: "",
  351. duration: 1500,
  352. mask: false,
  353. });
  354. },
  355. });
  356. },
  357. });
  358. } else if (res.tapIndex === 1) {
  359. wx.chooseImage({
  360. count: 1,
  361. sizeType: ["original", "compressed"],
  362. sourceType: ["album"],
  363. success (res) {
  364. const tempFilePaths = res.tempFilePaths;
  365. wx.uploadFile({
  366. url: App.apiRoot + "file/upload",
  367. filePath: tempFilePaths[0],
  368. name: "file",
  369. success: function (res) {
  370. if (res.errMsg === "uploadFile:ok") {
  371. wx.showToast({
  372. title: "上传成功",
  373. image: "",
  374. duration: 1500,
  375. mask: false,
  376. });
  377. let data = JSON.parse(res.data);
  378. _this.setData({
  379. userphoto: data.data,
  380. });
  381. }
  382. },
  383. function () {
  384. wx.showToast({
  385. title: "上传失败",
  386. icon: "none",
  387. image: "",
  388. duration: 1500,
  389. mask: false,
  390. success: (result) => { },
  391. fail: () => { },
  392. complete: () => { },
  393. });
  394. },
  395. });
  396. },
  397. });
  398. }
  399. },
  400. fail (res) { },
  401. });
  402. },
  403. /**
  404. * 加载省份
  405. */
  406. searchProvince () {
  407. let _this = this;
  408. let proId = "";
  409. let prov = "";
  410. // let prov = this.data.allData.province;
  411. App._post_form("areainfo/province", "", null, function (res) {
  412. if (res.code === 0) {
  413. let provice = res.list;
  414. _this.data.multiArray[0] = provice;
  415. CityArray0 = provice;
  416. console.log("数组:", _this.data.u.province);
  417. if (_this.data.u.region) {
  418. prov = _this.data.u.province;
  419. // debugger
  420. if (CityArray0.length) {
  421. for (let i = 0; i < CityArray0.length; i++) {
  422. if (CityArray0[i].areaid == prov) {
  423. // _this.data.multiIndex[0] = i;
  424. _this.setData({
  425. ["multiIndex[0]"]: i,
  426. });
  427. break;
  428. }
  429. }
  430. }
  431. }
  432. if (prov && _this.data.load === true) {
  433. proId = prov;
  434. } else {
  435. //根据默认省,获取默认市
  436. if (_this.data.multiArray[0].length) {
  437. proId = _this.data.multiArray[0][0].areaid;
  438. }
  439. }
  440. _this.loadCity(proId);
  441. }
  442. });
  443. },
  444. //获取市级
  445. loadCity (cid) {
  446. let _this = this;
  447. App._post_form("areainfo/city/" + cid, "", null, function (res) {
  448. if (res.code === 0) {
  449. let city = res.list;
  450. _this.data.multiArray[1] = city;
  451. CityArray1 = city;
  452. if (_this.data.u.region) {
  453. let region = _this.data.u.region;
  454. if (CityArray1.length) {
  455. for (let i = 0; i < CityArray1.length; i++) {
  456. if (CityArray1[i].areaid === region) {
  457. _this.data.multiIndex[1] = i;
  458. break;
  459. }
  460. }
  461. }
  462. let cityId = "";
  463. if (region && _this.data.load === true) {
  464. cityId = region;
  465. } else {
  466. if (_this.data.multiArray[1].length) {
  467. cityId = _this.data.multiArray[1][0].areaid;
  468. }
  469. }
  470. // _this.loadSchool(cityId)
  471. _this.getSchool(_this.data.allData.region);
  472. }
  473. _this.setData({
  474. multiArray: _this.data.multiArray,
  475. multiIndex: _this.data.multiIndex,
  476. });
  477. }
  478. });
  479. },
  480. /**
  481. * 生命周期函数--监听页面初次渲染完成
  482. */
  483. onReady () {
  484. this.popup2 = this.selectComponent("#popup2");
  485. },
  486. /**
  487. * 生命周期函数--监听页面显示
  488. */
  489. onShow () { },
  490. // 获取学校列表
  491. getSchool (id) {
  492. App._get("areainfo/Schoolinfo/" + id, {}, (res) => {
  493. if (res.code === 0) {
  494. this.setData({
  495. schoolList: res.dictList,
  496. });
  497. }
  498. });
  499. },
  500. schoolChange (e) {
  501. let that = this;
  502. this.setData({
  503. schoolIndex: e.detail.value,
  504. college: that.data.schoolList[e.detail.value]["itemcode"],
  505. });
  506. console.log(this.data.college);
  507. },
  508. //学校change
  509. bindChangeSchool (e) {
  510. console.log(e);
  511. this.setData({
  512. schoolIndex: e.detail.value,
  513. // college: that.data.schoolList[e.detail.value]['itemcode']
  514. });
  515. console.log(this.data.schoolIndex, "mmmmm");
  516. },
  517. pickstart () {
  518. this.setData({
  519. pickMove: true,
  520. });
  521. },
  522. pickend () {
  523. this.setData({
  524. pickMove: false,
  525. });
  526. },
  527. confirmSchool () {
  528. if (this.data.pickMove) {
  529. return;
  530. }
  531. if (this.data.schoolList.length == 0) {
  532. return App.showError("请选择学校!");
  533. }
  534. this.setData({
  535. schoolPopup: false,
  536. college: this.data.schoolList[this.data.schoolIndex]["itemcode"],
  537. });
  538. this.data.schoolList.map((v) => {
  539. if (v.itemcode == this.data.college) {
  540. this.setData({
  541. sname: v.itemname,
  542. });
  543. }
  544. });
  545. console.log(this.data.college, "college");
  546. },
  547. // 性别change
  548. sexChange (e) {
  549. let that = this;
  550. this.setData({
  551. sexIndex: e.detail.value,
  552. sexCode: that.data.sexArray[e.detail.value]["itemcode"],
  553. });
  554. },
  555. // 地区change
  556. areaChange (e) {
  557. this.data.load = false;
  558. let _this = this;
  559. _this.data.multiIndex[0] = e.detail.value[0];
  560. _this.data.multiIndex[1] = e.detail.value[1];
  561. _this.setData({
  562. multiIndex: _this.data.multiIndex,
  563. ["allData.province"]: CityArray0[_this.data.multiIndex[0]].areaid,
  564. ["allData.region"]: CityArray1[_this.data.multiIndex[1]].areaid,
  565. });
  566. // _this.loadSchool(_this.data.allData.region)
  567. _this.getSchool(_this.data.allData.region);
  568. console.log(this.data.allData);
  569. console.log("fdjkdfjkjjkjk");
  570. console.log(e);
  571. },
  572. //绑定选择器滑动事件 地区
  573. MultiPickerAreaChange: function (e) {
  574. this.data.load = false;
  575. let _this = this;
  576. if (e.detail.column === 0) {
  577. let pid = CityArray0[e.detail.value].areaid;
  578. _this.data.multiIndex[0] = e.detail.value;
  579. _this.loadCity(pid);
  580. _this.setData({
  581. index0: e.detail.value,
  582. });
  583. } else if (e.detail.column === 1) {
  584. _this.data.multiIndex[1] = e.detail.value;
  585. _this.setData({
  586. multiIndex: _this.data.multiIndex,
  587. });
  588. // _this.setData({
  589. // index1: e.detail.value
  590. // })
  591. }
  592. console.log(1111111111111);
  593. console.log(e);
  594. },
  595. schoolName () {
  596. if (this.data.disabled) {
  597. return;
  598. }
  599. if (!this.data.allData.region) {
  600. return App.showError("请选择学校地址!");
  601. } else {
  602. this.setData({
  603. // disabled1: false
  604. schoolPopup: true,
  605. // schoolIndex: [this.data.schoolIndex],
  606. schoolIndex: [0],
  607. searchName: "",
  608. });
  609. this.getSchool(this.data.allData.region);
  610. }
  611. console.log(this.data.allData.region, "0000000");
  612. console.log(this.data.schoolIndex, "ffff");
  613. },
  614. hiddenAddress () {
  615. this.setData({
  616. schoolPopup: false,
  617. });
  618. console.log(11111111111);
  619. },
  620. /**
  621. * 生命周期函数--监听页面隐藏
  622. */
  623. onHide () { },
  624. /**
  625. * 生命周期函数--监听页面卸载
  626. */
  627. onUnload () { },
  628. /**
  629. * 页面相关事件处理函数--监听用户下拉动作
  630. */
  631. onPullDownRefresh () { },
  632. /**
  633. * 页面上拉触底事件的处理函数
  634. */
  635. onReachBottom () { },
  636. /**
  637. * 用户点击右上角分享
  638. */
  639. onShareAppMessage () { },
  640. });