index.js 9.8 KB

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