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