forked from nsjcy/frontEnd/nsjcy

liuwh
2020-04-27 4e44bc1fd7806a6c1611302120882b91d96640b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// pages/pfyy/pfyy.js
 
const app = getApp();
var Validator = require("../../utils/validate.tools.js");
const verify = Validator.Validator;
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    disabled: false,
    id: '',
    picType: '',
    evalList: {},
    picturesInfo: {},
    ReplyLogs: []
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    console.log(options)
    let id = options.id
    let disabled = options.disabled
    var userinfo = wx.getStorageSync("user");
    wx.request({
      url: app.globalData.url + '/api/v1/appointment/find?id=' + id,
      success: function(res) {
        console.log(res.data.data.lawAppointment)
        if (res.data.code == 0) {
          var data1 = res.data.data.ReplyLogs || [];
          that.setData({
            picturesInfo: {
              ...res.data.data.lawAppointment,
              createId: userinfo.id,
              activitiesTime: app.formatDateday(res.data.data.lawAppointment.activitiesTime || new Date())
            },
            ReplyLogs: data1,
            disabled
          })
        } else {
          wx.showModal({
            title: '提示',
            content: "请求失败!"
          })
        }
      }
    })
  },
 
  inputChange: function(e) {
    var name = e.currentTarget.dataset.name;
    this.setData({
      picturesInfo: {
        ...this.data.picturesInfo,
        [name]: e.detail.value
      }
    })
 
  },
 
  reply: function(e) {
    var that = this;
    var openId = wx.getStorageSync("openId")
    var obj = {
      openId: openId,
      content: that.data.picturesInfo.replyContent,
      busType: 25,
      busId: that.data.picturesInfo.id
    };
    wx.request({
      url: app.globalData.url + '/api/v1/appointment/reply',
      data: obj,
      method: 'POST',
      header: {
        "Content-Type": "application/json"
      },
      success: function(res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交回复成功',
            icon: 'success',
            duration: 2000
          })
          setTimeout(function() {
            wx.navigateBack({
              changed: true
            }); //返回上一页
          }, 2000)
        } else {
          wx.showModal({
            title: '提示',
            content: "提交失败!"
          })
        }
      }
    })
  },
 
  submit: function(e) {
    var picturesInfo = this.data.picturesInfo;
    if (!picturesInfo.schoolName) {
      return app.showModal("请填写学校名称!");
    }
    if (!picturesInfo.schoolAddress) {
      return app.showModal("请填写学校地址!");
    }
    if (!picturesInfo.contactName) {
      return app.showModal("请填写联系人!");
    }
    if (!picturesInfo.contactPhone) {
      return app.showModal("请填写手机号码!");
    }
    if (/^[1]([3-9])[0-9]{9}$/.test(picturesInfo.contactPhone) == false) {
      return app.showModal("手机号码有误!");
    }
    if (!picturesInfo.activitiesTime) {
      return app.showModal("请填写活动时间!");
    }
    if (!picturesInfo.content) {
      return app.showModal("请填写普法内容!");
    }
    if (!picturesInfo.activitiesNum) {
      return app.showModal("请填写活动人数!");
    }
    if (!picturesInfo.activitiesAddress) {
      return app.showModal("请填写活动场地!");
    }
    if (!picturesInfo.remake) {
      return app.showModal("请填写备注!");
    }
    var that = this;
    wx.request({
      url: app.globalData.url + '/api/v1/appointment/save',
      data: picturesInfo,
      method: 'POST',
      header: {
        "Content-Type": "application/json"
      },
      success: function(res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 2000
          })
          setTimeout(function() {
            wx.reLaunch({
              url: '../zhwj/zhwj',
            })
          }, 2000)
        } else {
          wx.showModal({
            title: '提示',
            content: "提交失败!"
          })
        }
      }
    })
  },
})