getData.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { getStorage } from '@/common/utils/storage.js'
  2. export default {
  3. data() {
  4. return {
  5. // 网点下拉选项
  6. websitList: [],
  7. // 网点下拉选项选中的下标
  8. index: 0,
  9. // 类型切换选中值
  10. selected: 1,
  11. // 是否显示类型切换
  12. showTypeSwitching: true,
  13. // 下拉刷新状态
  14. refresherTriggered: false,
  15. // 配件类型列表
  16. accessoriesList: [],
  17. // 类型选中下标
  18. accessoriesIndex: -1,
  19. // 列表数据
  20. list: [],
  21. // 名称搜索
  22. partsName: '',
  23. option: {},
  24. apis: {
  25. default: {
  26. getGroupUrl: '/app/parts/stock/exist/websit/group/list',
  27. getStockUrl: '/app/parts/stock/exist/websit/stock/list'
  28. },
  29. applicationParts: {
  30. getGroupUrl: '/app/parts/websit/stock/group/list',
  31. getStockUrl: '/app/parts/websit/stock/list'
  32. }
  33. }
  34. }
  35. },
  36. onLoad(option) {
  37. this.option = option
  38. if (!option.partsWebsitId && !option.websitId) {
  39. this.getWebsitInfo()
  40. }
  41. },
  42. computed: {
  43. accessoriesParams() {
  44. if (this.option.partsWebsitId && this.option.websitId) {
  45. return {
  46. identity: this.userInfo.idCard,
  47. partsWebsitId: this.option.partsWebsitId,
  48. websitId: this.option.websitId
  49. }
  50. }
  51. var data = this.websitList[this.index]
  52. if (data) {
  53. return {
  54. identity: this.userInfo.idCard,
  55. partsAttr: ['OLD', 'NEW'][this.selected],
  56. partsWebsitId: data.partsWebsitId,
  57. websitId: data.websitId
  58. }
  59. } else {
  60. return false
  61. }
  62. },
  63. userInfo() {
  64. return getStorage('user')
  65. },
  66. idcard() {
  67. return this.userInfo.idCard
  68. }
  69. },
  70. watch: {
  71. accessoriesParams(newVal) {
  72. this.getGroup(newVal)
  73. this.list = []
  74. },
  75. accessoriesList(newVal) {
  76. if (this.accessoriesIndex !== 0) {
  77. this.accessoriesIndex = 0
  78. } else {
  79. this.getStock()
  80. }
  81. },
  82. accessoriesIndex() {
  83. this.getStock()
  84. },
  85. partsName() {
  86. this.getStock()
  87. }
  88. },
  89. methods: {
  90. // 获取网点
  91. getWebsitInfo() {
  92. this.$api
  93. .post('/app/parts/stock/exist/websit/list', {
  94. identity: this.idcard
  95. })
  96. .then(res => {
  97. console.log(res.data)
  98. this.websitList = res.data
  99. })
  100. .catch(() => {
  101. this.websitList = []
  102. })
  103. },
  104. // 获取分组
  105. getGroup(params) {
  106. if (params) {
  107. this.$api
  108. .post(this.apis[this.option.apiType || 'default'].getGroupUrl, params)
  109. .then(res => {
  110. this.accessoriesList = res.data
  111. })
  112. .catch(() => {
  113. this.accessoriesList = []
  114. })
  115. } else {
  116. this.accessoriesList = []
  117. }
  118. },
  119. // 获取配件
  120. getStock() {
  121. if (this.accessoriesList.length && this.accessoriesList[this.accessoriesIndex]) {
  122. this.$api
  123. .post(this.apis[this.option.apiType || 'default'].getStockUrl, {
  124. ...this.accessoriesParams,
  125. materialGroupId: this.accessoriesList[this.accessoriesIndex].id,
  126. partsName: this.partsName
  127. })
  128. .then(res => {
  129. this.list = res.data
  130. })
  131. .catch(() => {
  132. this.list = []
  133. })
  134. } else {
  135. this.list = []
  136. }
  137. },
  138. // 搜索按钮
  139. search(val) {
  140. this.partsName = val
  141. },
  142. // 监听下拉选项
  143. bindPickerChange(e) {
  144. this.index = e.detail.value
  145. },
  146. // 滚动到底部
  147. carScrolltolower(e) {},
  148. // 触发下拉刷新
  149. carRefresherrefresh(e) {
  150. this.refresherTriggered = true
  151. setTimeout(() => {
  152. this.refresherTriggered = false
  153. }, 3000)
  154. },
  155. // 下拉刷新结束
  156. carRefresherrestore(e) {},
  157. // 点击购买配件
  158. buyAccessories() {}
  159. }
  160. }