addition.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const APP = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. deviceNum: "",
  8. },
  9. /**
  10. * 扫码
  11. */
  12. scanCode: function () {
  13. const that = this;
  14. wx.scanCode({
  15. success(res) {
  16. that.setData({
  17. deviceNum: res.result
  18. })
  19. },
  20. fail: function () {
  21. console.log("调用摄像头失败")
  22. }
  23. })
  24. },
  25. /**
  26. * 提交表单
  27. */
  28. submit: function (form) {
  29. const params = {
  30. name: form.detail.value.deviceName,
  31. deviceNum: form.detail.value.deviceNum,
  32. }
  33. if (params.deviceNum == null || params.deviceNum === "") {
  34. APP.Modal.tips("请输入设备码!")
  35. return;
  36. }
  37. if (params.name == null || params.name === "") {
  38. APP.Modal.tips("请输入设备名称!")
  39. return;
  40. }
  41. //禁用提交按钮
  42. this.setData({
  43. deviceNum: "",
  44. deviceName: "",
  45. })
  46. APP.Post(APP.Url.bind, params).then(res => {
  47. //更新设备集合
  48. APP.Get(APP.Url.getListByUserId, params, false).then(res => {
  49. APP.globalData.deviceList = res.data;
  50. APP.Modal.tips("添加成功!");
  51. })
  52. })
  53. },
  54. })