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.

298 lines
7.1 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({
  110. // title: '请输入完整的用户信息',
  111. // icon: "none"
  112. // })
  113. // } else {}
  114. let tmeparr = []
  115. tmeparr = JSON.parse(JSON.stringify(that.data.childArr))
  116. console.log(that.data.childArr)
  117. tmeparr.map(item => {
  118. item.birthdate = new Date(item.birthdate).getTime()
  119. })
  120. console.log(that.data.childArr)
  121. Http.post({
  122. url: config.api.updateInfo,
  123. data: {
  124. sex: sex,
  125. address: address,
  126. name: username,
  127. birthdate: birthdate,
  128. childrenList: tmeparr,
  129. height: e.detail.value.height ? e.detail.value.height : that.data.height,
  130. weight: e.detail.value.weight ? e.detail.value.weight : that.data.weight,
  131. }
  132. })
  133. .then(res => {
  134. wx.showToast({
  135. title: "信息提交成功,将在3分钟内生效",
  136. icon: 'none',
  137. duration: 2000,
  138. mask: false
  139. }),
  140. setTimeout(() => {
  141. wx.navigateBack()
  142. }, 2000)
  143. })
  144. .catch(err => {
  145. wx.showToast({
  146. title: err.message,
  147. icon: 'none',
  148. duration: 2000,
  149. mask: false
  150. })
  151. })
  152. },
  153. radioChange: function (e) {
  154. this.setData({
  155. sex: e.detail.value,
  156. flagsex: 1
  157. })
  158. },
  159. childSex(e) {
  160. let index = e.currentTarget.dataset.index
  161. let tmpeObj = this.data.childArr
  162. tmpeObj[index].sex = e.detail.value
  163. this.setData({
  164. childArr: tmpeObj
  165. })
  166. console.log(tmpeObj)
  167. },
  168. chidBirthday(e) {
  169. let index = e.currentTarget.dataset.index
  170. let tmpeObj = this.data.childArr
  171. tmpeObj[index].birthdate = e.detail.value
  172. this.setData({
  173. childArr: tmpeObj
  174. })
  175. },
  176. chidName(e) {
  177. let index = e.currentTarget.dataset.index
  178. let tmpeObj = this.data.childArr
  179. tmpeObj[index].name = e.detail.value
  180. this.setData({
  181. childArr: tmpeObj
  182. })
  183. },
  184. childDel(e) {
  185. let index = e.currentTarget.dataset.index
  186. let tmpeObj = this.data.childArr
  187. tmpeObj.splice(index, 1)
  188. this.setData({
  189. childArr: tmpeObj
  190. })
  191. },
  192. childAdd() {
  193. let tmpeObj = this.data.childArr
  194. tmpeObj.unshift({ sex: 1 })
  195. this.setData({
  196. childArr: tmpeObj
  197. })
  198. },
  199. /**
  200. * 生命周期函数--监听页面加载
  201. */
  202. onLoad: function (options) {
  203. if (1 * options.type) {
  204. this.setData({
  205. type: false
  206. })
  207. }
  208. let tmpeDateEnd = util.formatTime(new Date(), "yyyy-MM-dd")
  209. let that = this;
  210. that.setData({
  211. dateEnd: tmpeDateEnd
  212. })
  213. Http.get({
  214. url: config.api.getScore,
  215. data: {},
  216. })
  217. .then(res => {
  218. res.data
  219. console.log(res);
  220. if (res.code == 200) {
  221. if (res.data.weight) {
  222. this.setData({
  223. weight: res.data.weight
  224. })
  225. }
  226. if (res.data.height) {
  227. this.setData({
  228. height: res.data.height
  229. })
  230. }
  231. if (res.data.childrenList) {
  232. let tmpeArr = res.data.childrenList
  233. tmpeArr.map(item => {
  234. item.birthdate = util.fmtDate(parseInt(item.birthdate))
  235. that.setData({
  236. childArr: tmpeArr
  237. })
  238. })
  239. }
  240. that.setData({
  241. showPage: true,
  242. })
  243. }
  244. var reg = RegExp(/address/);
  245. if (res && res.data && res.data.address && res.data.address.match(reg)) {
  246. that.setData({
  247. address: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name,
  248. addressStr: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name
  249. })
  250. } else {
  251. that.setData({
  252. address: res.data.address,
  253. addressStr: res.data.address
  254. })
  255. }
  256. if (res.data.name) {
  257. that.setData({
  258. username: res.data.name
  259. })
  260. }
  261. if (res.data.sex) {
  262. if (res.data.sex == 1) {
  263. var checked = 'items[' + 0 + '].checked'
  264. that.setData({
  265. [checked]: true,
  266. flagsex: 1
  267. })
  268. } else if (res.data.sex == 2) {
  269. var checked = 'items[' + 1 + '].checked'
  270. that.setData({
  271. [checked]: true,
  272. flagsex: 1
  273. })
  274. }
  275. that.setData({
  276. sex: res.data.sex
  277. })
  278. }
  279. if (res.data.birthdate) {
  280. that.setData({
  281. date: util.fmtDate(parseInt(res.data.birthdate)),
  282. flag: 2
  283. })
  284. }
  285. })
  286. .catch(error => {
  287. wx.showToast({
  288. title: error.errMsg,
  289. icon: 'none',
  290. duration: 2000,
  291. mask: false
  292. });
  293. })
  294. }
  295. })