index.js 12 KB

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