业务交流通
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

myRelease.js 9.7KB

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