three_yards.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. // components/three_yards/three_yards.js
  2. const upload_image = require("../../utils/upload/upload_image");
  3. import international from '../../international/appointment_scence/index'
  4. import {
  5. getXcInfo,
  6. sendMessage,
  7. getJkmAndHs,
  8. } from '../../utils/api/three_yards'
  9. const app = getApp()
  10. Component({
  11. /**
  12. * 组件的属性列表
  13. */
  14. properties: {
  15. // 语言
  16. language: {
  17. type: String,
  18. value: 'ch'
  19. },
  20. // 手机号
  21. xcPhone: {
  22. type: Number
  23. },
  24. //时间秒
  25. moMsgWait: {
  26. type: Number,
  27. value: 60
  28. },
  29. //验证码长度
  30. codeLength: {
  31. type: Number,
  32. value: 6
  33. },
  34. //预约开始时间
  35. startTime: {
  36. type: String
  37. },
  38. //核酸时长(单位小时)
  39. hsHour: {
  40. type: Number,
  41. },
  42. //三码 1-健康码 2-核酸 3-行程码
  43. threeCodeList: {
  44. type: Array
  45. },
  46. //楼宇id
  47. buildingId: {
  48. type: Number,
  49. },
  50. },
  51. /**
  52. * 组件的初始数据
  53. */
  54. data: {
  55. international: international, //国际化语言包
  56. form: {
  57. // xc: null, //行程信息1 代表没有去过高风险地区 2 代表去过高风险地区 3 代表用户没有行程记录
  58. // hs: null, //核酸
  59. // jkm: null, //健康码,1绿2黄3红
  60. // xcPhone: null,
  61. },
  62. moDisabled: false, //验证码是否可点击
  63. moCodeMsg: '获取验证码', //验证码文字
  64. focus: false, // 隐藏的输入框是否获取焦点
  65. codeVal: [], //验证码
  66. inputCodeFocus: [], //验证码样式
  67. },
  68. /**
  69. * 组件的方法列表
  70. */
  71. methods: {
  72. getValue(e) {
  73. let that = this
  74. let {
  75. form
  76. } = this.data
  77. if (e.currentTarget.dataset.type == 'xcPhone') {
  78. form[e.currentTarget.dataset.type] = e.detail.value
  79. } else {
  80. wx.chooseMedia({
  81. count: 1,
  82. mediaType: ['image'],
  83. sizeType: ['original'],
  84. sourceType: ['album', 'camera'],
  85. success(res) {
  86. var image = {
  87. url: res.tempFiles[0].tempFilePath
  88. }
  89. wx.showLoading({
  90. title: '上传中~',
  91. })
  92. upload_image(image).then((img) => {
  93. wx.hideLoading()
  94. form[e.currentTarget.dataset.type] = img.url
  95. that.setData({
  96. form
  97. })
  98. that.verifyForm()
  99. }).catch(() => {
  100. wx.hideLoading()
  101. })
  102. }
  103. })
  104. }
  105. },
  106. // 校验是否填写完整
  107. verifyForm() {
  108. let {
  109. form,
  110. } = this.data
  111. let isthreeYards = form
  112. for (let key in form) {
  113. if (form[key] == '') {
  114. isthreeYards = false
  115. }
  116. }
  117. this.triggerEvent('isthreeYards', isthreeYards)
  118. }, //
  119. //删除照片
  120. DelImg(e) {
  121. let that = this
  122. let form = this.data.form
  123. wx.showModal({
  124. title: '提示',
  125. content: '确定删除?',
  126. cancelText: '取消',
  127. confirmText: '确定',
  128. success: res => {
  129. if (res.confirm) {
  130. form[e.currentTarget.dataset.type] = ''
  131. that.setData({
  132. form
  133. })
  134. that.verifyForm()
  135. }
  136. }
  137. })
  138. },
  139. // 预览图片
  140. previewImg(event) {
  141. // 拿到图片的地址url
  142. let currentUrl = event.currentTarget.dataset.src;
  143. // 微信预览图片的方法
  144. wx.previewImage({
  145. current: currentUrl, // 图片的地址url
  146. urls: [currentUrl] // 预览的地址url
  147. })
  148. },
  149. // 获取验证码
  150. getCode() {
  151. if (this.data.form.xcPhone) {
  152. this.setData({
  153. moDisabled: true
  154. });
  155. wx.showLoading({
  156. title: '发送中...',
  157. })
  158. sendMessage({
  159. phone: this.data.form.xcPhone
  160. }).then(res => {
  161. wx.hideLoading();
  162. if (res.code == 0) {
  163. wx.showToast({
  164. title: '验证码发送成功,请注意查收',
  165. icon: 'none'
  166. })
  167. this.setData({
  168. focus: true
  169. })
  170. var inter = setInterval(function () {
  171. if (this.data.moMsgWait < 1) {
  172. clearInterval(inter)
  173. this.setData({
  174. moCodeMsg: "获取验证码",
  175. moMsgWait: 60,
  176. moDisabled: false,
  177. });
  178. return;
  179. }
  180. this.setData({
  181. moCodeMsg: "重新发送(" + this.data.moMsgWait + ")",
  182. moMsgWait: this.data.moMsgWait - 1,
  183. moDisabled: true
  184. });
  185. }.bind(this), 1000);
  186. } else {
  187. wx.showToast({
  188. title: res.msg,
  189. icon: 'none'
  190. })
  191. this.setData({
  192. moDisabled: true
  193. });
  194. }
  195. })
  196. } else {
  197. wx.showToast({
  198. title: '手机号不能为空!',
  199. icon: 'none'
  200. })
  201. }
  202. },
  203. // 长按
  204. longPressInput() {},
  205. // 失去焦点
  206. blurInput() {
  207. this.inputCodeFocusInit();
  208. this.setData({
  209. focus: false
  210. })
  211. },
  212. // 获取焦点
  213. tapInput() {
  214. let {
  215. codeLength,
  216. codeVal,
  217. inputCodeFocus
  218. } = this.data;
  219. if (codeVal.join('').length == codeLength) {
  220. inputCodeFocus[codeLength - 1] = true
  221. } else {
  222. inputCodeFocus[codeVal.join('').length] = true
  223. };
  224. this.setData({
  225. focus: true,
  226. inputCodeFocus
  227. })
  228. },
  229. // 输入验证码
  230. inputVal(e) {
  231. let value = e.detail.value;
  232. let {
  233. codeLength,
  234. codeVal,
  235. inputCodeFocus,
  236. focus
  237. } = this.data;
  238. inputCodeFocus = new Array(codeLength).fill(false);
  239. if (value.length > codeVal.join('').length) {
  240. inputCodeFocus[value.length - 1 >= 0 ? value.length - 1 : 0] = false;
  241. if (value.length == codeLength) {
  242. focus = false
  243. } else {
  244. inputCodeFocus[value.length] = true;
  245. }
  246. } else {
  247. if (value.length == 0) {
  248. inputCodeFocus[0] = true
  249. } else {
  250. inputCodeFocus[value.length - 1] = true
  251. }
  252. }
  253. codeVal = codeVal.map((item, index) => {
  254. return value.split('')[index] || ''
  255. })
  256. this.setData({
  257. codeVal,
  258. inputCodeFocus,
  259. focus
  260. })
  261. // 判断参数是否填写完全,若完全,查询接口,接口返回成功,隐藏手机号和验证码两行
  262. if (codeVal.join('').length == codeLength) {
  263. this.getXcInfo()
  264. }
  265. },
  266. // 获取行程信息
  267. getXcInfo() {
  268. wx.showLoading({
  269. title: '查询中..',
  270. })
  271. let {
  272. form,
  273. codeVal,
  274. } = this.data;
  275. form.verification = codeVal.join('')
  276. getXcInfo({
  277. verification: form.verification,
  278. phone: form.xcPhone,
  279. adminId: this.data.buildingId,
  280. }).then(res => {
  281. if (res.code == 200) {
  282. form.xc = res.data
  283. if (res.data == 3) {
  284. form.xcPhoto = ''
  285. }
  286. this.setData({
  287. form
  288. })
  289. this.verifyForm()
  290. } else {
  291. wx.showToast({
  292. title: res.msg,
  293. icon: 'none'
  294. })
  295. }
  296. wx.hideLoading()
  297. })
  298. },
  299. // 获取健康码和核酸信息
  300. getJkmAndHs() {
  301. let {
  302. form
  303. } = this.data
  304. let {
  305. userInfo
  306. } = app.data
  307. wx.showLoading({
  308. title: '查询账号配置~',
  309. })
  310. getJkmAndHs({
  311. idNumber: userInfo.idNumber,
  312. name: userInfo.username,
  313. phone: userInfo.phone,
  314. adminId: this.data.buildingId,
  315. }).then(res => {
  316. if (res.data.jkmStatus == 1) {
  317. form.jkm = res.data.jkm
  318. if (res.data.jkm != '绿码') {
  319. wx.showToast({
  320. title: '健康码状态异常哦~',
  321. icon: 'none'
  322. })
  323. this.setData({
  324. 'form.unqualifiedJKM': ''
  325. })
  326. }
  327. } else if (res.data.jkmStatus == 2) {
  328. form.jkmPhoto = ''
  329. }
  330. // res.data.hsStatus = 1;
  331. // form.hsStatus = 1
  332. if (res.data.hsStatus == 1) {
  333. // form.hsResultTime = res.data.hsResultTime || '2022-11-24 12:15:00'
  334. // form.hs = res.data.hs || '阴性'
  335. // res.data.hs = '阴性'
  336. let startTime_number = this.data.startTime ? Date.parse(new Date(this.data.startTime)) : Date.now();
  337. let resultTime_number = Date.parse(new Date(form.hsResultTime));
  338. if (((startTime_number - resultTime_number) >= this.data.hsHour * 60 * 60 * 1000) || res.data.hs !== "阴性") {
  339. wx.showToast({
  340. title: '您不满足进入时拥有' + this.data.hsHour + '小时内阴性核酸报告',
  341. icon: 'none'
  342. })
  343. form.unqualifiedHS = ''
  344. } else {
  345. form.unqualifiedHS = true
  346. }
  347. } else if (res.data.hsStatus == 2) {
  348. setTimeout(() => {
  349. wx.showToast({
  350. title: '您不满足进入时拥有' + this.data.hsHour + '小时内阴性核酸报告',
  351. icon: 'none'
  352. })
  353. setTimeout(() => {
  354. wx.hideToast();
  355. }, 2000)
  356. }, 0);
  357. form.hsPhoto = ''
  358. }
  359. this.setData({
  360. form
  361. })
  362. wx.hideLoading()
  363. this.verifyForm()
  364. })
  365. },
  366. //输入数据初始化
  367. codeValInit() {
  368. this.data.codeVal = new Array(this.data.codeLength).fill('');
  369. this.setData({
  370. codeVal: this.data.codeVal
  371. })
  372. },
  373. //焦点数据初始化
  374. inputCodeFocusInit() {
  375. this.data.inputCodeFocus = new Array(this.data.codeLength).fill(false);
  376. this.setData({
  377. inputCodeFocus: this.data.inputCodeFocus
  378. })
  379. }
  380. },
  381. observers: {
  382. 'xcPhone': function (n) {
  383. if (n) {
  384. let {
  385. form,
  386. } = this.data
  387. form.xcPhone = n
  388. this.setData({
  389. form
  390. })
  391. }
  392. },
  393. 'startTime': function (n) {
  394. this.getJkmAndHs();
  395. },
  396. threeCodeList(n) {
  397. this.setData({
  398. form: {
  399. xcPhone: this.data.xcPhone,
  400. },
  401. })
  402. if (n.indexOf('1') > -1 || n.indexOf('2') > -1) {
  403. this.getJkmAndHs()
  404. }
  405. if (n.indexOf('3') > -1) {
  406. this.setData({
  407. 'form.xc': ''
  408. })
  409. }
  410. },
  411. },
  412. lifetimes: {
  413. attached() {
  414. this.codeValInit()
  415. this.inputCodeFocusInit()
  416. }
  417. }
  418. })