index.js 8.9 KB

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