业务交流通
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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