index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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, condition = '') {
  237. const ftype = (this.data.ftype != '全部') ? this.data.ftype : "";
  238. let where = {
  239. "condition": this.data.searchText, //模糊搜索
  240. "ftype": ftype, //数据类型
  241. "fissupply": 0, // 0需 1供
  242. "fstatus": ""
  243. };
  244. /* 暂时不分供需 */
  245. if (fstatus) {
  246. where = {
  247. "condition": this.data.searchText, //模糊搜索
  248. "ftype": ftype, //数据类型
  249. "fissupply": 0, // 0需 1供
  250. "fstatus": "对接中"
  251. }
  252. };
  253. _Http.basic({
  254. "accesstoken": wx.getStorageSync('userData').token,
  255. "classname": "customer.supplyanddemand.supplyanddemand",
  256. "method": "query_supplyanddemandList",
  257. "content": {
  258. "getdatafromdbanyway": true,
  259. "pageNumber": this.data.pageNumber,
  260. "pageSize": 20,
  261. "where": where
  262. }
  263. }).then(res => {
  264. console.log("供需列表", res)
  265. if (res.msg != "成功") return wx.showToast({
  266. title: res.data,
  267. icon: "none"
  268. })
  269. this.returnList(res);
  270. })
  271. },
  272. /* tabs */
  273. tabsChange(even) {
  274. this.setData({
  275. active: even.detail.index
  276. })
  277. /* 初始化分页 */
  278. this.InitializeDataPaging();
  279. this.getList();
  280. },
  281. /* 跳转商品详情页 */
  282. jumpForDetails(e) {
  283. const {
  284. index
  285. } = e.currentTarget.dataset,
  286. id = this.data.productList[index].tsupplyanddemandid;
  287. wx.navigateTo({
  288. url: '/pages/tabbar-pages/supplyAndDemand/particulars?tsupplyanddemandid=' + id + '&type=' + this.data.active,
  289. })
  290. },
  291. /* 我的需求 */
  292. myNeed() {
  293. //全部加载完成退出请求
  294. _Http.basic({
  295. "accesstoken": wx.getStorageSync('userData').token,
  296. "classname": "customer.supplyanddemand.supplyanddemand",
  297. "method": "query_mysupplyanddemandList",
  298. "content": {
  299. "getdatafromdbanyway": true,
  300. "pageNumber": this.data.pageNumber,
  301. "pageSize": 20,
  302. "where": {
  303. "condition": this.data.searchText,
  304. "ftype": "",
  305. "fissupply": "0"
  306. }
  307. }
  308. }).then(res => {
  309. if (res.msg != "成功") return wx.showToast({
  310. title: res.data,
  311. })
  312. this.returnList(res);
  313. })
  314. },
  315. /* 返回列表 */
  316. returnList(res) {
  317. let data = handleList.checkdate(res.data)
  318. let productList = handleList.imageType(data, 'default');
  319. //替换或拼接
  320. if (res.pageNumber != 1) {
  321. productList = this.data.productList.concat(productList);
  322. }
  323. this.setData({
  324. productList,
  325. pageTotal: res.pageTotal,
  326. });
  327. },
  328. /* 我的需求编辑按钮跳转 */
  329. productEdit(e) {
  330. const {
  331. index
  332. } = e.currentTarget.dataset
  333. const data = JSON.stringify(this.data.productList[index])
  334. wx.navigateTo({
  335. url: '/pages/announceDemand/index?data=' + data,
  336. })
  337. },
  338. /* 我的需求搜索框获得焦点 */
  339. needSearchFocus() {
  340. this.setData({
  341. searchFocus: true
  342. })
  343. },
  344. /* 我的需求搜索框失去焦点 */
  345. needSearchBlur(e) {
  346. const {
  347. value
  348. } = e.detail;
  349. //数据比较,防止重复查询
  350. if (value == this.data.searchText) return this.setData({
  351. searchFocus: false,
  352. });
  353. this.setData({
  354. searchFocus: false,
  355. searchText:value
  356. })
  357. this.InitializeDataPaging();
  358. if (this.data.active == 0) {
  359. this.getSupplyAndDemand();
  360. } else {
  361. this.myNeed();
  362. }
  363. },
  364. /* 初始化分页数据 */
  365. InitializeDataPaging() {
  366. this.setData({
  367. pageTotal: 2,
  368. pageNumber: 1
  369. })
  370. },
  371. /**
  372. * 生命周期函数--监听页面隐藏
  373. */
  374. onHide: function () {
  375. this.setData({
  376. isOnShow: true
  377. })
  378. },
  379. /* 阻止刷新列表 */
  380. stopOnShow() {
  381. this.setData({
  382. isOnShow: false
  383. })
  384. },
  385. /**
  386. * 生命周期函数--监听页面卸载
  387. */
  388. onUnload: function () {
  389. },
  390. /**
  391. * 页面相关事件处理函数--监听用户下拉动作
  392. */
  393. onPullDownRefresh: function () {
  394. },
  395. /**
  396. * 页面上拉触底事件的处理函数
  397. */
  398. onReachBottom: function () {
  399. this.setData({
  400. pageNumber: this.data.pageNumber + 1
  401. })
  402. if (this.data.pageNumber <= this.data.pageTotal) this.getList();
  403. },
  404. /**
  405. * 用户点击右上角分享
  406. */
  407. onShareAppMessage: function () {
  408. }
  409. })