myStudy.js 17 KB

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