业务交流通
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. // 上架传0 下架传-1
  153. $request.post(`/businessCommunicationDemand/outDemand.action`,
  154. { businessCommunicationDemandId, state: state != 0 ? 0 : -1 }
  155. ).then(res => {
  156. wx.hideLoading()
  157. if (res.status == 0) {
  158. wx.showToast({
  159. title: state == 0 ? '下架成功' : '上架成功',
  160. icon: 'success',
  161. duration: 2000
  162. })
  163. let listData = this.data.listData;
  164. listData.forEach((el, inx) => {
  165. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  166. listData.splice(inx, 1);
  167. }
  168. })
  169. this.setData({
  170. listData
  171. })
  172. }
  173. }).catch(error => {
  174. console.log(error, 'error appletLogin')
  175. wx.hideLoading()
  176. })
  177. },
  178. // 删除需求
  179. productDel(e) {
  180. let item = e.currentTarget.dataset.item;
  181. let that = this;
  182. wx.showModal({
  183. title: '提示',
  184. content: "是否确认删除?",
  185. confirmText: "确认",
  186. cancelText: "取消",
  187. success(res) {
  188. if (res.confirm) {
  189. that.productDelPost(item);
  190. }
  191. }
  192. })
  193. },
  194. // 删除需求 Fn
  195. productDelPost(item) {
  196. let { businessCommunicationDemandId } = item;
  197. this.showLoading();
  198. $request.post(`/businessCommunicationDemand/deleteDemand.action`,
  199. { businessCommunicationDemandId }
  200. ).then(res => {
  201. wx.hideLoading()
  202. if (res.status == 0) {
  203. wx.showToast({
  204. title: '删除成功',
  205. icon: 'success',
  206. duration: 2000
  207. })
  208. let listData = this.data.listData;
  209. listData.forEach((el, inx) => {
  210. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  211. listData.splice(inx, 1);
  212. }
  213. })
  214. this.setData({
  215. listData
  216. })
  217. }
  218. }).catch(error => {
  219. console.log(error, 'error appletLogin')
  220. wx.hideLoading()
  221. })
  222. },
  223. // 修改需求
  224. productEdit(e) {
  225. let item = e.currentTarget.dataset.item;
  226. let that = this;
  227. wx.navigateTo({
  228. url: '/pages/releaseModule/index',
  229. success: function (res) {
  230. // 通过eventChannel向被打开页面传送数据
  231. res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: item })
  232. }
  233. })
  234. },
  235. // 数据加载提示
  236. showLoading(title) {
  237. wx.showLoading({
  238. title: title ? title : '加载中',
  239. mask: true
  240. })
  241. },
  242. // 显示下架原因
  243. showOutReason(e){
  244. let outReason = e.currentTarget.dataset.outreason;
  245. wx.showModal({
  246. title: '下架原因',
  247. content: outReason,
  248. showCancel: false,
  249. })
  250. },
  251. getListData() {
  252. let { page, size, customerId, keyword, currentTab } = this.data;
  253. $request.get('/businessCommunicationDemand/getDemandByStateAndCustomerId.action',
  254. { page, size, customerId, keyword, state: currentTab }
  255. ).then(res => {
  256. let tempListData = this.data.listData;
  257. if (res.status == 0) {
  258. let datas = res.data;
  259. console.log(datas, 'datas')
  260. // 先push数据
  261. tempListData.push(...datas.demandList);
  262. tempListData.forEach(el => {
  263. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  264. el.createdOn = el.createdOn.replaceAll('/', '-');
  265. if (typeof el.type == 'string') {
  266. el.type = el.type.split(',');
  267. }
  268. })
  269. // 设置总数
  270. this.setData({
  271. listData: tempListData,
  272. total: datas.total,
  273. })
  274. // 如果数据大于了返回的总数
  275. if (tempListData.length >= this.data.total) {
  276. // 停止累加数据
  277. this.setData({
  278. onRefresh: false,
  279. itemLoading: false,
  280. })
  281. } else {
  282. this.setData({
  283. onRefresh: true,
  284. itemLoading: false,
  285. page: page + 1
  286. })
  287. }
  288. console.log('-------------个人主页 beg-------------------')
  289. console.log(this.data.listData);
  290. console.log('-------------个人主页 end-------------------')
  291. }
  292. this.setData({
  293. listLoading: false,
  294. })
  295. }).catch(error => {
  296. console.log(error, 'error appletLogin')
  297. })
  298. },
  299. //
  300. /**
  301. * 页面上拉触底事件的处理函数
  302. */
  303. onReachBottom: function () {
  304. if (this.data.onRefresh) {
  305. this.setData({
  306. itemLoading: true
  307. })
  308. this.getListData();
  309. }
  310. },
  311. })