three_yards.js 11 KB

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