业务交流通
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. if (typeof listDetail.type == 'string') {
  117. listDetail.type = listDetail.type.split(',');
  118. listDetail.createdOn = $util.formatTime(new Date(listDetail.createdOn), true);
  119. }
  120. that.clearData();
  121. wx.setStorageSync('listDetail', listDetail)
  122. wx.reLaunch({
  123. url: '/pages/index/components/listDetails/Details',
  124. })
  125. }
  126. }
  127. })
  128. } else {
  129. wx.showLoading({
  130. title: '修改成功',
  131. mask: true
  132. })
  133. setTimeout(() => {
  134. wx.hideLoading()
  135. let pages = getCurrentPages();
  136. let Page = pages[pages.length - 1];//当前页
  137. let prevPage = pages[pages.length - 2]; //上一个页面
  138. let info = prevPage.data //取上页data里的数据也可以修改
  139. let tempListData = info.listData;
  140. tempListData.forEach(el => {
  141. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  142. el.info = Page.data.detailValue
  143. }
  144. })
  145. prevPage.setData({ listData: tempListData })//设置数据
  146. wx.navigateBack()
  147. }, 1000);
  148. }
  149. } else if (res.status == 501) {
  150. wx.showModal({
  151. title: '发布失败',
  152. content: res.msg,
  153. showCancel: false,
  154. })
  155. }
  156. }).catch(err => {
  157. console.log(err);
  158. this.setData({
  159. saveLoading: false
  160. })
  161. })
  162. },
  163. clearData() {
  164. let tags = this.data.tags;
  165. tags.forEach(el => {
  166. el.isActive = '';
  167. })
  168. this.setData({
  169. selectedTag: [],
  170. detailValue: "",
  171. tags
  172. })
  173. },
  174. trimRight(s) {
  175. if (s == null) return "";
  176. var whitespace = new String(" \t\n\r");
  177. var str = new String(s);
  178. if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
  179. var i = str.length - 1;
  180. while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
  181. i--;
  182. }
  183. str = str.substring(0, i + 1);
  184. }
  185. return str;
  186. },
  187. // 获取tag
  188. getTags() {
  189. this.setData({
  190. pageLoading: true,
  191. })
  192. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  193. this.setData({
  194. pageLoading: false,
  195. })
  196. if (res.status == 0) {
  197. let datas = res.data;
  198. let selectedTag = this.data.selectedTag;
  199. datas.forEach(el => {
  200. el.isActive = "";
  201. if (selectedTag.indexOf(el.typeName) != -1) {
  202. el.isActive = 'active' + selectedTag.indexOf(el.typeName);
  203. }
  204. })
  205. this.setData({
  206. tags: datas,
  207. })
  208. }
  209. console.log(this.data.tags, 'tags')
  210. }).catch(error => {
  211. console.log(error, 'error appletLogin')
  212. })
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage: function () {
  218. }
  219. })