index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. properties: {
  4. disabled: {
  5. type: Boolean,
  6. value: false
  7. }
  8. },
  9. options: {
  10. addGlobalClass: true
  11. },
  12. lifetimes: {
  13. attached: function () {
  14. getApp().globalData.Language.getLanguagePackage(this)
  15. this.setData({
  16. siteid: wx.getStorageSync('userMsg').siteid
  17. })
  18. }
  19. },
  20. data: {
  21. sa_workorderid: 0,
  22. content: {
  23. nocache: true,
  24. pageNumber: 1,
  25. pageSize: 10,
  26. pageTotal: 1,
  27. total: null,
  28. where: {
  29. condition: ""
  30. }
  31. },
  32. list: [],
  33. showSearch: false,
  34. focus: false,
  35. condition: ""
  36. },
  37. methods: {
  38. getList(id, init = false) {
  39. console.log("getList", id)
  40. let content = {
  41. ...this.data.content,
  42. sa_workorderid: id || this.data.sa_workorderid
  43. };
  44. if (init) {
  45. content.pageNumber = 1
  46. content.pageTotal = 1
  47. }
  48. _Http.basic({
  49. "id": 2026012813264502,
  50. content
  51. }).then(res => {
  52. console.log("服务产品", res)
  53. if (res.code != '1') return wx.showToast({
  54. title: res.data,
  55. icon: "none"
  56. });
  57. let list = res.data.map(v => {
  58. try {
  59. v.cover = v.attinfos.length ? _Http.getSpecifiedImage(v.attinfos[0]) : ''
  60. } catch (error) {
  61. }
  62. return v
  63. })
  64. this.setData({
  65. "content.pageNumber": res.pageNumber + 1,
  66. "content.pageTotal": res.pageTotal,
  67. "content.total": res.total,
  68. list: res.pageNumber == 1 ? list : this.data.list.concat(list),
  69. sa_workorderid: content.sa_workorderid
  70. })
  71. })
  72. },
  73. onBlur(e) {
  74. let {
  75. value
  76. } = e.detail, {
  77. name,
  78. item,
  79. index
  80. } = e.currentTarget.dataset;
  81. if (item[name] == value) return;
  82. if (name == 'qty' && value <= 0) {
  83. getApp().globalData.Language.modeBoxPrompts('数量不符合规则,已重置为1')
  84. item[name] = 1
  85. } else {
  86. item[name] = value
  87. }
  88. _Http.basic({
  89. "id": "20230215201903",
  90. "content": {
  91. "sa_workorderid": this.data.sa_workorderid,
  92. "iteminfos": [item]
  93. }
  94. }).then(res => {
  95. console.log("产品修改", res)
  96. if (res.code != '1') return wx.showToast({
  97. title: res.msg,
  98. icon: "none"
  99. });
  100. this.setData({
  101. [`list[${index}]`]: item
  102. })
  103. });
  104. },
  105. toSearch() {
  106. if (this.data.showSearch && this.data.content.where.condition) {
  107. this.data.content.where.condition = '';
  108. this.getList("", true);
  109. } else if (this.data.condition) {
  110. this.data.content.where.condition = this.data.condition;
  111. this.setData({
  112. condition: this.data.condition
  113. })
  114. this.getList("", true);
  115. }
  116. this.setData({
  117. showSearch: !this.data.showSearch
  118. })
  119. setTimeout(() => {
  120. this.setData({
  121. focus: this.data.showSearch
  122. })
  123. }, 300)
  124. },
  125. onChange({
  126. detail
  127. }) {
  128. this.data.condition = detail;
  129. },
  130. onSearch({
  131. detail
  132. }) {
  133. this.data.content.where.condition = detail;
  134. this.getList("", true)
  135. },
  136. }
  137. })