业务交流通
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.js 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // pages/index/components/listDetails/Details.js
  2. const app = getApp()
  3. const $request = require('../../utils/request.js');
  4. const $util = require('../../utils/util.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. currentIndex: 1,
  11. pageLoading: true,
  12. tags: [],
  13. min: 0,
  14. max: 300,
  15. // 用户有无点击过tag
  16. isClickTag: false,
  17. // 选中tag
  18. selectedTag: [],
  19. detailValue: "",
  20. saveLoading: false,
  21. businessCommunicationDemandId: null,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad() {
  27. if (!app.globalData.customerId) {
  28. app.goLogin();
  29. return
  30. }
  31. const eventChannel = this.getOpenerEventChannel()
  32. if (eventChannel.on) {
  33. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  34. eventChannel.on('acceptDataFromOpenerPage', data => {
  35. let listDetail = data.listDetail;
  36. this.setData({
  37. detailValue: listDetail.info,
  38. selectedTag: listDetail.type,
  39. businessCommunicationDemandId: listDetail.businessCommunicationDemandId
  40. })
  41. })
  42. }
  43. this.getTags();
  44. },
  45. // 输入框输入
  46. textareaInput(e) {
  47. let value = e.detail.value;
  48. let len = e.detail.cursor;;
  49. this.setData({
  50. min: len
  51. });
  52. this.setData({
  53. detailValue: value
  54. })
  55. },
  56. // tag选择切换
  57. tagSelectedChange(e) {
  58. let typename = e.currentTarget.dataset.typename;
  59. let selectedTag = this.data.selectedTag;
  60. let tempArr = [];
  61. // 1 如果选中的数组里没有当前type
  62. if (selectedTag.indexOf(typename) == -1) {
  63. // 2 如果选中的数组的长度小于3 直接push
  64. if (selectedTag.length < 3) {
  65. selectedTag.push(typename)
  66. }
  67. }
  68. // 3 如果选中的数组里有它,直接删除
  69. else {
  70. selectedTag.forEach((el, inx) => {
  71. if (el == typename) {
  72. selectedTag.splice(inx, 1);
  73. }
  74. })
  75. }
  76. let tags = this.data.tags;
  77. tags.forEach(el => {
  78. el.isActive = '';
  79. if (selectedTag.indexOf(el.typeName) != -1) {
  80. el.isActive = 'active' + selectedTag.indexOf(el.typeName);
  81. }
  82. })
  83. this.setData({
  84. selectedTag,
  85. tags
  86. })
  87. // console.log(this.data.selectedTag,'selectedTag');
  88. // console.log(this.data.tags,'tags');
  89. },
  90. // 发布需求
  91. releaseDemands() {
  92. this.setData({
  93. saveLoading: true
  94. })
  95. let { selectedTag, detailValue, businessCommunicationDemandId } = this.data;
  96. let param = {
  97. customerId: app.globalData.customerId,
  98. info: this.trimRight(detailValue),
  99. type: selectedTag.join(','),
  100. businessCommunicationDemandId,
  101. };
  102. $request.post('/businessCommunicationDemand/saveDemand.action', param).then(res => {
  103. this.setData({
  104. saveLoading: false
  105. })
  106. let that = this;
  107. if (res.status == 0) {
  108. if (!businessCommunicationDemandId) {
  109. wx.showModal({
  110. title: '发布成功',
  111. content: "请关注平台公众号,如有咨询,可及时接收消息通知!",
  112. confirmText: "去关注",
  113. cancelText: "关闭",
  114. success(res1) {
  115. if (res1.confirm) {
  116. that.clearData();
  117. wx.navigateTo({
  118. url: "/pages/outLink/outLink?followApplets=true", //跳转页面的路径,可带参数 ?隔开,不同参数用 & 分隔;相对路径,不需要.wxml后缀
  119. success: function () { }, //成功后的回调;
  120. fail: function () { }, //失败后的回调;
  121. complete: function () { } //结束后的回调(成功,失败都会执行)
  122. })
  123. } else if (res1.cancel) {
  124. let listDetail = res.data;
  125. that.clearData();
  126. wx.reLaunch({
  127. url: '/pages/index/components/listDetails/Details?businessCommunicationDemandId=' + listDetail.businessCommunicationDemandId,
  128. })
  129. }
  130. }
  131. })
  132. } else {
  133. wx.showLoading({
  134. title: '修改成功',
  135. mask: true
  136. })
  137. setTimeout(() => {
  138. wx.hideLoading()
  139. let pages = getCurrentPages();
  140. let Page = pages[pages.length - 1];//当前页
  141. let prevPage = pages[pages.length - 2]; //上一个页面
  142. let info = prevPage.data //取上页data里的数据也可以修改
  143. let tempListData = info.listData;
  144. tempListData.forEach(el => {
  145. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  146. el.info = Page.data.detailValue
  147. }
  148. })
  149. prevPage.setData({ listData: tempListData })//设置数据
  150. wx.navigateBack()
  151. }, 1000);
  152. }
  153. } else if (res.status == 501) {
  154. wx.showModal({
  155. title: '发布失败',
  156. content: res.msg,
  157. showCancel: false,
  158. })
  159. }
  160. }).catch(err => {
  161. console.log(err);
  162. this.setData({
  163. saveLoading: false
  164. })
  165. })
  166. },
  167. clearData() {
  168. let tags = this.data.tags;
  169. tags.forEach(el => {
  170. el.isActive = '';
  171. })
  172. this.setData({
  173. selectedTag: [],
  174. detailValue: "",
  175. tags
  176. })
  177. },
  178. trimRight(s) {
  179. if (s == null) return "";
  180. var whitespace = new String(" \t\n\r");
  181. var str = new String(s);
  182. if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
  183. var i = str.length - 1;
  184. while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
  185. i--;
  186. }
  187. str = str.substring(0, i + 1);
  188. }
  189. return str;
  190. },
  191. // 获取tag
  192. getTags() {
  193. this.setData({
  194. pageLoading: true,
  195. })
  196. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  197. this.setData({
  198. pageLoading: false,
  199. })
  200. if (res.status == 0) {
  201. let datas = res.data;
  202. let selectedTag = this.data.selectedTag;
  203. datas.forEach(el => {
  204. el.isActive = "";
  205. if (selectedTag.indexOf(el.typeName) != -1) {
  206. el.isActive = 'active' + selectedTag.indexOf(el.typeName);
  207. }
  208. })
  209. this.setData({
  210. tags: datas,
  211. })
  212. }
  213. console.log(this.data.tags, 'tags')
  214. }).catch(error => {
  215. console.log(error, 'error appletLogin')
  216. })
  217. },
  218. /**
  219. * 用户点击右上角分享
  220. */
  221. onShareAppMessage: function () {
  222. }
  223. })