index.js 9.0 KB

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