myStudy.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. this.setData({
  305. sexArray: App.sexList,
  306. });
  307. this.getInfo();
  308. },
  309. // 上传学籍
  310. upImg() {
  311. if (this.data.disabled) {
  312. return;
  313. }
  314. let _this = this;
  315. var tempFile;
  316. wx.showActionSheet({
  317. itemList: ["拍照上传", "从相册中选择"],
  318. success(res) {
  319. if (res.tapIndex === 0) {
  320. wx.chooseImage({
  321. count: 1,
  322. sizeType: ["original", "compressed"],
  323. sourceType: ["camera"],
  324. success(res) {
  325. const tempFilePaths = res.tempFilePaths;
  326. wx.uploadFile({
  327. url: App.apiRoot + "file/upload",
  328. filePath: tempFilePaths[0],
  329. name: "file",
  330. success: function (res) {
  331. if (res.errMsg === "uploadFile:ok") {
  332. wx.showToast({
  333. title: "上传成功",
  334. image: "",
  335. duration: 1500,
  336. mask: false,
  337. });
  338. let data = JSON.parse(res.data);
  339. _this.setData({
  340. userphoto: data.data,
  341. });
  342. }
  343. },
  344. function() {
  345. wx.showToast({
  346. title: "上传失败",
  347. icon: "none",
  348. image: "",
  349. duration: 1500,
  350. mask: false,
  351. });
  352. },
  353. });
  354. },
  355. });
  356. } else if (res.tapIndex === 1) {
  357. wx.chooseImage({
  358. count: 1,
  359. sizeType: ["original", "compressed"],
  360. sourceType: ["album"],
  361. success(res) {
  362. const tempFilePaths = res.tempFilePaths;
  363. wx.uploadFile({
  364. url: App.apiRoot + "file/upload",
  365. filePath: tempFilePaths[0],
  366. name: "file",
  367. success: function (res) {
  368. if (res.errMsg === "uploadFile:ok") {
  369. wx.showToast({
  370. title: "上传成功",
  371. image: "",
  372. duration: 1500,
  373. mask: false,
  374. });
  375. let data = JSON.parse(res.data);
  376. _this.setData({
  377. userphoto: data.data,
  378. });
  379. }
  380. },
  381. function() {
  382. wx.showToast({
  383. title: "上传失败",
  384. icon: "none",
  385. image: "",
  386. duration: 1500,
  387. mask: false,
  388. success: (result) => {},
  389. fail: () => {},
  390. complete: () => {},
  391. });
  392. },
  393. });
  394. },
  395. });
  396. }
  397. },
  398. fail(res) {},
  399. });
  400. },
  401. /**
  402. * 加载省份
  403. */
  404. searchProvince() {
  405. let _this = this;
  406. let proId = "";
  407. let prov = "";
  408. // let prov = this.data.allData.province;
  409. App._post_form("areainfo/province", "", null, function (res) {
  410. if (res.code === 0) {
  411. let provice = res.list;
  412. _this.data.multiArray[0] = provice;
  413. CityArray0 = provice;
  414. console.log("数组:", _this.data.u.province);
  415. if (_this.data.u.region) {
  416. prov = _this.data.u.province;
  417. // debugger
  418. if (CityArray0.length) {
  419. for (let i = 0; i < CityArray0.length; i++) {
  420. if (CityArray0[i].areaid == prov) {
  421. // _this.data.multiIndex[0] = i;
  422. _this.setData({
  423. ["multiIndex[0]"]: i,
  424. });
  425. break;
  426. }
  427. }
  428. }
  429. }
  430. if (prov && _this.data.load === true) {
  431. proId = prov;
  432. } else {
  433. //根据默认省,获取默认市
  434. if (_this.data.multiArray[0].length) {
  435. proId = _this.data.multiArray[0][0].areaid;
  436. }
  437. }
  438. _this.loadCity(proId);
  439. }
  440. });
  441. },
  442. //获取市级
  443. loadCity(cid) {
  444. let _this = this;
  445. App._post_form("areainfo/city/" + cid, "", null, function (res) {
  446. if (res.code === 0) {
  447. let city = res.list;
  448. _this.data.multiArray[1] = city;
  449. CityArray1 = city;
  450. if (_this.data.u.region) {
  451. let region = _this.data.u.region;
  452. if (CityArray1.length) {
  453. for (let i = 0; i < CityArray1.length; i++) {
  454. if (CityArray1[i].areaid === region) {
  455. _this.data.multiIndex[1] = i;
  456. break;
  457. }
  458. }
  459. }
  460. let cityId = "";
  461. if (region && _this.data.load === true) {
  462. cityId = region;
  463. } else {
  464. if (_this.data.multiArray[1].length) {
  465. cityId = _this.data.multiArray[1][0].areaid;
  466. }
  467. }
  468. // _this.loadSchool(cityId)
  469. _this.getSchool(_this.data.allData.region);
  470. }
  471. _this.setData({
  472. multiArray: _this.data.multiArray,
  473. multiIndex: _this.data.multiIndex,
  474. });
  475. }
  476. });
  477. },
  478. /**
  479. * 生命周期函数--监听页面初次渲染完成
  480. */
  481. onReady() {
  482. this.popup2 = this.selectComponent("#popup2");
  483. },
  484. /**
  485. * 生命周期函数--监听页面显示
  486. */
  487. onShow() {},
  488. // 获取学校列表
  489. getSchool(id) {
  490. App._get("areainfo/Schoolinfo/" + id, {}, (res) => {
  491. if (res.code === 0) {
  492. this.setData({
  493. schoolList: res.dictList,
  494. });
  495. }
  496. });
  497. },
  498. schoolChange(e) {
  499. let that = this;
  500. this.setData({
  501. schoolIndex: e.detail.value,
  502. college: that.data.schoolList[e.detail.value]["itemcode"],
  503. });
  504. console.log(this.data.college);
  505. },
  506. //学校change
  507. bindChangeSchool(e) {
  508. console.log(e);
  509. this.setData({
  510. schoolIndex: e.detail.value,
  511. // college: that.data.schoolList[e.detail.value]['itemcode']
  512. });
  513. console.log(this.data.schoolIndex, "mmmmm");
  514. },
  515. pickstart() {
  516. this.setData({
  517. pickMove: true,
  518. });
  519. },
  520. pickend() {
  521. this.setData({
  522. pickMove: false,
  523. });
  524. },
  525. confirmSchool() {
  526. if (this.data.pickMove) {
  527. return;
  528. }
  529. if (this.data.schoolList.length == 0) {
  530. return App.showError("请选择学校!");
  531. }
  532. this.setData({
  533. schoolPopup: false,
  534. college: this.data.schoolList[this.data.schoolIndex]["itemcode"],
  535. });
  536. this.data.schoolList.map((v) => {
  537. if (v.itemcode == this.data.college) {
  538. this.setData({
  539. sname: v.itemname,
  540. });
  541. }
  542. });
  543. console.log(this.data.college, "college");
  544. },
  545. // 性别change
  546. sexChange(e) {
  547. let that = this;
  548. this.setData({
  549. sexIndex: e.detail.value,
  550. sexCode: that.data.sexArray[e.detail.value]["itemcode"],
  551. });
  552. },
  553. // 地区change
  554. areaChange(e) {
  555. this.data.load = false;
  556. let _this = this;
  557. _this.data.multiIndex[0] = e.detail.value[0];
  558. _this.data.multiIndex[1] = e.detail.value[1];
  559. _this.setData({
  560. multiIndex: _this.data.multiIndex,
  561. ["allData.province"]: CityArray0[_this.data.multiIndex[0]].areaid,
  562. ["allData.region"]: CityArray1[_this.data.multiIndex[1]].areaid,
  563. });
  564. // _this.loadSchool(_this.data.allData.region)
  565. _this.getSchool(_this.data.allData.region);
  566. console.log(this.data.allData);
  567. console.log("fdjkdfjkjjkjk");
  568. console.log(e);
  569. },
  570. //绑定选择器滑动事件 地区
  571. MultiPickerAreaChange: function (e) {
  572. this.data.load = false;
  573. let _this = this;
  574. if (e.detail.column === 0) {
  575. let pid = CityArray0[e.detail.value].areaid;
  576. _this.data.multiIndex[0] = e.detail.value;
  577. _this.loadCity(pid);
  578. _this.setData({
  579. index0: e.detail.value,
  580. });
  581. } else if (e.detail.column === 1) {
  582. _this.data.multiIndex[1] = e.detail.value;
  583. _this.setData({
  584. multiIndex: _this.data.multiIndex,
  585. });
  586. // _this.setData({
  587. // index1: e.detail.value
  588. // })
  589. }
  590. console.log(1111111111111);
  591. console.log(e);
  592. },
  593. schoolName() {
  594. if (this.data.disabled) {
  595. return;
  596. }
  597. if (!this.data.allData.region) {
  598. return App.showError("请选择学校地址!");
  599. } else {
  600. this.setData({
  601. // disabled1: false
  602. schoolPopup: true,
  603. // schoolIndex: [this.data.schoolIndex],
  604. schoolIndex: [0],
  605. searchName: "",
  606. });
  607. this.getSchool(this.data.allData.region);
  608. }
  609. console.log(this.data.allData.region, "0000000");
  610. console.log(this.data.schoolIndex, "ffff");
  611. },
  612. hiddenAddress() {
  613. this.setData({
  614. schoolPopup: false,
  615. });
  616. console.log(11111111111);
  617. },
  618. /**
  619. * 生命周期函数--监听页面隐藏
  620. */
  621. onHide() {},
  622. /**
  623. * 生命周期函数--监听页面卸载
  624. */
  625. onUnload() {},
  626. /**
  627. * 页面相关事件处理函数--监听用户下拉动作
  628. */
  629. onPullDownRefresh() {},
  630. /**
  631. * 页面上拉触底事件的处理函数
  632. */
  633. onReachBottom() {},
  634. /**
  635. * 用户点击右上角分享
  636. */
  637. onShareAppMessage() {},
  638. });