业务交流通
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 7.6KB

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