seled.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/sorting/choice.js
  2. const app=getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. mainActiveIndex: 0,
  9. activeId: null,
  10. items:[],
  11. right1:"",
  12. wnumber:"",
  13. keyword:""
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.setData({
  20. wnumber:options.wnumber
  21. })
  22. this.getcaless();
  23. },
  24. onClickNav({ detail = {} }) {
  25. var id = detail.index || 0;
  26. this.setData({
  27. right1: this.data.right2[id]
  28. })
  29. },
  30. onClickItem(e) {
  31. var id=e.target.dataset.id;
  32. var title=e.currentTarget.dataset.title
  33. console.log(e);
  34. let pages = getCurrentPages();
  35. let prevPage = pages[pages.length - 2]; //上一页 -1为当前页面
  36. prevPage.setData({
  37. id: id,
  38. title:title,
  39. wnumber:this.data.wnumber
  40. })
  41. wx.navigateBack({
  42. delta: 1 //想要返回的层级
  43. })
  44. },
  45. toEnter(){
  46. wx.navigateTo({
  47. url: '../enter/enter',
  48. })
  49. },
  50. bindinput(e){
  51. console.log(e)
  52. this.setData({
  53. keyword:e.detail.value
  54. })
  55. },
  56. delete(){
  57. },
  58. getcaless: function (e) {
  59. console.log(e)
  60. //var name = e.detail.value['search - input'] ? e.detail.value['search - input'] : e.detail.value;
  61. var that=this;
  62. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/category", {
  63. keyword:this.data.keyword,
  64. }, "get").then(function (res) {
  65. console.log(res);
  66. if (res.code != 200) {
  67. wx.showLoading({
  68. title:res.message.msg,
  69. })
  70. setTimeout(function () {
  71. wx.hideLoading();
  72. }, 1000);
  73. } else {
  74. wx.hideLoading();
  75. var data = res.message.data;
  76. var shop = [];
  77. if(data==[] || data==""){
  78. wx.showLoading({
  79. title:"未获取到结果。",
  80. })
  81. setTimeout(function () {
  82. wx.hideLoading();
  83. }, 2000);
  84. }
  85. for (var index in data) {
  86. shop[index] = data[index].children
  87. }
  88. that.setData({
  89. items:data,
  90. right1: data[0].children,
  91. right2: shop
  92. })
  93. }
  94. }).catch(function (err) {
  95. console.log(222);
  96. })
  97. },
  98. afterRead(event) {
  99. const { file } = event.detail;
  100. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  101. wx.uploadFile({
  102. url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
  103. filePath: file.url,
  104. name: 'file',
  105. formData: { user: 'test' },
  106. success(res) {
  107. // 上传完成需要更新 fileList
  108. const { fileList = [] } = this.data;
  109. fileList.push({ ...file, url: res.data });
  110. this.setData({ fileList });
  111. },
  112. });
  113. },
  114. })