custom.js 2.9 KB

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