toolkitConfirm.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var util = require('../../../utils/util.js');
  2. var mall = require('../../../api/mall.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. index:'',
  7. columns:[],
  8. skus:[],
  9. showPicker:false,
  10. id:'',
  11. toolkitType:'',//1上线礼包 2晋升礼包
  12. detailList:[
  13. ]
  14. },
  15. onLoad: function(options) {
  16. // 页面初始化 options为页面跳转所带来的参数
  17. if(options){
  18. this.setData({
  19. id:options.id
  20. })
  21. }
  22. this.getOrderInfo();
  23. },
  24. getOrderInfo() {
  25. util.request(mall.ToolkitToComplete, {
  26. toolId: 'autoTool_'+this.data.id,
  27. }).then(res=>{
  28. if (res.errno === 0) {
  29. console.log(res.data);
  30. let list=res.data.detailList;
  31. list.forEach(item=>{
  32. // if(item.needConfirm==0){
  33. // }else if(item.needConfirm==1){
  34. // }
  35. let pickerProps=item.canChoiceProps.split('|');
  36. let pickerPrices=item.canChoicePrice.split('|');
  37. let pickerSkus=item.canChoiceSkus.split(',');
  38. item.pickerProps=pickerProps;
  39. item.pickerSkus=pickerSkus;
  40. item.pickerPrices=pickerPrices;
  41. item.finalChoice='';
  42. item.finalChoiceName='待确认';
  43. item.pickerPrice='';
  44. // item.finalChoice=pickerSkus[0];
  45. // item.finalChoiceName=pickerProps[0];
  46. });
  47. this.setData({
  48. detailList:list,
  49. toolkitType:res.data.toolkitType,
  50. });
  51. }
  52. });
  53. },
  54. showSpec(e){
  55. let index=e.currentTarget.dataset.index;
  56. let columns=e.currentTarget.dataset.columns;
  57. let skus=e.currentTarget.dataset.skus;
  58. this.setData({
  59. showPicker:true,
  60. index:index,
  61. columns:columns,
  62. skus:skus
  63. });
  64. },
  65. pickerCancel(){
  66. this.setData({
  67. showPicker:false
  68. });
  69. },
  70. pickerConfirm(e){
  71. let value=e.detail.value;
  72. let index=e.detail.index;
  73. let item1='detailList['+this.data.index+']'+'.finalChoiceName';
  74. let item2='detailList['+this.data.index+']'+'.finalChoice';
  75. let item3='detailList['+this.data.index+']'+'.pickerPrice';
  76. this.setData({
  77. [item1]:value,
  78. });
  79. this.setData({
  80. [item2]:this.data.detailList[this.data.index].pickerSkus[index],
  81. [item3]:this.data.detailList[this.data.index].pickerPrices[index],
  82. showPicker:false
  83. });
  84. },
  85. confirmSpec(){
  86. let isUnSelected=this.data.detailList.some(item=>{
  87. return item.finalChoice=='';
  88. });
  89. if(isUnSelected){
  90. wx.showToast({
  91. title: '请选择商品规格',
  92. icon:'none',
  93. });
  94. }else{
  95. util.request(mall.ToolkitReceive, {
  96. agree:true,
  97. detail:this.data.detailList,
  98. allDefault:false,
  99. toolkitId: this.data.id,
  100. },'POST').then(res=>{
  101. if (res.errno === 0) {
  102. app.globalData.specRefresh=true;
  103. wx.navigateBack({
  104. delta: 1,
  105. });
  106. }else{
  107. util.showErrorToast(res.errmsg);
  108. }
  109. });
  110. }
  111. },
  112. onReady: function() {
  113. // 页面渲染完成
  114. },
  115. onShow: function() {
  116. // 页面显示
  117. },
  118. onHide: function() {
  119. // 页面隐藏
  120. },
  121. onUnload: function() {
  122. // 页面关闭
  123. }
  124. })