index.js 8.9 KB

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