index.js 2.6 KB

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