index.js 3.2 KB

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