msBank.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import Dialog from '@vant/weapp/dialog/dialog';
  2. const util = require('../../../utils/util');
  3. const check = require('../../../utils/check');
  4. const api = require('../../../config/api');
  5. const user = require('../../../utils/user.js');
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. code: '',
  13. showSubmitBtn: true,
  14. userInfo: {
  15. nickName: '点击登录',
  16. avatarUrl: '/static/images/new/icon-user.png',
  17. isDis: false
  18. },
  19. hasLogin: false,
  20. myqr_show: false,
  21. infoGoods: app.globalData.infoGoods,
  22. customerName: '',
  23. customerTel: '',
  24. address: '',
  25. addressId: '',
  26. serviceModelText: '请选择',
  27. serviceModel: '',
  28. // startServiceTime:'请选择',
  29. typePickerShow: false,
  30. timePickerShow: false,
  31. serviceModelList: [{
  32. id: '1',
  33. name: '钟点工'
  34. },
  35. {
  36. id: '2',
  37. name: '白班保姆'
  38. },
  39. {
  40. id: '3',
  41. name: '住家保姆'
  42. },
  43. {
  44. id: '4',
  45. name: '月嫂'
  46. },
  47. {
  48. id: '5',
  49. name: '代班保姆-钟点工'
  50. },
  51. {
  52. id: '6',
  53. name: '代班保姆-保姆'
  54. },
  55. ],
  56. typeColumns: ['钟点工', '白班保姆', '住家保姆', '月嫂', '代班保姆-钟点工', '代班保姆-保姆'],
  57. //typeColumns: ['钟点工', '白班保姆', '住家保姆', '月嫂', '育儿嫂', '其他'],
  58. currentDate: new Date().getTime(),
  59. minDate: new Date().getTime(),
  60. },
  61. /**
  62. * 生命周期函数--监听页面加载
  63. */
  64. onLoad: function (options) {
  65. },
  66. showPoster() {
  67. this.setData({
  68. myqr_show: true
  69. });
  70. },
  71. hidePoster() {
  72. this.setData({
  73. myqr_show: false
  74. });
  75. },
  76. selectAddress() {
  77. if (this.data.hasLogin == false) {
  78. wx.navigateTo({
  79. url: "/pages/auth/login/login"
  80. });
  81. return;
  82. }
  83. wx.navigateTo({
  84. url: '/pages/ucenter/address/address',
  85. })
  86. },
  87. formatterDate(type, value) {
  88. if (type === 'year') {
  89. return `${value}年`;
  90. }
  91. if (type === 'month') {
  92. return `${value}月`;
  93. }
  94. return value;
  95. },
  96. onTimeCancel() {
  97. this.setData({
  98. timePickerShow: false,
  99. });
  100. },
  101. onTimeConfirm(event) {
  102. console.log(event);
  103. this.setData({
  104. startServiceTime: util.formetdate(new Date(event.detail)),
  105. timePickerShow: false,
  106. });
  107. },
  108. showServicePicker() {
  109. this.setData({
  110. typePickerShow: true,
  111. });
  112. },
  113. showTimePicker() {
  114. this.setData({
  115. timePickerShow: true,
  116. });
  117. },
  118. onTypeCancel: function () {
  119. this.setData({
  120. typePickerShow: false,
  121. });
  122. },
  123. onTypeConfirm: function (event) {
  124. this.setData({
  125. serviceModel: this.data.serviceModelList[event.detail.index].id,
  126. serviceModelText: event.detail.value,
  127. typePickerShow: false,
  128. });
  129. },
  130. confirmSubmit() {
  131. if (this.data.hasLogin == false) {
  132. wx.navigateTo({
  133. url: "/pages/auth/login/login"
  134. });
  135. return;
  136. }
  137. if (this.data.customerName == '') {
  138. wx.showToast({
  139. title: '请输入客户名称',
  140. icon: 'none',
  141. duration: 2000
  142. });
  143. return false;
  144. }
  145. if (this.data.customerTel == '') {
  146. wx.showToast({
  147. title: '请输入手机号',
  148. icon: 'none',
  149. duration: 2000
  150. });
  151. return false;
  152. }
  153. if (this.data.customerTel=='') {
  154. // util.showErrorToast('请输入正确的手机号码');
  155. wx.showToast({
  156. title: '输入正确的手机号码',
  157. icon: 'none',
  158. duration: 2000
  159. });
  160. return false;
  161. }
  162. if (this.data.address == '') {
  163. wx.showToast({
  164. title: '请输入详细住址',
  165. icon: 'none',
  166. duration: 2000
  167. });
  168. return false;
  169. }
  170. if (this.data.serviceModelText == '请选择') {
  171. wx.showToast({
  172. title: '请选择服务类型',
  173. icon: 'none',
  174. duration: 2000
  175. });
  176. return false;
  177. }
  178. let that = this;
  179. console.log('校验成功');
  180. wx.showLoading({
  181. title: '提交中...',
  182. mask: true,
  183. });
  184. util.request(api.addClueMs, {
  185. "customerName": this.data.customerName,
  186. "customerTel": this.data.customerTel,
  187. "address": this.data.address,
  188. "serviceModel": this.data.serviceModel,
  189. "userId": this.data.userInfo.id
  190. }, "POST")
  191. .then((res) => {
  192. wx.hideLoading();
  193. if (res.errno == 0) {
  194. that.showPoster();
  195. that.setData({
  196. showSubmitBtn: false
  197. })
  198. } else {
  199. util.showErrorToast(res.errmsg);
  200. }
  201. }).catch(() => {
  202. wx.hideLoading();
  203. });
  204. },
  205. /**
  206. * 生命周期函数--监听页面初次渲染完成
  207. */
  208. onReady: function () {
  209. },
  210. /**
  211. * 生命周期函数--监听页面显示
  212. */
  213. onShow: function () {
  214. let that = this;
  215. if (app.globalData.hasLogin) {
  216. let userInfo = wx.getStorageSync('userInfo');
  217. this.setData({
  218. userInfo: userInfo,
  219. hasLogin: true,
  220. customerTel:userInfo.mobile
  221. });
  222. app.globalData.userInfo = userInfo;
  223. } else {
  224. user.login().then(res => {
  225. console.info(res)
  226. that.setData({
  227. code: res.code
  228. })
  229. })
  230. }
  231. },
  232. getPhoneNumber: function (e) {
  233. var ivObj = e.detail.iv
  234. var telObj = e.detail.encryptedData
  235. var that = this;
  236. //------执行Login---------
  237. util.request(api.AuthRegister, {
  238. code: that.data.code,
  239. encryptedData: telObj,
  240. iv: ivObj,
  241. r_userid: 0
  242. }).then(function (res) {
  243. if (res.errno === 0) {
  244. //存储用户信息
  245. app.globalData.hasLogin = true;
  246. app.globalData.userInfo = res.data.userInfo;
  247. wx.setStorageSync('userInfo', res.data.userInfo);
  248. wx.setStorageSync('token', res.data.token);
  249. that.setData({
  250. hasLogin:true,
  251. userInfo:res.data.userInfo,
  252. customerTel:res.data.userInfo.mobile
  253. });
  254. wx.showToast({
  255. title: '授权手机号成功',
  256. icon: 'success',
  257. duration: 2000,
  258. })
  259. } else {
  260. console.info(res);
  261. wx.showToast({
  262. title: '授权失败请重试',
  263. icon: 'error',
  264. duration: 3000
  265. });
  266. }
  267. });
  268. //-----------------是否授权,授权通过进入主页面,授权拒绝则停留在登陆界面
  269. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击拒绝
  270. wx.showModal({
  271. title: '警告',
  272. content: '您点击了拒绝授权,部分功能无法使用!!!',
  273. showCancel: false,
  274. confirmText: '确定',
  275. success: function (res) {
  276. // 用户没有授权成功,不需要改变 isHide 的值
  277. if (res.confirm) {
  278. };
  279. }
  280. })
  281. }
  282. },
  283. /**
  284. * 生命周期函数--监听页面隐藏
  285. */
  286. onHide: function () {
  287. },
  288. /**
  289. * 生命周期函数--监听页面卸载
  290. */
  291. onUnload: function () {
  292. },
  293. /**
  294. * 页面相关事件处理函数--监听用户下拉动作
  295. */
  296. onPullDownRefresh: function () {
  297. },
  298. /**
  299. * 页面上拉触底事件的处理函数
  300. */
  301. onReachBottom: function () {
  302. },
  303. /**
  304. * 用户点击右上角分享
  305. */
  306. onShareAppMessage: function () {
  307. }
  308. })