C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 regels
8.7 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 60) + 'px'
  2. const util = require("../../utils/util.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const config = require("../../config/config");
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. childArr: [],
  12. navigationBarHeight,
  13. chevronUrl: imgurl.chevron.url,
  14. date: '1988-03-12',
  15. dateEnd: '',
  16. flag: 1,
  17. flagsex: 0,
  18. height: "",
  19. weight: "",
  20. items: [
  21. { name: 1, value: '男', checked: false },
  22. { name: 2, value: '女', checked: false },
  23. ],
  24. username: "",
  25. array: ['上班族', '学生', '企业高管', '个体户', '自由职业', '其他'],
  26. array1: ['附近住户', '距离2km', '距离3km', '更远'],
  27. index: 0,
  28. index1: 0,
  29. showPage: false,
  30. type: true
  31. },
  32. /**
  33. * 获得生日
  34. */
  35. bindDateChange: function (e) {
  36. this.setData({
  37. date: e.detail.value,
  38. flag: 2
  39. })
  40. },
  41. /**
  42. * 职业
  43. */
  44. bindPickerChange: function (e) {
  45. this.setData({
  46. index: e.detail.value
  47. })
  48. },
  49. /**
  50. * 生活半径
  51. */
  52. bindPickerChange1: function (e) {
  53. this.setData({
  54. index1: e.detail.value
  55. })
  56. },
  57. address: function () {
  58. return
  59. // let that = this;
  60. // wx.choose
  61. // Location({
  62. // success: function (res) {
  63. // that.setData({
  64. // address: res.name + '(' + res.address + ')',
  65. // addressStr: JSON.stringify(res)
  66. // })
  67. // },
  68. // fail: function (error) {
  69. // console.log(error)
  70. // },
  71. // complete: function (data) {
  72. // }
  73. // })
  74. },
  75. formSubmit: function (e) {
  76. console.log(e.detail, "formSubmit")
  77. let that = this;
  78. // console.log(that.data.childArr)
  79. /**
  80. * sex
  81. * 0 保密
  82. * 1 男
  83. * 2 女
  84. */
  85. if (that.data.flagsex == 0) {
  86. var sex = 0;
  87. } else {
  88. var sex = that.data.sex;
  89. }
  90. if (that.data.addressStr) {
  91. var address = that.data.addressStr;
  92. }
  93. else {
  94. var address = null;
  95. }
  96. if (e.detail.value.username) {
  97. var username = e.detail.value.username;
  98. }
  99. else if (that.data.username) {
  100. var username = that.data.username;
  101. }
  102. else {
  103. var username = null;
  104. }
  105. if (that.data.flag == 2 && that.data.date) {
  106. var birthdate = new Date(that.data.date).getTime();
  107. } else {
  108. var birthdate = null;
  109. }
  110. // if (username == null || address == null || sex == 0 || birthdate == null) {
  111. // wx.showToast({chidName
  112. // title: '请输入完整的用户信息',
  113. // icon: "none"
  114. // })
  115. // } else {}
  116. if (!that.data.type) {
  117. let tempArr = []
  118. tempArr = JSON.parse(JSON.stringify(that.data.childArr))
  119. tempArr.map(item => {
  120. if (item.birthdate) {
  121. item.birthdate = new Date(item.birthdate).getTime()
  122. let data = JSON.stringify(tempArr)
  123. Http.post({
  124. url: '/userBasicInfoChild/saveList', data
  125. }).then(res => {
  126. console.log(res);
  127. if (res.code == 200) {
  128. wx.showToast({
  129. title: "信息提交成功,将在3分钟内生效",
  130. icon: 'none',
  131. duration: 2000,
  132. mask: false
  133. })
  134. setTimeout(() => {
  135. wx.navigateBack()
  136. }, 2000)
  137. }
  138. }).catch(err => {
  139. console.log(err);
  140. })
  141. } else {
  142. wx.showToast({
  143. title: '请填写生日',
  144. icon: 'warning',
  145. duration: 2000,
  146. })
  147. return
  148. }
  149. })
  150. }
  151. return
  152. Http.post({
  153. url: config.api.updateInfo,
  154. data: {
  155. sex: sex,
  156. address: address,
  157. name: username,
  158. birthdate: birthdate,
  159. childrenList: tmeparr,
  160. height: e.detail.value.height ? e.detail.value.height : that.data.height,
  161. weight: e.detail.value.weight ? e.detail.value.weight : that.data.weight,
  162. }
  163. })
  164. .then(res => {
  165. wx.showToast({
  166. title: "信息提交成功,将在3分钟内生效",
  167. icon: 'none',
  168. duration: 2000,
  169. mask: false
  170. }),
  171. setTimeout(() => {
  172. wx.navigateBack()
  173. }, 2000)
  174. })
  175. .catch(err => {
  176. wx.showToast({
  177. title: err.message,
  178. icon: 'none',
  179. duration: 2000,
  180. mask: false
  181. })
  182. })
  183. },
  184. radioChange: function (e) {
  185. this.setData({
  186. sex: e.detail.value,
  187. flagsex: 1
  188. })
  189. },
  190. childSex(e) {
  191. let index = e.currentTarget.dataset.index
  192. let tmpeObj = this.data.childArr
  193. tmpeObj[index].sex = e.detail.value
  194. this.setData({
  195. childArr: tmpeObj
  196. })
  197. console.log(tmpeObj)
  198. },
  199. chidBirthday(e) {
  200. let index = e.currentTarget.dataset.index
  201. let tmpeObj = this.data.childArr
  202. tmpeObj[index].birthdate = e.detail.value
  203. this.setData({
  204. childArr: tmpeObj
  205. })
  206. },
  207. chidName(e) {
  208. let index = e.currentTarget.dataset.index
  209. let tempObj = this.data.childArr
  210. tempObj[index].name = e.detail.value
  211. this.setData({
  212. childArr: tempObj
  213. })
  214. },
  215. childDel(e) {
  216. let index = e.currentTarget.dataset.index
  217. let id = null
  218. let tmpeObj = this.data.childArr
  219. tmpeObj.splice(index, 1)
  220. this.setData({
  221. childArr: tmpeObj
  222. })
  223. if (e.currentTarget.dataset.id) {
  224. id = e.currentTarget.dataset.id
  225. Http.get({
  226. url: `/userBasicInfoChild/del?id=${id}`,
  227. }).then(res => {
  228. console.log(res);
  229. wx.showToast({
  230. title: "删除成功",
  231. icon: 'none',
  232. duration: 2000
  233. })
  234. }).catch(err => {
  235. console.log(err);
  236. })
  237. }
  238. },
  239. childAdd() {
  240. let tmpeObj = this.data.childArr
  241. tmpeObj.unshift({ sex: 1 })
  242. this.setData({
  243. childArr: tmpeObj
  244. })
  245. },
  246. /**
  247. * 生命周期函数--监听页面加载
  248. */
  249. onLoad: function (options) {
  250. if (1 * options.type) {
  251. this.setData({
  252. type: false
  253. })
  254. }
  255. Http.get({
  256. url: '/userBasicInfoChild/list?pageNum=1&pageSize=100',
  257. }).then(res => {
  258. console.log(res);
  259. if (res.data.list) {
  260. let tmpeArr = res.data.list
  261. tmpeArr.map(item => {
  262. item.birthdate = util.fmtDate(parseInt(item.birthdate))
  263. that.setData({
  264. childArr: tmpeArr
  265. })
  266. })
  267. }
  268. }).catch(err => {
  269. console.log(err)
  270. })
  271. let tmpeDateEnd = util.formatTime(new Date(), "yyyy-MM-dd")
  272. let that = this;
  273. that.setData({
  274. dateEnd: tmpeDateEnd
  275. })
  276. Http.get({
  277. url: config.api.getScore,
  278. data: {},
  279. })
  280. .then(res => {
  281. if (res.code == 200) {
  282. if (res.data.weight) {
  283. this.setData({
  284. weight: res.data.weight
  285. })
  286. }
  287. if (res.data.height) {
  288. this.setData({
  289. height: res.data.height
  290. })
  291. }
  292. if (res.data.childrenList) {
  293. let tmpeArr = res.data.childrenList
  294. tmpeArr.map(item => {
  295. item.birthdate = util.fmtDate(parseInt(item.birthdate))
  296. that.setData({
  297. childArr: tmpeArr
  298. })
  299. })
  300. }
  301. that.setData({
  302. showPage: true,
  303. })
  304. }
  305. var reg = RegExp(/address/);
  306. if (res && res.data && res.data.address && res.data.address.match(reg)) {
  307. that.setData({
  308. address: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name,
  309. addressStr: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name
  310. })
  311. } else {
  312. that.setData({
  313. address: res.data.address,
  314. addressStr: res.data.address
  315. })
  316. }
  317. if (res.data.name) {
  318. that.setData({
  319. username: res.data.name
  320. })
  321. }
  322. if (res.data.sex) {
  323. if (res.data.sex == 1) {
  324. var checked = 'items[' + 0 + '].checked'
  325. that.setData({
  326. [checked]: true,
  327. flagsex: 1
  328. })
  329. } else if (res.data.sex == 2) {
  330. var checked = 'items[' + 1 + '].checked'
  331. that.setData({
  332. [checked]: true,
  333. flagsex: 1
  334. })
  335. }
  336. that.setData({
  337. sex: res.data.sex
  338. })
  339. }
  340. if (res.data.birthdate) {
  341. that.setData({
  342. date: util.fmtDate(parseInt(res.data.birthdate)),
  343. flag: 2
  344. })
  345. }
  346. })
  347. .catch(error => {
  348. wx.showToast({
  349. title: error.errMsg,
  350. icon: 'none',
  351. duration: 2000,
  352. mask: false
  353. });
  354. })
  355. }
  356. })