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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. 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: this.data.customerId }
  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. // 上架传0 下架传-1
  152. $request.post(`/businessCommunicationDemand/outDemand.action`,
  153. { businessCommunicationDemandId, state: state != 0 ? 0 : -1 }
  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. // 显示下架原因
  242. showOutReason(e){
  243. let outReason = e.currentTarget.dataset.outreason;
  244. wx.showModal({
  245. title: '下架原因',
  246. content: outReason,
  247. showCancel: false,
  248. })
  249. },
  250. getListData() {
  251. let { page, size, customerId, keyword, currentTab } = this.data;
  252. $request.get('/businessCommunicationDemand/getDemandByStateAndCustomerId.action',
  253. { page, size, customerId, keyword, state: currentTab }
  254. ).then(res => {
  255. let tempListData = this.data.listData;
  256. if (res.status == 0) {
  257. let datas = res.data;
  258. // 先push数据
  259. tempListData.push(...datas.demandList);
  260. tempListData.forEach(el => {
  261. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  262. el.createdOn = el.createdOn.replaceAll('/', '-');
  263. if (typeof el.type == 'string') {
  264. el.type = el.type.split(',');
  265. }
  266. })
  267. // 设置总数
  268. this.setData({
  269. listData: tempListData,
  270. total: datas.total,
  271. })
  272. // 如果数据大于了返回的总数
  273. if (tempListData.length >= this.data.total) {
  274. // 停止累加数据
  275. this.setData({
  276. onRefresh: false,
  277. itemLoading: false,
  278. })
  279. } else {
  280. this.setData({
  281. onRefresh: true,
  282. itemLoading: false,
  283. page: page + 1
  284. })
  285. }
  286. }
  287. this.setData({
  288. listLoading: false,
  289. })
  290. }).catch(error => {
  291. console.log(error, 'error appletLogin')
  292. })
  293. },
  294. //
  295. /**
  296. * 页面上拉触底事件的处理函数
  297. */
  298. onReachBottom: function () {
  299. if (this.data.onRefresh) {
  300. this.setData({
  301. itemLoading: true
  302. })
  303. this.getListData();
  304. }
  305. },
  306. })