index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. id: "001",
  25. url: "/static/userImage.png",
  26. src: ''
  27. }, {
  28. id: "002",
  29. url: "/static/userImage.png",
  30. src: ''
  31. }, {
  32. id: "003",
  33. url: "/static/userImage.png",
  34. src: ''
  35. }],
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. /* 获取所有信息分类 */
  42. _Http.basic({
  43. "accesstoken": wx.getStorageSync('userData').token,
  44. "classname": "enterprise.system.supplyanddemand",
  45. "method": "query_typeselectList",
  46. "content": {}
  47. }).then(res => {
  48. if (res.msg != '成功') return;
  49. this.setData({
  50. ftypeList: res.data
  51. })
  52. })
  53. },
  54. /* tabs切换接口 */
  55. getList() {
  56. if (this.data.active == 0) return this.getSupplyAndDemand();
  57. if (this.data.active == 1) return this.getSupplyAndDemand(true);
  58. if (this.data.active == 2) return this.myNeed();
  59. },
  60. /* 宫格区点击事件 */
  61. switchScreenType(even) {
  62. let {
  63. type
  64. } = even.currentTarget.dataset;
  65. this.InitializeDataPaging();
  66. /* 第二次触发同一个,查询全部 */
  67. if (type == this.data.ftype) type = "";
  68. this.setData({
  69. ftype: type
  70. });
  71. this.getSupplyAndDemand()
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. this.getTabBar().init();
  83. //获取列表
  84. if (this.data.isOnShow) {
  85. this.getList();
  86. } else {
  87. this.setData({
  88. isOnShow: true
  89. })
  90. }
  91. },
  92. /* 显示沟通数量 */
  93. showCommunicationOfNumber() {
  94. this.setData({
  95. ifShowCommunicationOfNumber: !this.data.ifShowCommunicationOfNumber
  96. })
  97. },
  98. /* 阻止冒泡 */
  99. stop() {
  100. },
  101. /* 一键联系 */
  102. contact() {
  103. console.log('一键联系')
  104. },
  105. /* 供需下架 */
  106. soldOut(e) {
  107. const that = this;
  108. const {
  109. index
  110. } = e.target.dataset;
  111. wx.showModal({
  112. title: '提示',
  113. content: '是否确定下架该需求',
  114. success: function (res) {
  115. if (res.confirm) {
  116. _Http.basic({
  117. "accesstoken": wx.getStorageSync('userData').token,
  118. "classname": "customer.supplyanddemand.supplyanddemand",
  119. "method": "updatesupplyanddemandstatus",
  120. "content": {
  121. "tsupplyanddemandid": that.data.productList[index].tsupplyanddemandid,
  122. "fstatus": "已解决"
  123. }
  124. }).then(res => {
  125. console.log(res)
  126. if (res.msg != "成功") return;
  127. let productList = that.data.productList;
  128. productList[index].fstatus = "已解决"
  129. that.setData({
  130. productList
  131. })
  132. wx.showToast({
  133. title: "下架成功"
  134. })
  135. })
  136. }
  137. }
  138. });
  139. },
  140. /* 获取供需列表 */
  141. getSupplyAndDemand(fstatus) {
  142. let condition = "";
  143. let where = {
  144. "condition": condition, //模糊搜索
  145. "ftype": this.data.ftype, //数据类型
  146. "fissupply": "" // 0需 1供
  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. this.returnList(res);
  210. })
  211. },
  212. /* 返回列表 */
  213. returnList(res) {
  214. const data = handleList.checkdate(res.data)
  215. const productList = handleList.listOrdering(data);
  216. let pageNumber = this.data.pageNumber + 1;
  217. //替换或拼接
  218. if (res.pageNumber == 1) {
  219. this.InitializeDataPaging()
  220. //第一页直接替换list
  221. this.setData({
  222. productList,
  223. pageTotal: res.pageTotal,
  224. pageNumber
  225. });
  226. } else {
  227. //第二页开始拼接列表
  228. let list = this.data.productList.concat(productList);
  229. this.setData({
  230. productList: list,
  231. pageNumber
  232. })
  233. };
  234. },
  235. /* 我的需求编辑按钮跳转 */
  236. productEdit(e) {
  237. console.log(e)
  238. const {
  239. index
  240. } = e.currentTarget.dataset
  241. const data = JSON.stringify(this.data.productList[index])
  242. wx.navigateTo({
  243. url: '/pages/announceDemand/index?data=' + data,
  244. })
  245. },
  246. /* 我的需求搜索框获得焦点 */
  247. needSearchFocus() {
  248. this.setData({
  249. searchFocus: true
  250. })
  251. },
  252. /* 我的需求搜索框失去焦点 */
  253. needSearchBlur(e) {
  254. const {
  255. value
  256. } = e.detail;
  257. //数据比较,防止重复查询
  258. if (value == this.data.searchText) return this.setData({
  259. searchFocus: false,
  260. });
  261. let searchText = "";
  262. if (value != "") searchText = value;
  263. this.setData({
  264. searchFocus: false,
  265. searchText
  266. })
  267. this.InitializeDataPaging();
  268. this.myNeed();
  269. },
  270. /* 初始化分页数据 */
  271. InitializeDataPaging() {
  272. this.setData({
  273. pageTotal: 2,
  274. pageNumber: 1
  275. })
  276. },
  277. /**
  278. * 生命周期函数--监听页面隐藏
  279. */
  280. onHide: function () {
  281. this.setData({
  282. isOnShow: true
  283. })
  284. },
  285. /* 阻止刷新列表 */
  286. stopOnShow() {
  287. this.setData({
  288. isOnShow: false
  289. })
  290. },
  291. /**
  292. * 生命周期函数--监听页面卸载
  293. */
  294. onUnload: function () {
  295. },
  296. /**
  297. * 页面相关事件处理函数--监听用户下拉动作
  298. */
  299. onPullDownRefresh: function () {
  300. },
  301. /**
  302. * 页面上拉触底事件的处理函数
  303. */
  304. onReachBottom: function () {
  305. if (this.data.pageNumber <= this.data.pageTotal) this.getList();
  306. },
  307. /**
  308. * 用户点击右上角分享
  309. */
  310. onShareAppMessage: function () {
  311. }
  312. })