业务交流通
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

myRelease.js 9.6KB

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