C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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