index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. lifetimes: {
  25. attached: function () {
  26. // 在组件实例进入页面节点树时执行
  27. _Http.basic({
  28. "accesstoken": wx.getStorageSync('userData').token,
  29. "classname": "enterprise.system.supplyanddemand",
  30. "method": "query_typeselectList",
  31. "content": {}
  32. }).then(res => {
  33. console.log(res)
  34. if (res.msg != "成功") return;
  35. let dataList = []
  36. for (let i = 0; i < res.data.length; i++) {
  37. let checked = false;
  38. if (res.data[i].ftype == this.data.pitchOnItem) checked = true;
  39. dataList.push({
  40. value: res.data[i].ftype,
  41. index: i,
  42. checked: checked
  43. })
  44. }
  45. this.setData({
  46. dataList
  47. })
  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. })