index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. saleprodclass: {
  16. type: Array,
  17. value: []
  18. },
  19. /* 回调 */
  20. saleprodChange: {
  21. type: Function
  22. },
  23. /* 分类列表 */
  24. dataList: {
  25. type: Array
  26. },
  27. /* 是否请求 */
  28. isRequest: {
  29. type: Boolean,
  30. value: true
  31. }
  32. },
  33. lifetimes: {
  34. attached: function () {
  35. //查询类目列表
  36. if (this.data.isRequest) _Http.basic({
  37. "accesstoken": wx.getStorageSync('userData').token,
  38. "classname": "enterprise.system.prodclass",
  39. "method": "query_typeselectList",
  40. "content": {}
  41. }).then(res => {
  42. if (res.msg != '成功') return;
  43. let dataList = [];
  44. for (let i = 0; i < res.data.length; i++) {
  45. dataList.push({
  46. value: res.data[i],
  47. index: i,
  48. checked: false
  49. })
  50. }
  51. //遍历选中数据
  52. const arr = this.data.saleprodclass;
  53. for (let i = 0; i < arr.length; i++) {
  54. for (let k = 0; k < dataList.length; k++) {
  55. if (arr[i] == dataList[k].value) {
  56. dataList[k].checked = true;
  57. break;
  58. }
  59. }
  60. }
  61. this.setData({
  62. dataList
  63. })
  64. })
  65. },
  66. },
  67. /**
  68. * 组件的初始数据
  69. */
  70. data: {
  71. pitchOnList: [], //选中列表
  72. },
  73. /**
  74. * 组件的方法列表
  75. */
  76. methods: {
  77. /* 确定 */
  78. confirm() {
  79. this.triggerEvent("saleprodChange", this.data.pitchOnList)
  80. },
  81. /* 多选框返回数值 */
  82. checkedChange(e) {
  83. this.setData({
  84. pitchOnList: e.detail.value
  85. });
  86. },
  87. /* 添加背景色 */
  88. pitchOn(e) {
  89. let dataList = this.data.dataList;
  90. dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
  91. this.setData({
  92. dataList
  93. })
  94. }
  95. }
  96. })