index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. import {
  2. ApiModel
  3. } from "../../../utils/api";
  4. const _Http = new ApiModel();
  5. const handleList = require("../../../utils/processingData");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. isOnShow: true, //是否触发onshow中的刷新列表
  12. searchFocus: false, //我的需求搜索框焦点
  13. searchText: "", //我的需求搜索内容
  14. pageNumber: 1, //获取第几页
  15. pageTotal: 2, //全部分页数量
  16. active: 0, //tabs 选中下标
  17. ftypeList: [], //分类列表
  18. ftype: "全部", //当前查询分类
  19. ifShowCommunicationOfNumber: false,
  20. /* 供需列表 */
  21. productList: [],
  22. //轮播图列表
  23. swiperBannerList: [],
  24. imdialogs: [], //沟通列表
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. /* 获取所有信息分类 */
  31. _Http.basic({
  32. "accesstoken": wx.getStorageSync('userData').token,
  33. "classname": "enterprise.system.supplyanddemand",
  34. "method": "query_typeselectList",
  35. "content": {}
  36. }).then(res => {
  37. console.log("分类", res)
  38. if (res.msg != '成功') return wx.showToast({
  39. title: res.data,
  40. icon: "none"
  41. });
  42. for (let i = 0; i < res.data.length; i++) {
  43. let attinfos = [];
  44. for (let k = 0; k < res.data[i].attinfos.length; k++) {
  45. if (res.data[i].attinfos[k].ftype == 'default') {
  46. attinfos.unshift(res.data[i].attinfos[k])
  47. } else if (res.data[i].attinfos[k].ftype == 'click') {
  48. attinfos.push(res.data[i].attinfos[k])
  49. }
  50. };
  51. res.data[i].attinfos = attinfos;
  52. };
  53. /* 添加全部 */
  54. res.data.unshift({
  55. ftype: "全部",
  56. attinfos: [{
  57. fobsurl: "https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/supplyAndDemand/all-icon.png",
  58. ftype: "default"
  59. }, {
  60. fobsurl: "https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/supplyAndDemand/acAll-icon.png",
  61. ftype: "click"
  62. }]
  63. });
  64. this.setData({
  65. ftypeList: res.data
  66. });
  67. });
  68. /* 获取轮播图 */
  69. const bannerList = wx.getStorageSync('bannerDataList').filter(value => value.flocation == 'supplyanddemand_head');
  70. this.setData({
  71. swiperBannerList: bannerList[0].banner
  72. });
  73. },
  74. //跳转聊天
  75. toLinkUpPage(e) {
  76. const {
  77. timdialogid
  78. } = e.currentTarget.dataset;
  79. wx.navigateTo({
  80. url: '/pages/chatRoom/dialogbox?id=' + timdialogid,
  81. })
  82. },
  83. /* tabs切换接口 */
  84. getList() {
  85. if (this.data.active == 0) return this.getSupplyAndDemand();
  86. if (this.data.active == 1) return this.getSupplyAndDemand(true);
  87. if (this.data.active == 2) return this.myNeed();
  88. },
  89. /* 宫格区点击事件 */
  90. switchScreenType(even) {
  91. let {
  92. type
  93. } = even.currentTarget.dataset;
  94. if (type == this.data.ftype) return;
  95. this.InitializeDataPaging();
  96. this.setData({
  97. ftype: type
  98. });
  99. this.getSupplyAndDemand()
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow: function () {
  110. this.getTabBar().init();
  111. //获取列表
  112. if (this.data.isOnShow) {
  113. this.getList();
  114. } else {
  115. this.setData({
  116. isOnShow: true
  117. })
  118. }
  119. this.getTabBar().setData({
  120. 'tabbarList[3].fcount': getApp().globalData.msgFcount
  121. })
  122. },
  123. /* 显示沟通数量 */
  124. showCommunicationOfNumber(e) {
  125. let {
  126. item
  127. } = e.currentTarget.dataset;
  128. let imdialogs = [];
  129. _Http.basic({
  130. "accesstoken": wx.getStorageSync('userData').token,
  131. "classname": "customer.supplyanddemand.supplyanddemand",
  132. "method": "query_mysupplyanddemandMain",
  133. "content": {
  134. "tsupplyanddemandid": item.tsupplyanddemandid
  135. }
  136. }, false).then(res => {
  137. console.log('沟通列表', res)
  138. if (res.msg != '成功') return wx.showToast({
  139. title: res.data,
  140. icon: "none"
  141. })
  142. imdialogs = res.data[0].imdialogs;
  143. if (imdialogs.length != 0) {
  144. for (let i = 0; i < imdialogs.length; i++) {
  145. let checkdate = imdialogs[i].createdate;
  146. if (checkdate != null && checkdate != undefined) imdialogs[i].createdate = checkdate.slice(0, checkdate.lastIndexOf('.'));
  147. }
  148. this.setData({
  149. ifShowCommunicationOfNumber: true,
  150. imdialogs
  151. })
  152. } else {
  153. wx.showToast({
  154. title: '暂无对话信息',
  155. icon: "none"
  156. })
  157. }
  158. })
  159. },
  160. endShowCommunicationOfNumber() {
  161. this.setData({
  162. ifShowCommunicationOfNumber: false
  163. })
  164. },
  165. postDemand() {
  166. wx.navigateTo({
  167. url: '/pages/announceDemand/index',
  168. })
  169. },
  170. /* 阻止冒泡 */
  171. stop() {
  172. /* 所有供需列表中,已过期或已解决 不做操作 */
  173. },
  174. toLinkUp(e) {
  175. const {
  176. tsupplyanddemandid,
  177. tenterprise_userid
  178. } = e.currentTarget.dataset.item;
  179. if (tenterprise_userid == wx.getStorageSync('userData').userid) return wx.showToast({
  180. title: '无法与自己对话',
  181. icon: "none"
  182. })
  183. _Http.basic({
  184. "accesstoken": wx.getStorageSync('userData').token,
  185. "classname": "customer.supplyanddemand.supplyanddemand",
  186. "method": "OpenImDialog",
  187. "content": {
  188. "tsupplyanddemandid": tsupplyanddemandid
  189. }
  190. }).then(res => {
  191. console.log("创建聊天", res)
  192. if (res.msg != '成功') return wx.showToast({
  193. title: res.data,
  194. icon: "none"
  195. })
  196. wx.navigateTo({
  197. url: '/pages/chatRoom/dialogbox?id=' + res.data[0].timdialogid,
  198. })
  199. })
  200. },
  201. /* 供需下架 */
  202. soldOut(e) {
  203. const that = this;
  204. const {
  205. index
  206. } = e.target.dataset;
  207. wx.showModal({
  208. title: '提示',
  209. content: '是否确定下架该需求',
  210. success: function (res) {
  211. if (res.confirm) {
  212. _Http.basic({
  213. "accesstoken": wx.getStorageSync('userData').token,
  214. "classname": "customer.supplyanddemand.supplyanddemand",
  215. "method": "updatesupplyanddemandstatus",
  216. "content": {
  217. "tsupplyanddemandid": that.data.productList[index].tsupplyanddemandid,
  218. "fstatus": "已解决"
  219. }
  220. }).then(res => {
  221. if (res.msg != "成功") return;
  222. let productList = that.data.productList;
  223. productList[index].fstatus = "已解决"
  224. that.setData({
  225. productList
  226. })
  227. wx.showToast({
  228. title: "下架成功"
  229. })
  230. })
  231. }
  232. }
  233. });
  234. },
  235. /* 获取供需列表 */
  236. getSupplyAndDemand(fstatus) {
  237. const ftype = (this.data.ftype != '全部') ? this.data.ftype : "";
  238. let condition = "",
  239. where = {
  240. "condition": condition, //模糊搜索
  241. "ftype": ftype, //数据类型
  242. "fissupply": 0, // 0需 1供
  243. "fstatus": ""
  244. };
  245. /* 暂时不分供需 */
  246. if (fstatus) {
  247. where = {
  248. "condition": condition, //模糊搜索
  249. "ftype": ftype, //数据类型
  250. "fissupply": 0, // 0需 1供
  251. "fstatus": "对接中"
  252. }
  253. };
  254. _Http.basic({
  255. "accesstoken": wx.getStorageSync('userData').token,
  256. "classname": "customer.supplyanddemand.supplyanddemand",
  257. "method": "query_supplyanddemandList",
  258. "content": {
  259. "getdatafromdbanyway": true,
  260. "pageNumber": this.data.pageNumber,
  261. "pageSize": 20,
  262. "where": where
  263. }
  264. }).then(res => {
  265. console.log("供需列表", res)
  266. if (res.msg != "成功") return wx.showToast({
  267. title: res.data,
  268. icon: "none"
  269. })
  270. this.returnList(res);
  271. })
  272. },
  273. /* tabs */
  274. tabsChange(even) {
  275. this.setData({
  276. active: even.detail.index
  277. })
  278. /* 初始化分页 */
  279. this.InitializeDataPaging();
  280. this.getList();
  281. },
  282. /* 跳转商品详情页 */
  283. jumpForDetails(e) {
  284. const {
  285. index
  286. } = e.currentTarget.dataset,
  287. id = this.data.productList[index].tsupplyanddemandid;
  288. wx.navigateTo({
  289. url: '/pages/tabbar-pages/supplyAndDemand/particulars?tsupplyanddemandid=' + id + '&type=' + this.data.active,
  290. })
  291. },
  292. /* 我的需求 */
  293. myNeed() {
  294. //全部加载完成退出请求
  295. _Http.basic({
  296. "accesstoken": wx.getStorageSync('userData').token,
  297. "classname": "customer.supplyanddemand.supplyanddemand",
  298. "method": "query_mysupplyanddemandList",
  299. "content": {
  300. "getdatafromdbanyway": true,
  301. "pageNumber": this.data.pageNumber,
  302. "pageSize": 20,
  303. "where": {
  304. "condition": this.data.searchText,
  305. "ftype": "",
  306. "fissupply": "0"
  307. }
  308. }
  309. }).then(res => {
  310. if (res.msg != "成功") return wx.showToast({
  311. title: res.data,
  312. })
  313. this.returnList(res);
  314. })
  315. },
  316. /* 返回列表 */
  317. returnList(res) {
  318. let data = handleList.checkdate(res.data)
  319. let productList = handleList.imageType(data, 'default');
  320. //替换或拼接
  321. if (res.pageNumber != 1) {
  322. productList = this.data.productList.concat(productList);
  323. }
  324. this.setData({
  325. productList,
  326. pageTotal: res.pageTotal,
  327. });
  328. },
  329. /* 我的需求编辑按钮跳转 */
  330. productEdit(e) {
  331. const {
  332. index
  333. } = e.currentTarget.dataset
  334. const data = JSON.stringify(this.data.productList[index])
  335. wx.navigateTo({
  336. url: '/pages/announceDemand/index?data=' + data,
  337. })
  338. },
  339. /* 我的需求搜索框获得焦点 */
  340. needSearchFocus() {
  341. this.setData({
  342. searchFocus: true
  343. })
  344. },
  345. /* 我的需求搜索框失去焦点 */
  346. needSearchBlur(e) {
  347. const {
  348. value
  349. } = e.detail;
  350. //数据比较,防止重复查询
  351. if (value == this.data.searchText) return this.setData({
  352. searchFocus: false,
  353. });
  354. let searchText = "";
  355. if (value != "") searchText = value;
  356. this.setData({
  357. searchFocus: false,
  358. searchText
  359. })
  360. this.InitializeDataPaging();
  361. this.myNeed();
  362. },
  363. /* 初始化分页数据 */
  364. InitializeDataPaging() {
  365. this.setData({
  366. pageTotal: 2,
  367. pageNumber: 1
  368. })
  369. },
  370. /**
  371. * 生命周期函数--监听页面隐藏
  372. */
  373. onHide: function () {
  374. this.setData({
  375. isOnShow: true
  376. })
  377. },
  378. /* 阻止刷新列表 */
  379. stopOnShow() {
  380. this.setData({
  381. isOnShow: false
  382. })
  383. },
  384. /**
  385. * 生命周期函数--监听页面卸载
  386. */
  387. onUnload: function () {
  388. },
  389. /**
  390. * 页面相关事件处理函数--监听用户下拉动作
  391. */
  392. onPullDownRefresh: function () {
  393. },
  394. /**
  395. * 页面上拉触底事件的处理函数
  396. */
  397. onReachBottom: function () {
  398. this.setData({
  399. pageNumber: this.data.pageNumber + 1
  400. })
  401. if (this.data.pageNumber <= this.data.pageTotal) this.getList();
  402. },
  403. /**
  404. * 用户点击右上角分享
  405. */
  406. onShareAppMessage: function () {
  407. }
  408. })