index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. import {
  2. ApiModel
  3. } from "../../../utils/api";
  4. const _Http = new ApiModel();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. searchFocus: false, //我的需求搜索框焦点
  11. searchText: "", //我的需求搜索内容
  12. pageNumber: 1, //获取第几页
  13. pageTotal: 2, //全部分页数量
  14. active: 0, //tabs 选中下标
  15. ftypeList: [], //分类列表
  16. ftype: "", //当前查询分类
  17. /* 供需列表 */
  18. productList: [],
  19. //轮播图列表
  20. swiperBannerList: [{
  21. id: "001",
  22. url: "/static/userImage.png",
  23. src: ''
  24. }, {
  25. id: "002",
  26. url: "/static/userImage.png",
  27. src: ''
  28. }, {
  29. id: "003",
  30. url: "/static/userImage.png",
  31. src: ''
  32. }],
  33. /* 宫格列表 */
  34. gridList: [{
  35. id: '001',
  36. text: '寻找面料',
  37. icon: '/static/login/Phone.png'
  38. }, {
  39. id: '002',
  40. text: '面料设计',
  41. icon: '/static/login/identity.png'
  42. }, {
  43. id: '003',
  44. text: '平面设计',
  45. icon: '/static/login/username.png'
  46. }, {
  47. id: '004',
  48. text: '产品策划',
  49. icon: '/static/login/verificationcode.png'
  50. }, {
  51. id: '005',
  52. text: '寻找主播',
  53. icon: '/static/login/verificationcode.png'
  54. }, {
  55. id: '006',
  56. text: '摄影摄像',
  57. icon: '/static/login/identity.png'
  58. }, {
  59. id: '007',
  60. text: '商业培训',
  61. icon: '/static/login/username.png'
  62. }],
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad: function (options) {
  68. /* 获取所有信息分类 */
  69. _Http.basic({
  70. "accesstoken": wx.getStorageSync('userData').token,
  71. "classname": "enterprise.system.supplyanddemand",
  72. "method": "query_typeselectList",
  73. "content": {}
  74. }).then(res => {
  75. if (res.msg != '成功') return;
  76. this.setData({
  77. ftypeList: res.data
  78. })
  79. })
  80. },
  81. /* 宫格区点击事件 */
  82. switchScreenType(even) {
  83. let {
  84. type
  85. } = even.currentTarget.dataset;
  86. /* 第二次触发同一个,查询全部 */
  87. if (type == this.data.ftype) type = "";
  88. this.setData({
  89. ftype: type
  90. });
  91. this.getSupplyAndDemand()
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function () {
  102. this.getTabBar().init();
  103. //获取列表
  104. this.getList();
  105. },
  106. /* tabs切换接口 */
  107. getList() {
  108. if (this.data.active == 0) return this.getSupplyAndDemand();
  109. if (this.data.active == 2) return this.myNeed();
  110. },
  111. /* 供需下架 */
  112. soldOut(e) {
  113. const {
  114. index
  115. } = e.target.dataset
  116. console.log(index)
  117. _Http.basic({
  118. "accesstoken": wx.getStorageSync('userData').token,
  119. "classname": "customer.supplyanddemand.supplyanddemand",
  120. "method": "deletesupplyanddemand",
  121. "content": {
  122. "tsupplyanddemandid": this.data.productList[index].tsupplyanddemandid
  123. }
  124. }).then(res => {
  125. console.log(res)
  126. if (res.msg != "成功") {
  127. wx.showToast({
  128. title: res.data,
  129. icon: "error"
  130. })
  131. } else {
  132. console.log("删除产品")
  133. }
  134. })
  135. },
  136. /* 获取供需列表 */
  137. getSupplyAndDemand(fstatus) {
  138. if (this.data.pageNumber > this.data.pageTotal) return;
  139. let condition = "";
  140. let where = {
  141. "condition": condition, //模糊搜索
  142. "ftype": this.data.ftype, //数据类型
  143. "fissupply": "" // 0需 1供
  144. };
  145. if (fstatus) {
  146. where = {
  147. "condition": condition, //模糊搜索
  148. "ftype": this.data.ftype, //数据类型
  149. "fissupply": 0, // 0需 1供
  150. "fstatus": "对接中"
  151. }
  152. };
  153. _Http.basic({
  154. "accesstoken": wx.getStorageSync('userData').token,
  155. "classname": "customer.supplyanddemand.supplyanddemand",
  156. "method": "query_supplyanddemandList",
  157. "content": {
  158. "getdatafromdbanyway": true,
  159. "pageNumber": this.data.pageNumber,
  160. "pageSize": 20,
  161. "where": where
  162. }
  163. }).then(res => {
  164. console.log(res)
  165. if (res.msg != "成功") return;
  166. //替换或拼接
  167. if (res.pageNumber == 1) {
  168. this.InitializeDataPaging()
  169. //第一页直接替换list
  170. this.setData({
  171. productList: res.data,
  172. pageTotal: res.pageTotal
  173. });
  174. } else {
  175. //第二页开始拼接列表
  176. let productList = this.data.productList.concat(res.data);
  177. this.setData({
  178. productList
  179. })
  180. };
  181. this.PageDemanding()
  182. })
  183. },
  184. /* tabs */
  185. tabsChange(even) {
  186. this.setData({
  187. active: even.detail.index
  188. })
  189. /* 初始化分页 */
  190. this.InitializeDataPaging();
  191. this.getList();
  192. },
  193. /* 我的需求 */
  194. myNeed() {
  195. //全部加载完成退出请求
  196. if (this.data.pageTotal < this.data.pageNumber) return;
  197. _Http.basic({
  198. "accesstoken": wx.getStorageSync('userData').token,
  199. "classname": "customer.supplyanddemand.supplyanddemand",
  200. "method": "query_mysupplyanddemandList",
  201. "content": {
  202. "getdatafromdbanyway": true,
  203. "pageNumber": this.data.pageNumber,
  204. "pageSize": 20,
  205. "where": {
  206. "condition": this.data.searchText,
  207. "ftype": "",
  208. "fissupply": "0"
  209. }
  210. }
  211. }).then(res => {
  212. console.log(res);
  213. if (res.msg != "成功") return;
  214. //替换或拼接
  215. if (res.pageNumber == 1) {
  216. //第一页直接替换list
  217. this.setData({
  218. productList: res.data
  219. })
  220. this.InitializeDataPaging()
  221. } else {
  222. //第二页开始拼接列表
  223. let productList = this.data.productList.concat(res.data);
  224. this.setData({
  225. productList
  226. })
  227. console.log(321651)
  228. }
  229. this.PageDemanding()
  230. })
  231. },
  232. /* 我的需求编辑按钮跳转 */
  233. productEdit(e) {
  234. console.log(e)
  235. const {
  236. index
  237. } = e.currentTarget.dataset
  238. const data = JSON.stringify(this.data.productList[index])
  239. wx.navigateTo({
  240. url: '/pages/announceDemand/index?data=' + data,
  241. })
  242. },
  243. /* 我的需求搜索框获得焦点 */
  244. needSearchFocus() {
  245. this.setData({
  246. searchFocus: true
  247. })
  248. },
  249. /* 我的需求搜索框失去焦点 */
  250. needSearchBlur(e) {
  251. const {
  252. value
  253. } = e.detail;
  254. //数据比较,防止重复查询
  255. if (value == this.data.searchText) return this.setData({
  256. searchFocus: false,
  257. });
  258. let searchText = "";
  259. if (value != "") searchText = value;
  260. this.setData({
  261. searchFocus: false,
  262. searchText
  263. })
  264. this.InitializeDataPaging();
  265. this.myNeed();
  266. },
  267. /* 初始化分页数据 */
  268. InitializeDataPaging() {
  269. this.setData({
  270. pageTotal: 2,
  271. pageNumber: 1
  272. })
  273. },
  274. /* 分页 */
  275. PageDemanding() {
  276. let pageNumber = this.data.pageNumber + 1;
  277. this.setData({
  278. pageNumber
  279. })
  280. },
  281. /**
  282. * 生命周期函数--监听页面隐藏
  283. */
  284. onHide: function () {
  285. },
  286. /**
  287. * 生命周期函数--监听页面卸载
  288. */
  289. onUnload: function () {
  290. },
  291. /**
  292. * 页面相关事件处理函数--监听用户下拉动作
  293. */
  294. onPullDownRefresh: function () {
  295. },
  296. /**
  297. * 页面上拉触底事件的处理函数
  298. */
  299. onReachBottom: function () {
  300. this.getList();
  301. },
  302. /**
  303. * 用户点击右上角分享
  304. */
  305. onShareAppMessage: function () {
  306. }
  307. })