12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //获取应用实例
- const app = getApp()
- Page({
- data: {
- start_date: '',
- periodArr: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],
- menstrualArr: [3, 4, 5, 6, 7, 8],
- periodIndex: 8,
- index: 3,
- hiddenPicker: false,
- defaultPeriod: '',
- defaultCycle: ''
- },
- onLoad: function (e) {
- let that = this, today = '', choose_start = 0;
- let defaultPeriod = '', defaultCycle = '', latest_info = wx.getStorageSync('latest_info');
- today = app.getFormat(new Date(), 'yyyy/MM/dd');
- if (latest_info) {
- latest_info = JSON.parse(latest_info);
- defaultPeriod = latest_info.menstruate_days
- defaultCycle = latest_info.menstruate_period
- }
- choose_start = app.getFormat(new Date((app.getTimestamp(app.getFormat(new Date(), 'yyyy/MM/dd')) - 44 * app.globalData.TIME_TURN) *1000), 'yyyy/MM/dd');
- that.getToday();
- if (!app.globalData.token) {
- app.login(that)
- }
- that.setData({today: app.toWechatFormat(today), choose_start: app.toWechatFormat(choose_start), defaultPeriod: defaultPeriod, defaultCycle: defaultCycle})
- },
- getToday () {
- let that = this, date = new Date();
- let today = app.getFormat(date, 'yyyy/MM/dd');
- that.setData({start_date: app.toWechatFormat(today)})
- },
- bindPeriodChange (e) {
- this.setData({
- defaultCycle: '',
- periodIndex: e.detail.value
- })
- },
- bindMenstrualChange (e) {
- this.setData({
- defaultPeriod: '',
- index: e.detail.value
- })
- },
- finishSetting () {
- const that = this;
- let latest_info = wx.getStorageSync('latest_info');
- let menstruate_period =that.data.defaultCycle || that.data.periodArr[that.data.periodIndex],
- menstruate_days =that.data.defaultPeriod || that.data.menstrualArr[that.data.index];
- if (latest_info) {
- latest_info = JSON.parse(latest_info);
- latest_info.menstruate_period = menstruate_period;
- latest_info.menstruate_days = menstruate_days;
- wx.setStorageSync('latest_info', JSON.stringify(latest_info));
- wx.request({
- url: app.globalData.HOST + '/api/mini_user/setUserSetting',
- method: 'POST',
- header: {
- "token": app.globalData.token
- },
- data: {
- info: {
- menstruate_period: menstruate_period,
- menstruate_days: menstruate_days
- },
- flag: 0
- },
- success: function(res) {
- if (res.data.errno == 0) {
- app.getMonthPeriod(new Date().getFullYear())
- }else if(res.data.errno == 401){
- app.login(that)
- }
- }
- });
- app.confirmModal('恭喜你设置完成啦', false, app.getToIndex)
- }else{
- wx.redirectTo({url: '/pages/firstSetting/firstSetting'})
- }
- },
- formSubmit(e) {
- let that = this, formId = e.detail.formId;
- app.getFromid(formId);
- }
- })
|