pub.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var chooseFlag = true;
  4. var myDate = new Date();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. begin_time: '',
  11. end_time: '',
  12. noteMaxLen: 500,
  13. imgGroup: [],
  14. goods: [], // 选择商品
  15. type: 0, // 0社区商品 1仅快递
  16. title: '',
  17. content: ''
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.getData();
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function () {
  29. },
  30. titleInput: function(e){
  31. var title = e.detail.value;
  32. this.setData({ title })
  33. },
  34. /**
  35. * 开始时间
  36. */
  37. beginTimePicker: function(e){
  38. this.setData({ begin_time: e.detail })
  39. },
  40. /**
  41. * 开始时间
  42. */
  43. endTimePicker: function (e) {
  44. this.setData({ end_time: e.detail })
  45. },
  46. contentInput: function(e){
  47. var value = e.detail.value, len = parseInt(value.length);
  48. if (len > this.data.noteMaxLen) return;
  49. this.setData({
  50. currentNoteLen: len, //当前字数
  51. limitNoteLen: this.data.noteMaxLen - len, //剩余字数
  52. content: value
  53. });
  54. },
  55. chooseImage: function () {
  56. chooseFlag = false;
  57. },
  58. changeImg: function (e) {
  59. chooseFlag = e.detail.len === e.detail.value.length;
  60. this.setData({
  61. imgGroup: e.detail.value
  62. });
  63. },
  64. deleteGoods: function(e){
  65. let idx = e.detail;
  66. console.log(idx);
  67. let goods = this.data.goods;
  68. if(idx!=-1) {
  69. goods.splice(idx, 1);
  70. this.setData({ goods })
  71. }
  72. },
  73. /**
  74. * 获取团长信息
  75. */
  76. getData: function () {
  77. const token = wx.getStorageSync('token');
  78. let that = this;
  79. app.util.request({
  80. url: 'entry/wxapp/index',
  81. data: {
  82. controller: 'solitaire.get_solitaire_headinfo',
  83. token: token
  84. },
  85. dataType: 'json',
  86. success: function (res) {
  87. if (res.data.code == 0) {
  88. that.setData({ community: res.data.data || '' })
  89. } else if (res.data.code == 1) {
  90. app.util.message('您还未登录', 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  91. return;
  92. } else {
  93. app.util.message(res.data.msg, 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  94. return;
  95. }
  96. }
  97. })
  98. },
  99. /**
  100. * 提交
  101. */
  102. subForm: function(){
  103. let { title, content, begin_time, end_time, imgGroup, goods } = this.data;
  104. let that = this;
  105. if(title=='') {
  106. wx.showToast({
  107. title: '请输入标题',
  108. icon: 'none'
  109. })
  110. return;
  111. }
  112. if (content == '') {
  113. wx.showToast({
  114. title: '请输入内容',
  115. icon: 'none'
  116. })
  117. return;
  118. }
  119. if (imgGroup.length <= 0) {
  120. wx.showToast({
  121. title: '请上传接龙图片',
  122. icon: 'none'
  123. })
  124. return;
  125. }
  126. if (goods.length <= 0) {
  127. wx.showToast({
  128. title: '请选择商品',
  129. icon: 'none'
  130. })
  131. return;
  132. }
  133. let ids = [];
  134. goods.forEach(item=>{
  135. ids.push(item.gid);
  136. })
  137. let goods_list = ids.join(',');
  138. const token = wx.getStorageSync('token');
  139. let data = { title, content, begin_time, end_time, images_list: imgGroup.join(','), goods_list, token };
  140. app.util.request({
  141. url: 'entry/wxapp/index',
  142. data: {
  143. controller: 'solitaire.sub_head_solitaire',
  144. ...data
  145. },
  146. dataType: 'json',
  147. success: function (res) {
  148. if (res.data.code == 0) {
  149. app.util.message('提交成功', 'redirect:/lionfish_comshop/moduleA/solitaire/groupIndex', 'success');
  150. } else {
  151. app.util.message(res.data.msg || '提交失败', '', 'error');
  152. return;
  153. }
  154. }
  155. })
  156. }
  157. })