index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. "accesstoken": wx.getStorageSync('userData').token,
  47. "classname": "enterprise.system.supplyanddemand",
  48. "method": "query_typeselectList",
  49. "content": {}
  50. };
  51. if (this.data.type == 'product') data = {
  52. "accesstoken": wx.getStorageSync('userData').token,
  53. "classname": "enterprise.system.prodclass",
  54. "method": "query_typeselectList",
  55. "content": {}
  56. };
  57. _Http.basic(data).then(res => {
  58. console.log(res)
  59. this.returnClassify(res);
  60. })
  61. },
  62. },
  63. /**
  64. * 组件的初始数据
  65. */
  66. data: {
  67. dataList: [], //类目列表
  68. pitchOn: '', //选中
  69. },
  70. /**
  71. * 组件的方法列表
  72. */
  73. methods: {
  74. /* 确定 */
  75. confirm() {
  76. this.triggerEvent("optionChange", this.data.pitchOn)
  77. },
  78. /* 多选框返回数值 */
  79. radioChange(e) {
  80. this.setData({
  81. pitchOn: e.detail.value
  82. })
  83. },
  84. /* 添加背景色 */
  85. pitchOn(e) {
  86. let dataList = this.data.dataList;
  87. for (let i = 0; i < dataList.length; i++) {
  88. dataList[i].checked = false
  89. }
  90. dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
  91. this.setData({
  92. dataList
  93. })
  94. },
  95. /* 返回分类 */
  96. returnClassify(res) {
  97. if (res.msg != "成功") return wx.showToast({
  98. title: '数据加载失败,请重新进入页面',
  99. icon: "none",
  100. duration: 5000
  101. })
  102. let dataList = []
  103. for (let i = 0; i < res.data.length; i++) {
  104. let checked = false,
  105. value = "";
  106. if (this.data.type == 'product') {
  107. if (res.data[i] == this.data.pitchOnItem) checked = true;
  108. value = res.data[i];
  109. } else {
  110. if (res.data[i].ftype == this.data.pitchOnItem) checked = true;
  111. value = res.data[i].ftype;
  112. }
  113. dataList.push({
  114. value,
  115. index: i,
  116. checked: checked
  117. })
  118. }
  119. this.setData({
  120. dataList
  121. })
  122. }
  123. }
  124. })