stockDeviceDetail.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. deviceId:'',
  9. deviceInfo:{
  10. deviceDetail:{
  11. // gridNum:'',
  12. // productGrid:'',
  13. mgVmDevice:{},
  14. stockGrid:''
  15. },
  16. gridList:[]
  17. },
  18. productId:'',
  19. isStock:''
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.setData({
  26. deviceId: options.deviceId
  27. })
  28. this.bindDevice()
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload: function () {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh: function () {
  54. },
  55. /**
  56. * 页面上拉触底事件的处理函数
  57. */
  58. onReachBottom: function () {
  59. },
  60. /**
  61. * 用户点击右上角分享
  62. */
  63. onShareAppMessage: function () {
  64. },
  65. bindDevice(){
  66. var that = this
  67. util.request(util.api.queryByDeviceId, {id:that.data.deviceId}, "GET", true, true,app.globalData.token).then((res)=>{
  68. if (res.code == 200) {
  69. console.log(res)
  70. that.setData({
  71. deviceInfo: res.result,
  72. })
  73. }
  74. }).catch((res) => {})
  75. },
  76. updateIsStock(e){
  77. var that = this
  78. that.data.productId = e.currentTarget.dataset.id
  79. that.data.isStock = e.currentTarget.dataset.as
  80. util.request(util.api.editMgVmDeviceGridProductQc, {deviceId:that.data.deviceId, gridId:e.currentTarget.dataset.id,isStock:that.data.isStock}, "POST", true, true,app.globalData.token).then((res)=>{
  81. if (res.code == 200) {
  82. that.bindDevice()
  83. }
  84. }).catch((res) => {})
  85. },
  86. number: function (e) {
  87. let value = this.validateNumber(e.detail.value)
  88. let inx = `deviceInfo.gridList[${e.target.dataset.index}].repairNum`
  89. this.setData({
  90. //parseInt将数字字符串转换成数字
  91. [inx]: parseInt(value)
  92. })
  93. },
  94. validateNumber(val) {
  95. //正则表达式指定字符串只能为数字
  96. return val.replace(/\D/g, '')
  97. },
  98. updateSkuStock(e){
  99. var repairnum = e.currentTarget.dataset.repairnum?e.currentTarget.dataset.repairnum:0
  100. let data = this.data.deviceInfo.gridList[e.target.dataset.index];
  101. var stockCount = data.stockCount?data.stockCount:0
  102. var gridCount = data.gridCount?data.gridCount:0
  103. if((stockCount+repairnum)>gridCount){
  104. util.toast('超过格子可存放数量')
  105. return;
  106. }
  107. var that = this;
  108. util.request(util.api.replenishment, {gridId:e.currentTarget.dataset.id,goodsNumber:repairnum,deviceId:that.data.deviceId}, "POST", true, true,app.globalData.token).then((res)=>{
  109. if (res.code == 200) {
  110. that.bindDevice()
  111. }
  112. }).catch((res) => {})
  113. }
  114. })