业务交流通
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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