index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {
  2. ApiModel
  3. } from "../../utils/api"
  4. const _Http = new ApiModel();
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. /* 标题 */
  11. title: {
  12. type: String,
  13. },
  14. /* 选中项 */
  15. pitchOnItem: {
  16. type: String,
  17. value: ""
  18. },
  19. /* 回调 */
  20. optionChange: {
  21. type: Function
  22. },
  23. /* 类型,默认供需分类 */
  24. type: {
  25. type: String,
  26. value: 'mr'
  27. }
  28. },
  29. lifetimes: {
  30. ready: function () {
  31. // 在组件实例进入页面节点树时执行
  32. //选择合作方式
  33. if (this.data.type == 'annunciate') {
  34. const res = {
  35. msg: "成功",
  36. data: [{
  37. ftype: "合作商通告"
  38. }, {
  39. ftype: "团队通告"
  40. }]
  41. };
  42. return this.returnClassify(res)
  43. };
  44. //默认供需分类
  45. let data = {
  46. "classname": "publicmethod.homepage.homepage",
  47. "method": "query_typeselectList",
  48. "content": {}
  49. };
  50. if (this.data.type == 'product') data = {
  51. "accesstoken": wx.getStorageSync('userData').token,
  52. "classname": "enterprise.system.prodclass",
  53. "method": "query_typeselectList",
  54. "content": {}
  55. };
  56. _Http.basic(data).then(res => {
  57. console.log(res)
  58. this.returnClassify(res);
  59. })
  60. },
  61. },
  62. /**
  63. * 组件的初始数据
  64. */
  65. data: {
  66. dataList: [], //类目列表
  67. pitchOn: '', //选中
  68. },
  69. /**
  70. * 组件的方法列表
  71. */
  72. methods: {
  73. /* 确定 */
  74. confirm() {
  75. this.triggerEvent("optionChange", this.data.pitchOn)
  76. },
  77. /* 多选框返回数值 */
  78. radioChange(e) {
  79. this.setData({
  80. pitchOn: e.detail.value
  81. })
  82. },
  83. /* 添加背景色 */
  84. pitchOn(e) {
  85. let dataList = this.data.dataList;
  86. for (let i = 0; i < dataList.length; i++) {
  87. dataList[i].checked = false
  88. }
  89. dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
  90. this.setData({
  91. dataList
  92. })
  93. },
  94. /* 返回分类 */
  95. returnClassify(res) {
  96. if (res.msg != "成功") return wx.showToast({
  97. title: '数据加载失败,请重新进入页面',
  98. icon: "none",
  99. duration: 5000
  100. })
  101. let dataList = []
  102. for (let i = 0; i < res.data.length; i++) {
  103. let checked = false,
  104. value = "";
  105. if (this.data.type == 'product') {
  106. if (res.data[i] == this.data.pitchOnItem) checked = true;
  107. value = res.data[i];
  108. } else {
  109. if (res.data[i].ftype == this.data.pitchOnItem) checked = true;
  110. value = res.data[i].ftype;
  111. }
  112. dataList.push({
  113. value,
  114. index: i,
  115. checked: checked
  116. })
  117. }
  118. this.setData({
  119. dataList
  120. })
  121. }
  122. }
  123. })