业务交流通
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/index/components/listDetails/Details.js
  2. const app = getApp()
  3. const $request = require('../../utils/request.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. currentIndex: 1,
  10. pageLoading: false,
  11. tags: [],
  12. min: 0,
  13. max: 300,
  14. // 用户有无点击过tag
  15. isClickTag: false,
  16. // 选中tag
  17. selectedTag: [],
  18. detailValue: "",
  19. saveLoading:false,
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad() {
  25. this.getTags();
  26. },
  27. // 输入框输入
  28. textareaInput(e) {
  29. let value = e.detail.value;
  30. let len = e.detail.cursor;;
  31. this.setData({
  32. min: len
  33. });
  34. this.setData({
  35. detailValue: value
  36. })
  37. },
  38. // tag选择切换
  39. tagSelectedChange(e) {
  40. let typename = e.currentTarget.dataset.typename;
  41. let selectedTag = this.data.selectedTag;
  42. let tempArr = [];
  43. // 1 如果选中的数组里没有当前type
  44. if (selectedTag.indexOf(typename) == -1) {
  45. // 2 如果选中的数组的长度小于3 直接push
  46. if (selectedTag.length < 3) {
  47. selectedTag.push(typename)
  48. }
  49. }
  50. // 3 如果选中的数组里有它,直接删除
  51. else {
  52. selectedTag.forEach((el, inx) => {
  53. if (el == typename) {
  54. selectedTag.splice(inx, 1);
  55. }
  56. })
  57. }
  58. let tags = this.data.tags;
  59. tags.forEach(el => {
  60. el.isActive = '';
  61. if (selectedTag.indexOf(el.typeName) != -1) {
  62. el.isActive = 'active' + selectedTag.indexOf(el.typeName);
  63. }
  64. })
  65. console.log(tags)
  66. this.setData({
  67. selectedTag,
  68. tags
  69. })
  70. // console.log(this.data.selectedTag,'selectedTag');
  71. // console.log(this.data.tags,'tags');
  72. },
  73. // 发布需求
  74. releaseDemands() {
  75. this.setData({
  76. saveLoading:true
  77. })
  78. let { selectedTag, detailValue } = this.data;
  79. let param = {
  80. customerId: 666967,
  81. info: this.trimRight(detailValue),
  82. type: selectedTag.join(','),
  83. businessCommunicationDemandId: null,
  84. };
  85. $request.post('/businessCommunicationDemand/saveDemand.action', param).then(res => {
  86. this.setData({
  87. saveLoading:false
  88. })
  89. let that = this;
  90. if (res.status == 0) {
  91. wx.showModal({
  92. title: '发布成功',
  93. content: "请关注平台公众号,如有咨询,可及时接收消息通知!",
  94. confirmText: "去关注",
  95. cancelText:"关闭",
  96. success (res1) {
  97. if (res1.confirm) {
  98. that.clearData();
  99. console.log('用户点击确定')
  100. } else if (res1.cancel) {
  101. let listDetail = res.data;
  102. if (typeof listDetail.type == 'string') {
  103. listDetail.type = listDetail.type.split(',');
  104. }
  105. that.clearData();
  106. wx.navigateTo({
  107. url: '/pages/index/components/listDetails/Details',
  108. success: function (res2) {
  109. // 通过eventChannel向被打开页面传送数据
  110. res2.eventChannel.emit('acceptDataFromOpenerPage', { listDetail })
  111. }
  112. })
  113. }
  114. }
  115. })
  116. } else if (res.status == 501) {
  117. wx.showModal({
  118. title: '发布失败',
  119. content: res.msg,
  120. showCancel: false,
  121. })
  122. }
  123. }).catch(err => {
  124. console.log(err);
  125. this.setData({
  126. saveLoading:false
  127. })
  128. })
  129. },
  130. clearData(){
  131. this.setData({
  132. selectedTag:[],
  133. detailValue:"",
  134. })
  135. },
  136. trimRight(s) {
  137. if (s == null) return "";
  138. var whitespace = new String(" \t\n\r");
  139. var str = new String(s);
  140. if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
  141. var i = str.length - 1;
  142. while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
  143. i--;
  144. }
  145. str = str.substring(0, i + 1);
  146. }
  147. return str;
  148. },
  149. // 获取tag
  150. getTags() {
  151. this.setData({
  152. pageLoading: true,
  153. })
  154. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  155. this.setData({
  156. pageLoading: false,
  157. })
  158. if (res.status == 0) {
  159. let datas = res.data;
  160. datas.forEach(el => {
  161. el.isActive = false;
  162. })
  163. this.setData({
  164. tags: datas,
  165. })
  166. }
  167. console.log(this.data.tags, 'tags')
  168. }).catch(error => {
  169. console.log(error, 'error appletLogin')
  170. })
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })