settledStore.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const util = require('../../utils/util.js');
  2. const form = require('../../utils/formValidation');
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. storeList: [],
  10. values: {
  11. storeId: '',
  12. storeName: '',
  13. deviceSn: '',
  14. deviceLocation: '',
  15. remark: ''
  16. }
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. this.bindStoreList()
  23. },
  24. scanCodeEvent() {
  25. var that = this;
  26. wx.scanCode({
  27. onlyFromCamera: true, // 只允许从相机扫码
  28. success(res) {
  29. console.log("扫码成功:" + JSON.stringify(res))
  30. that.setData({
  31. ['values.deviceSn']: res.result
  32. })
  33. }
  34. })
  35. },
  36. formSubmit: function (e) {
  37. var that = this
  38. //表单规则
  39. let rules = [{
  40. name: "storeName",
  41. rule: ["required"], //可使用区间,此处主要测试功能
  42. msg: ["请输入门店名称"]
  43. }, {
  44. name: "deviceSn",
  45. rule: ["required"], //可使用区间,此处主要测试功能
  46. msg: ["请输入设备码"]
  47. }, {
  48. name: "deviceLocation",
  49. rule: ["required"],
  50. msg: ["请输入客房房间号"]
  51. }];
  52. //进行表单检查
  53. let formData = e.detail.value;
  54. let checkRes = form.validation(formData, rules);
  55. console.log(that.data.values)
  56. if (!checkRes) {
  57. util.request(util.api.addDevice, that.data.values, "POST", false, true,app.globalData.token).then((res) => {
  58. if (res.code == 200) {
  59. wx.redirectTo({
  60. url: '/pages/device/index',
  61. })
  62. }else{
  63. util.toast(res.message)
  64. }
  65. }).catch((res) => {})
  66. } else {
  67. wx.showToast({
  68. title: checkRes,
  69. icon: "none"
  70. });
  71. }
  72. },
  73. formReset: function (e) {
  74. console.log("清空数据")
  75. },
  76. bindStorePickerChange: function (e) {
  77. console.log("=====================")
  78. console.log(e)
  79. var item = this.data.storeList[e.detail.value]
  80. console.log(item)
  81. this.setData({
  82. ['values.storeId']: item.id,
  83. ['values.storeName']: item.storeName
  84. })
  85. },
  86. bindStoreList() {
  87. var that = this
  88. util.request(util.api.storeList, {}, "GET", false, true,app.globalData.token).then((res) => {
  89. if (res.code == 200) {
  90. that.setData({
  91. storeList: res.result
  92. })
  93. }
  94. }).catch((res) => {})
  95. },
  96. inputedit: function (e) {
  97. let _this = this;
  98. let dataset = e.currentTarget.dataset;
  99. let value = e.detail.value;
  100. let name = dataset.name;
  101. _this.data[name] = value;
  102. _this.setData({
  103. [name]: _this.data[name]
  104. });
  105. },
  106. })