index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. isAll: {
  29. type: Boolean,
  30. value: false
  31. }
  32. },
  33. lifetimes: {
  34. ready: function () {
  35. // 在组件实例进入页面节点树时执行
  36. //选择合作方式
  37. if (this.data.type == 'annunciate') {
  38. const res = {
  39. msg: "成功",
  40. data: [{
  41. ftype: "合作商通告"
  42. }, {
  43. ftype: "团队通告"
  44. }]
  45. };
  46. return this.returnClassify(res)
  47. };
  48. //默认供需分类
  49. let data = {
  50. "classname": "publicmethod.homepage.homepage",
  51. "method": "query_typeselectList",
  52. "content": {}
  53. };
  54. if (this.data.type == 'product') data = {
  55. "accesstoken": wx.getStorageSync('userData').token,
  56. "classname": "enterprise.system.prodclass",
  57. "method": "query_typeselectList",
  58. "content": {}
  59. };
  60. _Http.basic(data).then(res => {
  61. console.log(res)
  62. if (this.data.isAll) res.data.unshift({
  63. attinfos: [],
  64. ftype: '全部',
  65. ttypedetailid: 0
  66. })
  67. this.returnClassify(res);
  68. })
  69. },
  70. },
  71. /**
  72. * 组件的初始数据
  73. */
  74. data: {
  75. dataList: [], //类目列表
  76. pitchOn: '', //选中
  77. },
  78. /**
  79. * 组件的方法列表
  80. */
  81. methods: {
  82. /* 确定 */
  83. confirm() {
  84. this.triggerEvent("optionChange", this.data.pitchOn)
  85. },
  86. /* 多选框返回数值 */
  87. radioChange(e) {
  88. this.setData({
  89. pitchOn: e.detail.value
  90. })
  91. },
  92. /* 添加背景色 */
  93. pitchOn(e) {
  94. let dataList = this.data.dataList;
  95. for (let i = 0; i < dataList.length; i++) {
  96. dataList[i].checked = false
  97. }
  98. dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
  99. this.setData({
  100. dataList
  101. })
  102. },
  103. /* 返回分类 */
  104. returnClassify(res) {
  105. if (res.msg != "成功") return wx.showToast({
  106. title: '数据加载失败,请重新进入页面',
  107. icon: "none",
  108. duration: 3000
  109. })
  110. let dataList = []
  111. for (let i = 0; i < res.data.length; i++) {
  112. let checked = false,
  113. value = "";
  114. if (this.data.type == 'product') {
  115. if (res.data[i] == this.data.pitchOnItem) checked = true;
  116. value = res.data[i];
  117. } else {
  118. if (res.data[i].ftype == this.data.pitchOnItem) checked = true;
  119. value = res.data[i].ftype;
  120. }
  121. dataList.push({
  122. value,
  123. index: i,
  124. checked: checked
  125. })
  126. }
  127. this.setData({
  128. dataList
  129. })
  130. }
  131. }
  132. })