业务交流通
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

myRelease.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // pages/myModule/components/myRelease/myRelease.js
  2. const $request = require('../../../../utils/request.js');
  3. const $util = require('../../../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. tabs: [
  10. {
  11. tab: "发布中",
  12. code: 'release'
  13. },
  14. {
  15. tab: "已下架",
  16. code: 'remove'
  17. }
  18. ],
  19. currentTab: 'release',
  20. listLoading: false,
  21. customerId: null,
  22. // 我发布的需求----
  23. // item行加载
  24. itemLoading: false,
  25. listData: [],
  26. page: 1,
  27. size: 10,
  28. total: 0,
  29. // 是否加载数据,true加载,false不加载
  30. onRefresh: true,
  31. // 搜索值
  32. keyword: "",
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  38. const eventChannel = this.getOpenerEventChannel()
  39. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  40. eventChannel.on('customerid', data => {
  41. console.log(data)
  42. this.setData({
  43. customerId: data.customerid,
  44. listLoading: true,
  45. })
  46. this.getListData();
  47. })
  48. },
  49. // tab切换
  50. tabChange(e) {
  51. let code = e.currentTarget.dataset.code;
  52. this.setData({
  53. currentTab: code
  54. })
  55. this.toSearch();
  56. },
  57. // 搜索框输入同步值
  58. bindKeyInput: function (e) {
  59. this.setData({
  60. keyword: e.detail.value
  61. })
  62. },
  63. toSearch() {
  64. this.setData({
  65. listData: [],
  66. onRefresh: true,
  67. listLoading: true,
  68. page: 1,
  69. })
  70. this.getListData();
  71. },
  72. // 置顶/取消置顶需求
  73. productIsOnTop(e) {
  74. let item = e.currentTarget.dataset.item;
  75. let that = this;
  76. if (item.isOnTop) {
  77. wx.showModal({
  78. title: '提示',
  79. content: "是否确认取消置顶?",
  80. confirmText: "确认",
  81. cancelText: "取消",
  82. success(res) {
  83. if (res.confirm) {
  84. that.productIsOnTopPost(item);
  85. }
  86. }
  87. })
  88. } else {
  89. that.productIsOnTopPost(item);
  90. }
  91. },
  92. // 置顶/取消置顶需求Fn
  93. productIsOnTopPost(item) {
  94. let { businessCommunicationDemandId, isOnTop } = item;
  95. this.showLoading();
  96. $request.post(`/businessCommunicationDemand/setOnTopOrDown.action`,
  97. { businessCommunicationDemandId, isOnTop: isOnTop ? 0 : 1, customerId: "666967" }
  98. ).then(res => {
  99. wx.hideLoading()
  100. if (res.status == 0) {
  101. wx.showToast({
  102. title: isOnTop ? '取消置顶成功' : '置顶成功',
  103. icon: 'success',
  104. duration: 2000
  105. })
  106. let listData = this.data.listData;
  107. listData.forEach(el => {
  108. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  109. el.isOnTop = isOnTop ? false : true
  110. }
  111. })
  112. this.setData({
  113. listData
  114. })
  115. }else if(res.status == 106){
  116. wx.showToast({
  117. title: res.msg,
  118. icon: 'error',
  119. duration: 2000
  120. })
  121. }
  122. }).catch(error => {
  123. console.log(error, 'error appletLogin')
  124. wx.hideLoading()
  125. })
  126. },
  127. // 上架/下架需求
  128. productRelease(e) {
  129. let item = e.currentTarget.dataset.item;
  130. let that = this;
  131. if (item.state == 0) {
  132. wx.showModal({
  133. title: '提示',
  134. content: "是否确认下架?",
  135. confirmText: "确认",
  136. cancelText: "取消",
  137. success(res) {
  138. if (res.confirm) {
  139. that.productReleasePost(item);
  140. }
  141. }
  142. })
  143. } else {
  144. that.productReleasePost(item);
  145. }
  146. },
  147. // 上架/下架需求 Fn
  148. productReleasePost(item) {
  149. this.showLoading();
  150. let { businessCommunicationDemandId, state } = item;
  151. $request.post(`/businessCommunicationDemand/outDemand.action`,
  152. { businessCommunicationDemandId, state }
  153. ).then(res => {
  154. wx.hideLoading()
  155. if (res.status == 0) {
  156. wx.showToast({
  157. title: state == 0 ? '下架成功' : '上架成功',
  158. icon: 'success',
  159. duration: 2000
  160. })
  161. let listData = this.data.listData;
  162. listData.forEach((el, inx) => {
  163. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  164. listData.splice(inx, 1);
  165. }
  166. })
  167. this.setData({
  168. listData
  169. })
  170. }
  171. }).catch(error => {
  172. console.log(error, 'error appletLogin')
  173. wx.hideLoading()
  174. })
  175. },
  176. // 删除需求
  177. productDel(e) {
  178. let item = e.currentTarget.dataset.item;
  179. let that = this;
  180. wx.showModal({
  181. title: '提示',
  182. content: "是否确认删除?",
  183. confirmText: "确认",
  184. cancelText: "取消",
  185. success(res) {
  186. if (res.confirm) {
  187. that.productDelPost(item);
  188. }
  189. }
  190. })
  191. },
  192. // 删除需求 Fn
  193. productDelPost(item) {
  194. let { businessCommunicationDemandId } = item;
  195. this.showLoading();
  196. $request.post(`/businessCommunicationDemand/deleteDemand.action`,
  197. { businessCommunicationDemandId }
  198. ).then(res => {
  199. wx.hideLoading()
  200. if (res.status == 0) {
  201. wx.showToast({
  202. title: '删除成功',
  203. icon: 'success',
  204. duration: 2000
  205. })
  206. let listData = this.data.listData;
  207. listData.forEach((el, inx) => {
  208. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  209. listData.splice(inx, 1);
  210. }
  211. })
  212. this.setData({
  213. listData
  214. })
  215. }
  216. }).catch(error => {
  217. console.log(error, 'error appletLogin')
  218. wx.hideLoading()
  219. })
  220. },
  221. // 修改需求
  222. productEdit(e) {
  223. let item = e.currentTarget.dataset.item;
  224. let that = this;
  225. wx.navigateTo({
  226. url: '/pages/releaseModule/index',
  227. success: function (res) {
  228. // 通过eventChannel向被打开页面传送数据
  229. res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: item })
  230. }
  231. })
  232. },
  233. // 数据加载提示
  234. showLoading(title) {
  235. wx.showLoading({
  236. title: title ? title : '加载中',
  237. mask: true
  238. })
  239. },
  240. getListData() {
  241. let { page, size, customerId, keyword, currentTab } = this.data;
  242. $request.get('/businessCommunicationDemand/getDemandByStateAndCustomerId.action',
  243. { page, size, customerId, keyword, state: currentTab }
  244. ).then(res => {
  245. let tempListData = this.data.listData;
  246. if (res.status == 0) {
  247. let datas = res.data;
  248. console.log(datas, 'datas')
  249. // 先push数据
  250. tempListData.push(...datas.demandList);
  251. tempListData.forEach(el => {
  252. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  253. if (typeof el.type == 'string') {
  254. el.type = el.type.split(',');
  255. }
  256. })
  257. // 设置总数
  258. this.setData({
  259. listData: tempListData,
  260. total: datas.total,
  261. })
  262. // 如果数据大于了返回的总数
  263. if (tempListData.length >= this.data.total) {
  264. // 停止累加数据
  265. this.setData({
  266. onRefresh: false,
  267. itemLoading: false,
  268. })
  269. } else {
  270. this.setData({
  271. onRefresh: true,
  272. itemLoading: false,
  273. page: page + 1
  274. })
  275. }
  276. console.log('-------------个人主页 beg-------------------')
  277. console.log(this.data.listData);
  278. console.log('-------------个人主页 end-------------------')
  279. }
  280. this.setData({
  281. listLoading: false,
  282. })
  283. }).catch(error => {
  284. console.log(error, 'error appletLogin')
  285. })
  286. },
  287. //
  288. /**
  289. * 页面上拉触底事件的处理函数
  290. */
  291. onReachBottom: function () {
  292. if (this.data.onRefresh) {
  293. this.setData({
  294. itemLoading: true
  295. })
  296. this.getListData();
  297. }
  298. },
  299. /**
  300. * 用户点击右上角分享
  301. */
  302. onShareAppMessage: function () {
  303. }
  304. })