业务交流通
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 = false
  61. if (selectedTag.indexOf(el.typeName) != -1) {
  62. el.isActive = true;
  63. }
  64. })
  65. this.setData({
  66. selectedTag,
  67. tags
  68. })
  69. // console.log(this.data.selectedTag,'selectedTag');
  70. // console.log(this.data.tags,'tags');
  71. },
  72. // 发布需求
  73. releaseDemands() {
  74. this.setData({
  75. saveLoading:true
  76. })
  77. let { selectedTag, detailValue } = this.data;
  78. let param = {
  79. customerId: 666967,
  80. info: this.trimRight(detailValue),
  81. type: selectedTag.join(','),
  82. businessCommunicationDemandId: null,
  83. };
  84. $request.post('/businessCommunicationDemand/saveDemand.action', param).then(res => {
  85. this.setData({
  86. saveLoading:false
  87. })
  88. let that = this;
  89. if (res.status == 0) {
  90. wx.showModal({
  91. title: '发布成功',
  92. content: "请关注平台公众号,如有咨询,可及时接收消息通知!",
  93. confirmText: "去关注",
  94. cancelText:"关闭",
  95. success (res1) {
  96. if (res1.confirm) {
  97. that.clearData();
  98. console.log('用户点击确定')
  99. } else if (res1.cancel) {
  100. let listDetail = res.data;
  101. if (typeof listDetail.type == 'string') {
  102. listDetail.type = listDetail.type.split(',');
  103. }
  104. that.clearData();
  105. wx.navigateTo({
  106. url: '/pages/index/components/listDetails/Details',
  107. success: function (res2) {
  108. // 通过eventChannel向被打开页面传送数据
  109. res2.eventChannel.emit('acceptDataFromOpenerPage', { listDetail })
  110. }
  111. })
  112. }
  113. }
  114. })
  115. } else if (res.status == 501) {
  116. wx.showModal({
  117. title: '发布失败',
  118. content: res.msg,
  119. showCancel: false,
  120. })
  121. }
  122. }).catch(err => {
  123. console.log(err);
  124. this.setData({
  125. saveLoading:false
  126. })
  127. })
  128. },
  129. clearData(){
  130. this.setData({
  131. selectedTag:[],
  132. detailValue:"",
  133. })
  134. },
  135. trimRight(s) {
  136. if (s == null) return "";
  137. var whitespace = new String(" \t\n\r");
  138. var str = new String(s);
  139. if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
  140. var i = str.length - 1;
  141. while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
  142. i--;
  143. }
  144. str = str.substring(0, i + 1);
  145. }
  146. return str;
  147. },
  148. // 获取tag
  149. getTags() {
  150. this.setData({
  151. pageLoading: true,
  152. })
  153. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  154. this.setData({
  155. pageLoading: false,
  156. })
  157. if (res.status == 0) {
  158. let datas = res.data;
  159. datas.forEach(el => {
  160. el.isActive = false;
  161. })
  162. this.setData({
  163. tags: datas,
  164. })
  165. }
  166. console.log(this.data.tags, 'tags')
  167. }).catch(error => {
  168. console.log(error, 'error appletLogin')
  169. })
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function () {
  175. }
  176. })