index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const util = require('../../utils/util')
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. hotelList: [],
  9. searchParams: {
  10. hotelId: '',
  11. hotelName: '',
  12. },
  13. stockList: []
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.bindHotelList()
  20. this.bindProductStockList()
  21. },
  22. bindHotelPickerChange: function (e) {
  23. var item = this.data.hotelList[e.detail.value]
  24. console.log(item)
  25. this.setData({
  26. ['searchParams.hotelName']: item.hotelName,
  27. ['searchParams.hotelId']: item.id
  28. })
  29. this.bindProductStockList()
  30. },
  31. bindHotelList() {
  32. var that = this
  33. util.request(util.api.hotelList, {}, "GET", false, true, app.globalData.token).then((res) => {
  34. if (res.code == 200) {
  35. that.setData({
  36. hotelList: res.result
  37. })
  38. }
  39. }).catch((res) => {})
  40. },
  41. formSubmit: function (e) {
  42. var that = this
  43. util.request(util.api.editVmProductStock, that.data.stockList, "POST", false, true, app.globalData.token).then((res) => {
  44. if (res.code == 200) {
  45. util.toast('保存成功')
  46. setTimeout(() => {
  47. wx.navigateBack()
  48. }, 500)
  49. }
  50. }).catch((res) => {})
  51. },
  52. formReset: function (e) {
  53. console.log("清空数据")
  54. },
  55. inputedit: function (e) {
  56. let _this = this;
  57. let dataset = e.currentTarget.dataset;
  58. let value = e.detail.value;
  59. let name = dataset.name;
  60. _this.data[name] = value;
  61. _this.setData({
  62. [name]: _this.data[name]
  63. });
  64. },
  65. inputeditRow: function (e) {
  66. let that = this;
  67. let dataset = e.currentTarget.dataset;
  68. let value = e.detail.value;
  69. let name = dataset.name;
  70. var list = that.data.stockList
  71. var index = dataset.index;
  72. var itemProduct = dataset.item
  73. itemProduct.skuStock = value
  74. list.splice(index, 1, itemProduct)
  75. that.setData({
  76. stockList: list
  77. })
  78. },
  79. bindProductStockList() {
  80. var that = this
  81. util.request(util.api.productStockList, that.data.searchParams, "GET", true, true, app.globalData.token).then((res) => {
  82. if (res.code == 200) {
  83. that.setData({
  84. stockList: res.result
  85. })
  86. }
  87. }).catch((res) => {})
  88. }
  89. })