add.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const utils = require('../../utils/util')
  2. const form = require('../../utils/formValidation')
  3. const util = require('../../utils/util.js');
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. values:{
  11. repairsBy:'',
  12. repairsPhone:'',
  13. expressCompany:'',
  14. expressSn:'',
  15. area:'',
  16. address:'',
  17. deviceId:'',
  18. deviceSn:'',
  19. repairsRemark:''
  20. },
  21. region: [],
  22. expressCompany:[{
  23. text:"韵达快递",
  24. value:"韵达快递"
  25. },{
  26. text:"天天快递",
  27. value:"天天快递"
  28. },{
  29. text:"申通快递",
  30. value:"申通快递"
  31. },{
  32. text:"圆通速递",
  33. value:"圆通速递"
  34. },{
  35. text:"德邦物流",
  36. value:"德邦物流"
  37. },{
  38. text:"百世汇通",
  39. value:"百世汇通"
  40. },{
  41. text:"顺丰速运",
  42. value:"顺丰速运"
  43. },{
  44. text:"京东物流",
  45. value:"京东物流"
  46. },{
  47. text:"中通速递",
  48. value:"中通速递"
  49. },{
  50. text:"国通快递",
  51. value:"国通快递"
  52. },{
  53. text:"极兔快递",
  54. value:"极兔快递"
  55. }],
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. },
  62. bindPickerChange: function (e) {
  63. console.log(e)
  64. var item = this.data.expressCompany[e.detail.value]
  65. console.log(item)
  66. this.setData({
  67. ['values.expressCompany']: item.value,
  68. })
  69. },
  70. scanCodeEvent() {
  71. var that = this;
  72. wx.scanCode({
  73. onlyFromCamera: true, // 只允许从相机扫码
  74. success(res) {
  75. console.log("扫码成功:" + JSON.stringify(res))
  76. that.setData({
  77. ['values.deviceSn']: res.result
  78. })
  79. }
  80. })
  81. },
  82. formSubmit: function(e) {
  83. //表单规则
  84. let rules = [{
  85. name: "repairsBy",
  86. rule: ["required", "isChinese"],
  87. msg: ["请选择负责人姓名", "姓名必须全部为中文"]
  88. }, {
  89. name: "repairsPhone",
  90. rule: ["required", "isMobile"],
  91. msg: ["请输入手机号", "请输入正确的手机号"]
  92. }];
  93. //进行表单检查
  94. let formData = e.detail.value;
  95. let checkRes = form.validation(formData, rules);
  96. console.log(this.data.values)
  97. if (!checkRes) {
  98. // wx.showToast({
  99. // title: "验证通过!",
  100. // icon: "none"
  101. // });
  102. var that = this
  103. util.request(util.api.addRepairs, that.data.values, "POST", false, true,app.globalData.token).then((res)=>{
  104. console.log(that.data.values)
  105. if (res.code == 200) {
  106. wx.navigateTo({
  107. url: '/pages/repairs/index',
  108. })
  109. }
  110. }).catch((res) => {})
  111. } else {
  112. wx.showToast({
  113. title: checkRes,
  114. icon: "none"
  115. });
  116. }
  117. },
  118. formReset: function(e) {
  119. console.log("清空数据")
  120. },
  121. bindRegionChange: function (e) {
  122. console.log(e.detail.value)
  123. console.log(e.detail.code)
  124. this.setData({
  125. region: e.detail.value
  126. })
  127. this.data.values.area = this.data.region.join(" ")
  128. },
  129. inputedit: function (e) {
  130. let _this = this;
  131. let dataset = e.currentTarget.dataset;
  132. let value = e.detail.value;
  133. let name = dataset.name;
  134. _this.data[name] = value;
  135. _this.setData({
  136. [name]: _this.data[name]
  137. });
  138. },
  139. })