业务交流通
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.js 8.8KB

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