业务交流通
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

myRelease.js 9.7KB

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