index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {
  2. ApiModel
  3. } from "../../utils/api"
  4. const _Http = new ApiModel();
  5. Component({
  6. options:{
  7. addGlobalClass: true
  8. },
  9. /**
  10. * 组件的属性列表
  11. */
  12. properties: {
  13. /* 类型 */
  14. type: {
  15. type: String,
  16. value: "default" //annunciate
  17. },
  18. /* 标题 */
  19. title: {
  20. type: String,
  21. },
  22. /* 选中列表 */
  23. saleprodclass: {
  24. type: Array,
  25. value: []
  26. },
  27. /* 回调 */
  28. saleprodChange: {
  29. type: Function
  30. },
  31. /* 分类列表 */
  32. dataList: {
  33. type: Array,
  34. value: []
  35. },
  36. /* 是否请求 */
  37. isRequest: {
  38. type: Boolean,
  39. value: true
  40. }
  41. },
  42. lifetimes: {
  43. attached: function () {
  44. //查询类目列表
  45. if (this.data.isRequest) _Http.basic({
  46. "accesstoken": wx.getStorageSync('userData').token,
  47. "classname": "enterprise.system.prodclass",
  48. "method": "query_typeselectList",
  49. "content": {}
  50. }, false).then(res => {
  51. console.log('asdasd')
  52. if (res.msg != '成功') return;
  53. let dataList = [];
  54. for (let i = 0; i < res.data.length; i++) {
  55. dataList.push({
  56. value: res.data[i],
  57. index: i,
  58. checked: false
  59. })
  60. }
  61. //遍历选中数据
  62. const arr = this.data.saleprodclass;
  63. for (let i = 0; i < arr.length; i++) {
  64. for (let k = 0; k < dataList.length; k++) {
  65. if (arr[i] == dataList[k].value) {
  66. dataList[k].checked = true;
  67. break;
  68. }
  69. }
  70. }
  71. this.setData({
  72. dataList
  73. })
  74. })
  75. },
  76. },
  77. observers: {
  78. 'dataList,saleprodclass': function (dataList, saleprodclass) {
  79. console.log(dataList, saleprodclass)
  80. console.log(this.data.dataList)
  81. if (dataList.length == 0 || saleprodclass == 0) return;
  82. }
  83. },
  84. /**
  85. * 组件的初始数据
  86. */
  87. data: {
  88. pitchOnList: [], //选中列表
  89. },
  90. /**
  91. * 组件的方法列表
  92. */
  93. methods: {
  94. /* 确定 */
  95. confirm() {
  96. this.triggerEvent("saleprodChange", this.data.pitchOnList)
  97. },
  98. /* 多选框返回数值 */
  99. checkedChange(e) {
  100. this.setData({
  101. pitchOnList: e.detail.value
  102. });
  103. },
  104. /* 添加背景色 */
  105. pitchOn(e) {
  106. let dataList = this.data.dataList;
  107. dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
  108. this.setData({
  109. dataList
  110. })
  111. }
  112. }
  113. })