index.js 3.7 KB

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