info.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. const app = getApp();
  2. const request = require('../../utils/request.js');
  3. const tools = require('../../utils/tools.js');
  4. import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
  5. Page({
  6. data: {
  7. showareaPicker: false,
  8. showadressPicker: false,
  9. areacolumnsArr: [],
  10. areacolumns: [
  11. // {
  12. // values: [],
  13. // className: 'column1',
  14. // },
  15. // {
  16. // values: [],
  17. // className: 'column2'
  18. // },
  19. // {
  20. // values: [],
  21. // className: 'column3'
  22. // }
  23. ],
  24. adresscolumnsArr: [],
  25. adresscolumns: [],
  26. errorinfo: {
  27. nameerr: '',
  28. idcarderr: '',
  29. areaerr: '',
  30. adresserr: '',
  31. adressDetailserr: '',
  32. telerr: ''
  33. },
  34. info: {
  35. id: '',
  36. name: '',
  37. idcard: '',
  38. area: [],
  39. adress: '',
  40. adressDetails: '',
  41. tel: ''
  42. },
  43. readonly: false
  44. },
  45. async getUnit(regioncode, communityid) {
  46. let options = {
  47. url: 'resource/miniapp/user/getXqdwList',
  48. data: {
  49. regioncode,
  50. accountId: wx.getStorageSync('userId')
  51. },
  52. method: 'post'
  53. }
  54. let res = await request.query(options);
  55. if (res.data.code === 200) {
  56. this.setData({
  57. adresscolumnsArr: res.data.data,
  58. adresscolumns: res.data.data.map(item => {
  59. return item.name
  60. })
  61. })
  62. let adress = ['info.adress']
  63. if (communityid) {
  64. console.log(res.data.data)
  65. this.setData({
  66. [adress]: res.data.data.length == 0 ? '' : res.data.data.filter(item => {
  67. return item.id == communityid
  68. })[0].name
  69. })
  70. } else {
  71. this.setData({
  72. [adress]: ''
  73. })
  74. }
  75. } else {
  76. Toast.fail(res.data.msg);
  77. }
  78. },
  79. async getArea(parentId, level) {
  80. // if(level===3)return false;
  81. console.log('我调用了几次')
  82. let options = {
  83. url: 'resource/miniapp/user/getDeptList',
  84. data: {
  85. accountId: wx.getStorageSync('userId'),
  86. parentId: parentId ? parentId : '',
  87. level: level ? level : ''
  88. },
  89. method: 'post'
  90. }
  91. let res = await request.query(options);
  92. if (res.data.code === 200) {
  93. let idx = level ? level : 0;
  94. console.log(res.data.data, '111111111')
  95. if (res.data.data.length !== 0) {
  96. console.log('22222222222222')
  97. this.setData({
  98. ['areacolumnsArr[' + idx + ']']: res.data.data.map(item => {
  99. return item
  100. }),
  101. ['areacolumns[' + idx + '].values']: res.data.data.map(item => {
  102. return item.name
  103. }),
  104. // ['areacolumns[' + idx + '].className']: 'column' + idx
  105. })
  106. this.getArea(res.data.data[0].id, idx + 1)
  107. }
  108. // if (res.data.data.length !== 0) this.getArea(res.data.data[0].id, idx + 1)
  109. } else {
  110. Toast.fail(res.data.msg);
  111. }
  112. },
  113. async getInfo() {
  114. let options = {
  115. url: 'resource/miniapp/user/getUserInfo',
  116. data: {
  117. openId: wx.getStorageSync('openid')
  118. },
  119. method: 'post'
  120. }
  121. let res = await request.query(options);
  122. if (res.data.code === 200) {
  123. let id = 'info.id';
  124. let name = 'info.name';
  125. let idcard = 'info.idcard';
  126. let area = 'info.area';
  127. let adressDetails = 'info.adressDetails';
  128. let tel = 'info.tel';
  129. this.setData({
  130. [id]: res.data.data.id,
  131. [name]: (res.data.data.name !== 'null' && res.data.data.name) ? res.data.data.name : '',
  132. [idcard]: (res.data.data.idcard !== 'null' && res.data.data.idcard) ? res.data.data.idcard : '',
  133. [area]: res.data.data.regionName,
  134. [adressDetails]: (res.data.data.address !== 'null' && res.data.data.address) ? res.data.data.address : '',
  135. [tel]: (res.data.data.phone !== 'null' && res.data.data.phone) ? res.data.data.phone : ''
  136. })
  137. this.getUnit(res.data.data.regioncode, res.data.data.communityid);
  138. this.getArea();
  139. } else {
  140. Toast.fail(res.data.msg);
  141. }
  142. },
  143. areaClick(e) {
  144. this.setData({
  145. showareaPicker: true
  146. })
  147. },
  148. onareaCancel() {
  149. this.setData({
  150. showareaPicker: false
  151. })
  152. },
  153. onareaConfirm(e) {
  154. console.log(e)
  155. let area = 'info.area';
  156. this.setData({
  157. showareaPicker: false,
  158. [area]: e.detail.value[0] ? e.detail.value : []
  159. })
  160. let a = e.detail.value[e.detail.value.length - 1];
  161. let regioncode = this.data.areacolumnsArr[this.data.areacolumnsArr.length - 1].filter(item => {
  162. return item.name == a
  163. })[0].code
  164. this.getUnit(regioncode);
  165. },
  166. adressClick() {
  167. if (this.data.info.area.length !== 0) {
  168. this.setData({
  169. showadressPicker: true
  170. })
  171. } else {
  172. Toast.fail('请先选择区划');
  173. }
  174. },
  175. onadressCancel() {
  176. this.setData({
  177. showadressPicker: false
  178. })
  179. },
  180. onadressConfirm(e) {
  181. console.log(e.detail.value)
  182. let adress = 'info.adress';
  183. this.setData({
  184. [adress]: e.detail.value,
  185. showadressPicker: false
  186. })
  187. },
  188. nameChange(e) {
  189. console.log(e)
  190. let val = 'info.name'
  191. this.setData({
  192. [val]: e.detail
  193. })
  194. console.log(this.data.info.name)
  195. },
  196. idCardChange(e) {
  197. let val = 'info.idcard'
  198. this.setData({
  199. [val]: e.detail
  200. })
  201. },
  202. adressDetailsChange(e) {
  203. let val = 'info.adressDetails'
  204. this.setData({
  205. [val]: e.detail
  206. })
  207. },
  208. telChange(e) {
  209. let val = 'info.tel'
  210. this.setData({
  211. [val]: e.detail
  212. })
  213. },
  214. onareaChange(e) {
  215. console.log(e.detail.index)
  216. // if (e.detail.index < 2) {
  217. let item = this.data.areacolumnsArr[e.detail.index].filter(item => {
  218. return item.name == e.detail.value[e.detail.index]
  219. })[0].id
  220. // if (item.level === 3) return false;
  221. this.getArea(item.id, item.level)
  222. // }
  223. },
  224. async submit(e) {
  225. console.log(this.data.info.area, '我是选择的行政区划')
  226. console.log(this.data.areacolumnsArr, '我是获取的行政区划所有信息')
  227. let regioncode = this.data.info.area.length > 0 ? this.data.areacolumnsArr[this.data.info.area.length - 1].filter(item => {
  228. return item.name == this.data.info.area[this.data.info.area.length - 1]
  229. })[0].code : '';
  230. console.log(this.data.info.adress)
  231. let options = {
  232. url: 'resource/miniapp/user/editUserInfo',
  233. data: {
  234. id: this.data.info.id,
  235. name: this.data.info.name,
  236. idcard: this.data.info.idcard,
  237. regioncode,
  238. communityid: this.data.info.adress.length > 0 ? this.data.adresscolumnsArr.filter(item => {
  239. return item.name == this.data.info.adress
  240. })[0].id : '',
  241. address: this.data.info.adressDetails,
  242. phone: this.data.info.tel
  243. },
  244. method: 'post'
  245. }
  246. let res = await request.query(options);
  247. if (res.data.code === 200) {
  248. wx.showModal({
  249. title: '提示',
  250. content: '保存成功',
  251. showCancel: false,
  252. success: (res) => {
  253. if (res.confirm) {
  254. wx.switchTab({
  255. url: '/pages/personInfo/personInfo',
  256. })
  257. }
  258. }
  259. })
  260. } else {
  261. Toast.fail(res.data.msg);
  262. }
  263. // }
  264. // console.log(this.data.errorinfo)
  265. },
  266. onLoad: function () {
  267. },
  268. onShow() {
  269. if (!wx.getStorageSync('userId')) {
  270. wx.showModal({
  271. title: '提示',
  272. content: '请扫描二维码进入小程序',
  273. showCancel: false,
  274. success: (res) => {
  275. if (res.confirm) {
  276. wx.navigateTo({
  277. url: '/pages/login/login',
  278. })
  279. }
  280. }
  281. })
  282. return false;
  283. }
  284. tools.isLogin().then((res) => {
  285. // this.getArea();
  286. this.getInfo();
  287. this.setData({
  288. readonly: app.globalData.type === 'jhdx' ? false : true
  289. })
  290. }, (error) => {
  291. console.log(error);
  292. })
  293. }
  294. })