myStudy.js 18 KB

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