index.js 2.4 KB

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