custom.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. properties: {},
  4. data: {
  5. item: null,
  6. show: false
  7. },
  8. methods: {
  9. onClick(item) {
  10. if (this.data.product != null && item.itemid == this.data.product.itemid) return this.setData({
  11. show: true
  12. })
  13. wx.showLoading({
  14. title: '获取定制方案中..',
  15. })
  16. let arr = [];
  17. Promise.all([{
  18. "id": "20230707091603",
  19. "version": 1,
  20. "content": {
  21. "sa_sizecustomizedschemeid": item.lengthschemeid
  22. }
  23. }, {
  24. "id": "20230707091603",
  25. "version": 1,
  26. "content": {
  27. "sa_sizecustomizedschemeid": item.widthschemeid
  28. }
  29. }].map(v => _Http.basic(v))).then(s => {
  30. console.log("获取定制方案", s)
  31. wx.hideLoading();
  32. if (s.some(c => c.msg != '成功')) return wx.showToast({
  33. title: '定制方案获取失败',
  34. icon: "none"
  35. })
  36. if (item.lengthschemeid) {
  37. let data = s[0].data;
  38. if (!item.length || item.length == 0) item.length = data.type == '可选' ? data.rowsdetail[0].num : data.min - 0;
  39. arr.push(data)
  40. }
  41. if (item.widthschemeid) {
  42. let data = s[1].data;
  43. if (!item.width || item.width == 0) item.width = data.type == '可选' ? data.rowsdetail[0].num : data.min - 0;
  44. arr.push(data)
  45. }
  46. this.setData({
  47. show: true,
  48. arr,
  49. product: item
  50. });
  51. console.log("arr", arr, item)
  52. });
  53. this.selectComponent("#Dialog").data.beforeClose = (action) => new Promise((resolve) => {
  54. if (action === 'confirm') {
  55. getApp().globalData.customizedProduct(this.data.product).then(res => {
  56. resolve(true);
  57. })
  58. } else {
  59. resolve(false);
  60. this.setData({
  61. show: false
  62. })
  63. }
  64. });
  65. },
  66. selected(e) {
  67. const {
  68. name,
  69. num
  70. } = e.currentTarget.dataset;
  71. this.data.product[name] = num;
  72. this.setData({
  73. product: this.data.product
  74. })
  75. },
  76. /* 定制步进器 */
  77. cahngeStepper(e) {
  78. const {
  79. name,
  80. item
  81. } = e.currentTarget.dataset,
  82. product = this.data.product;
  83. if (e.type == 'plus') {
  84. product[name] += 1
  85. } else if (e.type == 'minus') {
  86. product[name] -= 1
  87. } else {
  88. product[name] = (e.detail.value - 0).toFixed(product.decimalplaces);
  89. }
  90. if (product[name] > item.max) product[name] = item.max;
  91. if (product[name] < item.min) product[name] = item.min;
  92. this.setData({
  93. product
  94. })
  95. },
  96. }
  97. })