commodityDetail.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var app = getApp();
  2. var that;
  3. Page({
  4. data: {
  5. val: 1,
  6. detail:{},
  7. num:'',
  8. remark:'',
  9. disabled: false,
  10. gxd:'',
  11. },
  12. onLoad(e) {
  13. that = this;
  14. dd.setNavigationBar({ title: "奖品详情" });
  15. if(e.item){
  16. let item=JSON.parse(e.item);
  17. that.setData({gxd:item.gxd })
  18. that.getData(item.id);
  19. }
  20. },
  21. showImg(e) {
  22. var url = e.target.dataset.url
  23. dd.previewImage({
  24. current: 0,
  25. urls:[url]
  26. });
  27. },
  28. getData(id) {
  29. app.$get('api/shop/goods/detail', { id:id}).then((res) => {
  30. this.setData({
  31. detail:res.data.data,
  32. })
  33. })
  34. },
  35. active(e) {
  36. var id = e.target.dataset.id;
  37. let val = this.data.val;
  38. if (id == 1) {
  39. if (val != 1) {
  40. val--;
  41. }
  42. } else {
  43. val++
  44. }
  45. this.setData({
  46. val: val
  47. })
  48. },
  49. //备注输入
  50. bindTextAreaBlur: function (e) {
  51. this.setData({
  52. remark: e.detail.value,
  53. });
  54. },
  55. openText(){
  56. if(this.data.disabled){
  57. return false
  58. };
  59. if(this.data.detail.gxd<this.data.num){
  60. app.globalData.showToast("功勋点不足");
  61. return false
  62. }
  63. let data={
  64. goods_id:this.data.detail.id,
  65. num:this.data.val,
  66. remark:this.data.remark,
  67. }
  68. this.setData({ disabled: true });
  69. app.$post("api/shop/exchange/create", data).then((res) => {
  70. app.globalData.showToast("已兑换");
  71. setTimeout(() => {
  72. this.setData({ disabled: false });
  73. dd.navigateBack({ delta: 1 })
  74. }, 1000);
  75. }).catch(err => {
  76. this.setData({ disabled: false });
  77. })
  78. },
  79. showText() {
  80. this.setData({
  81. isBh: !this.data.isBh,
  82. num: this.data.val*this.data.detail.price,
  83. })
  84. },
  85. handleCopy() {
  86. dd.setClipboard({
  87. text: this.data.text,
  88. })
  89. app.globalData.showToast("已复制");
  90. }
  91. });