crossBoundaryQuotaQuery.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp()
  4. Page({
  5. data: {
  6. userInfo: {},
  7. curUser: {},
  8. idNoM: '',
  9. idNo: '',
  10. currentIdNo: '',
  11. userName: '',
  12. listData: [],
  13. idCardIsNull: null,
  14. startTime: '',
  15. endTime: '',
  16. isQuery: null
  17. },
  18. onLoad: function (options) {
  19. // 页面初始化 options为页面跳转所带来的参数
  20. let that = this;
  21. var timestamp = Date.parse(new Date());
  22. var date = new Date(timestamp);
  23. //获取年份  
  24. var Y = date.getFullYear();
  25. //获取月份  
  26. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  27. //获取当日日期 
  28. var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  29. console.log("当前时间:" + Y + '年' + M + '月' + D + '日'); 
  30. that.setData({
  31. startTime: Y+'年1月1日00:00',
  32. endTime: Y + '年' + M + '月' + (D-1) + '日24:00'
  33. });
  34. },
  35. onReady: function () {
  36. },
  37. onShow: function () {
  38. let that = this;
  39. let userInfo = wx.getStorageSync('userInfo');
  40. let token = wx.getStorageSync('token');
  41. // 页面显示
  42. if (userInfo && token) {
  43. app.globalData.userInfo = userInfo;
  44. app.globalData.token = token;
  45. this.setData({
  46. userInfo: app.globalData.userInfo,
  47. });
  48. util.request(api.getCurUser, {
  49. userInfo: app.globalData.userInfo
  50. }, 'POST').then(function (res) {
  51. if (res.errno === 0) {
  52. that.setData({
  53. curUser: res.data
  54. });
  55. if (res.data.idNo) {
  56. that.setData({
  57. idNoM: that.formatidcard(res.data.idNo),
  58. idNo: res.data.idNo,
  59. currentIdNo: res.data.idNo,
  60. userName: res.data.username
  61. });
  62. } else {
  63. that.setData({
  64. idCardIsNull: 'true'
  65. });
  66. }
  67. }
  68. });
  69. } else {
  70. wx.navigateTo({
  71. url: '/pages/ucenter/userLogin/userLogin'
  72. })
  73. }
  74. },
  75. onHide: function () {
  76. // 页面隐藏
  77. },
  78. onUnload: function () {
  79. // 页面关闭
  80. },
  81. saveIdCard: function (e) {
  82. this.setData({
  83. isQuery: true
  84. });
  85. wx.showLoading({
  86. title: '加载中...',
  87. })
  88. let that = this;
  89. if (!e.detail.value.idNo) {
  90. wx.showToast({
  91. title: '身份证号不能为空',
  92. icon: 'none'
  93. });
  94. return false;
  95. }
  96. if (!e.detail.value.username) {
  97. wx.showToast({
  98. title: '姓名不能为空',
  99. icon: 'none'
  100. });
  101. return false;
  102. }
  103. if (that.data.idNoM != that.formatidcard(e.detail.value.idNo)) {
  104. that.setData({
  105. idNo: e.detail.value.idNo
  106. });
  107. } else {
  108. that.setData({
  109. idNo: that.data.currentIdNo
  110. });
  111. }
  112. that.setData({
  113. userName: e.detail.value.username
  114. });
  115. if (!that.checkIdcard(that.data.idNo)) {
  116. wx.showToast({
  117. title: '请输入正确的身份证号',
  118. icon: 'none'
  119. });
  120. return false;
  121. }
  122. util.request(api.GetCrossBoundaryQuotaQuery, {
  123. idCard: that.data.idNo,
  124. name: that.data.userName,
  125. merchId: wx.getStorageSync('merchSn'),
  126. storeId: wx.getStorageSync('storeId')
  127. }, 'POST').then(function (res) {
  128. if (res.errno != undefined) {
  129. if (res.errno === 0) {
  130. wx.hideLoading();
  131. that.setData({
  132. listData: [
  133. { "totalAmount": res.data.totalAmount, "innerbalance": res.data.innerbalance }
  134. ],
  135. isQuery: false
  136. });
  137. } else {
  138. wx.showToast({
  139. title: res.errmsg,
  140. icon: 'none'
  141. });
  142. that.setData({
  143. isQuery: false
  144. });
  145. }
  146. } else {
  147. if (res.code != 0) {
  148. wx.showToast({
  149. title: res.msg,
  150. icon: 'none'
  151. });
  152. that.setData({
  153. isQuery: false
  154. });
  155. }
  156. }
  157. });
  158. },
  159. clearData: function () {
  160. let that = this;
  161. that.setData({
  162. idNoM: ''
  163. });
  164. },
  165. formatidcard(idcard) {
  166. if (idcard.length == 15) {
  167. return idcard.replace(/(\d{3})\d{10}(\d{1})/, "$1**********$2");
  168. } else {
  169. return idcard.replace(/(\d{3})\d{13}(\d{1})/, "$1*************$2");
  170. }
  171. },
  172. // 校验身份证号
  173. //校验码校验
  174. checkCode: function (val) {
  175. var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  176. var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  177. var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  178. var code = val.substring(17);
  179. if (p.test(val)) {
  180. var sum = 0;
  181. for (var i = 0; i < 17; i++) {
  182. sum += val[i] * factor[i];
  183. }
  184. if (parity[sum % 11] == code.toUpperCase()) {
  185. return true;
  186. }
  187. }
  188. return false;
  189. },
  190. //省份校验
  191. checkProv: function (val) {
  192. var pattern = /^[1-9][0-9]/;
  193. var provs = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江 ", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北 ", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏 ", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门" };
  194. if (pattern.test(val)) {
  195. if (provs[val]) {
  196. return true;
  197. }
  198. }
  199. return false;
  200. },
  201. //出生日期码校验
  202. checkDate: function (val) {
  203. var pattern = /^(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)$/;
  204. if (pattern.test(val)) {
  205. var year = val.substring(0, 4);
  206. var month = val.substring(4, 6);
  207. var date = val.substring(6, 8);
  208. var date2 = new Date(year + "-" + month + "-" + date);
  209. if (date2 && date2.getMonth() == (parseInt(month) - 1)) {
  210. return true;
  211. }
  212. }
  213. return false;
  214. },
  215. checkIdcard: function (val) {
  216. if (this.checkCode(val)) {
  217. var date = val.substring(6, 14);
  218. if (this.checkDate(date)) {
  219. if (this.checkProv(val.substring(0, 2))) {
  220. return true;
  221. }
  222. }
  223. }
  224. // this.isError("请输入正确身份证号");
  225. return false;
  226. },
  227. // 通过身份证号获取出生日期和性别
  228. getBirthAndSex: function (idCard) {
  229. var that = this;
  230. var info = {};
  231. var birth = (idCard.length === 18) ? idCard.slice(6, 14) : idCard.slice(6, 12);
  232. var order = (idCard.length === 18) ? idCard.slice(-2, -1) : idCard.slice(-1);
  233. info.birthDay = (idCard.length === 18) ? ([birth.slice(0, 4), birth.slice(4, 6), birth.slice(-2)]).join('-') : (['19' + birth.slice(0, 2), birth.slice(2, 4), birth.slice(-2)]).join('-');
  234. info.sex = (order % 2 === 0 ? 2 : 0);
  235. return info;
  236. }
  237. })