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

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