index.js 10 KB

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