业务交流通
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. listDetail.createdOn = listDetail.createdOn.replaceAll('/', '-');
  120. }
  121. that.clearData();
  122. wx.setStorageSync('listDetail', listDetail)
  123. wx.reLaunch({
  124. url: '/pages/index/components/listDetails/Details',
  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. })