index.js 9.1 KB

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