业务交流通
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 7.2KB

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