index.js 13 KB

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