product.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. import axios from '~/plugins/axios'
  2. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  3. function saveStores ({ commit }, params = {}) {
  4. commit('common/REQUEST_COLLECTLIST')
  5. return axios.get(`/trade/collection/list`, { params })
  6. .then(response => {
  7. commit('common/GET_COLLECTLIST_SUCCESS', response.data)
  8. }, err => {
  9. commit('common/GET_COLLECTLIST_FAILURE', err)
  10. })
  11. }
  12. export const actions = {
  13. // 全局服务初始化
  14. nuxtServerInit (store, { params, route, req }) {
  15. // 检查设备类型
  16. const userAgent = process.server ? req.headers['user-agent'] : navigator.userAgent
  17. const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  18. store.commit('option/SET_MOBILE_LAYOUT', isMobile)
  19. store.commit('option/SET_USER_AGENT', userAgent)
  20. return Promise.all([
  21. // 全局数据
  22. // store.dispatch('loadUserInfo')
  23. ])
  24. },
  25. // 品牌列表推荐品牌配置
  26. loadRecommends ({ commit }) {
  27. commit('brand/REQUEST_RECOMMENDS')
  28. return axios.get('/cmsApi?method=queryContentPage&module=brandCenter_brandReco&orderBy=contExp_sort')
  29. .then(response => {
  30. commit('brand/GET_RECOMMENDS_SUCCESS', response.data)
  31. }, err => {
  32. commit('brand/GET_RECOMMENDS_FAILURE', err)
  33. })
  34. },
  35. // 品牌列表推荐品牌配置
  36. loadPCBRecommends ({ commit }) {
  37. commit('brand/REQUEST_RECOMMENDS')
  38. return axios.get('/cmsApi?method=queryContentPage&module=brandCenter_brandReco')
  39. .then(response => {
  40. commit('brand/GET_RECOMMENDS_SUCCESS', response.data)
  41. }, err => {
  42. commit('brand/GET_RECOMMENDS_FAILURE', err)
  43. })
  44. },
  45. // 品牌列表配置
  46. loadBrands ({ commit }, params = {}) {
  47. let keyword = params.keyword
  48. commit('brand/REQUEST_BRANDS', params)
  49. return axios.get(`/api/product/brand/initial/${keyword}`)
  50. .then(response => {
  51. commit('brand/GET_BRANDS_SUCCESS', response.data)
  52. }, err => {
  53. commit('brand/GET_BRANDS_FAILURE', err)
  54. })
  55. },
  56. // 品牌列表分页查询(索引)
  57. loadBrandsPager ({ commit }, params = {}) {
  58. commit('brand/REQUEST_BRANDS_PAGER', params)
  59. return axios.get(`/api/product/brand/page/initial`, {params: params})
  60. .then(response => {
  61. commit('brand/GET_BRANDS_PAGER_SUCCESS', response.data)
  62. }, err => {
  63. commit('brand/GET_BRANDS_PAGER_FAILURE', err)
  64. })
  65. },
  66. // 品牌列表分页查询(搜索)
  67. loadBrandsPagerWithoutIndex ({ commit }, params = {}) {
  68. commit('brand/REQUEST_BRANDS_PAGER', params)
  69. return axios.get(`/api/product/brand/Brand/ByPage`, {params: params})
  70. .then(response => {
  71. commit('brand/GET_BRANDS_PAGER_SUCCESS', response.data)
  72. }, err => {
  73. commit('brand/GET_BRANDS_PAGER_FAILURE', err)
  74. })
  75. },
  76. // 获取全部子器件类目
  77. loadAllProductKinds ({ commit }, params = {}) {
  78. let id = params.id
  79. commit('kind/REQUEST_KIND', params)
  80. return axios.get(`/api/product/kind/${id}/children_all`)
  81. .then(response => {
  82. commit('kind/GET_KIND_SUCCESS', { id, result: response.data })
  83. }, err => {
  84. commit('kind/GET_KIND_FAILURE', {id, err})
  85. })
  86. },
  87. loadKindParentsWithBothers ({ commit }, params = {}) {
  88. let id = params.id
  89. commit('kind/REQUEST_KINDPARENTSWITHBOTHERS', params)
  90. return axios.get(`/api/product/kind/${id}/parentsWithBothers`)
  91. .then(response => {
  92. commit('kind/GET_KINDPARENTSWITHBOTHERS_SUCCESS', response.data)
  93. // if (response.data) {
  94. // if (!response.data[response.data.length - 1].leaf) {
  95. // // commit('kind/REQUEST_CHILDREN')
  96. // // return axios.get(`/api/product/kind/${id}/children`)
  97. // // .then(response => {
  98. // // commit('kind/GET_CHILDREN_SUCCESS', response.data)
  99. // // }, err => {
  100. // // commit('kind/GET_CHILDREN_FAILURE', err)
  101. // // })
  102. // } else {
  103. // // commit('kind/REQUEST_KINDPROPERTY')
  104. // // return axios.get(`/api/product/kind/${id}/properties/values`)
  105. // // .then(response => {
  106. // // commit('kind/GET_KINDPROPERTY_SUCCESS', response.data)
  107. // // }, err => {
  108. // // commit('kind/GET_KINDPROPERTY_FAILURE', err)
  109. // // })
  110. // }
  111. // }
  112. }, err => {
  113. commit('kind/GET_KINDPARENTSWITHBOTHERS_FAILURE', err)
  114. })
  115. },
  116. loadKindFirstChild ({ commit }, params = {}) {
  117. let id = params.id
  118. commit('kind/REQUEST_KINDFIRSTCHILD', params)
  119. return axios.get(`/api/product/kind/${id}/children`)
  120. .then(response => {
  121. commit('kind/GET_KINDFIRSTCHILD_SUCCESS', response.data)
  122. }, err => {
  123. commit('kind/GET_KINDFIRSTCHILD_FAILURE', err)
  124. })
  125. },
  126. loadKindBrands ({ commit }, params = {}) {
  127. let id = params.id
  128. commit('kind/REQUEST_KINDBRANDS')
  129. return axios.get(`/api/product/kind/${id}/brands`)
  130. .then(response => {
  131. commit('kind/GET_KINDBRANDS_SUCCESS', response.data)
  132. }, err => {
  133. commit('kind/GET_KINDBRANDS_FAILURE', err)
  134. })
  135. },
  136. pageComGoods ({ commit }, kindid = '', brandid = '', pageParams = { page: 1, count: 10 }) {
  137. let params = {}
  138. let filter = {kindid: kindid.kindid, brandid: kindid.brandid, properties: kindid.properties}
  139. params.filter = filter
  140. params.page = pageParams.page
  141. params.count = pageParams.count
  142. commit('component/REQUEST_CMPGOODS')
  143. return axios.get('/api/product/product/getCompGoodsByKindid', { params })
  144. .then(response => {
  145. commit('component/GET_CMPGOODS_SUCCESS', response.data)
  146. }, err => {
  147. commit('component/GET_CMPGOODS_FAILURE', err)
  148. })
  149. },
  150. // 保存单个收藏记录
  151. saveEntity ({ commit }, componentid) {
  152. commit('common/REQUEST_COLLECTSAVA')
  153. return axios.post(`/trade/collection/save`, componentid)
  154. .then(response => {
  155. commit('common/GET_COLLECTSAVA_SUCCESS', response.data)
  156. if (response.data === 'success') {
  157. commit('common/GET_COLLECTLIST_SUCCESS')
  158. return Promise.all([
  159. saveStores({ commit })
  160. ])
  161. }
  162. }, err => {
  163. commit('common/GET_COLLECTSAVA_FAILURE', err)
  164. })
  165. },
  166. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  167. saveStores ({ commit }, params = {}) {
  168. commit('common/REQUEST_COLLECTLIST')
  169. return axios.get(`/trade/collection/list`, { params })
  170. .then(response => {
  171. commit('common/GET_COLLECTLIST_SUCCESS', response.data)
  172. }, err => {
  173. commit('common/GET_COLLECTLIST_FAILURE', err)
  174. })
  175. },
  176. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  177. getCollectList ({ commit }, params = {}) {
  178. commit('common/REQUEST_COLLECT_LIST')
  179. return axios.get(`/trade/collection/list`, { params })
  180. .then(response => {
  181. commit('common/GET_COLLECT_LIST_SUCCESS', response.data)
  182. }, err => {
  183. commit('common/GET_COLLECT_LIST_FAILURE', err)
  184. })
  185. },
  186. // 获取搜索所有物料信息
  187. loadPublishList ({ commit }, params = {}) {
  188. commit('common/REQUEST_PUBLISH_MOBILE')
  189. return axios.get(`/api/product/search/page`, { params })
  190. .then(response => {
  191. commit('common/GET_PUBLISH_MOBILE_SUCCESS', response.data)
  192. }, err => {
  193. commit('common/GET_PUBLISH_MOBILE_FAILURE', err)
  194. })
  195. },
  196. // 供应商维护
  197. loadSupplierInformation ({ commit }, params = {}) {
  198. let uuid = params.uuid
  199. let param = {
  200. page: params.page,
  201. count: params.count
  202. }
  203. commit('supplierInformation/REQUEST_INFORMATION')
  204. return axios.get(`/api/produce/vendorlist/${uuid}`, {params: param})
  205. .then(response => {
  206. commit('supplierInformation/GET_INFORMATION_SUCCESS', response.data)
  207. }, err => {
  208. commit('supplierInformation/GET_INFORMATION_FAILURE', err)
  209. })
  210. },
  211. // 获取用户器件收藏数据
  212. loadCompCollectInfo({ commit }) {
  213. commit('component/REQUEST_COLLECT')
  214. return axios.get('/trade/collection/count', { params: {type: 'component'} })
  215. .then(response => {
  216. commit('component/REQUEST_COLLECT_SUCCESS', response.data)
  217. }, err => {
  218. commit('component/REQUEST_COLLECT_FAILURE', err)
  219. })
  220. },
  221. // 获取用户收藏类目数据
  222. getUserCollectCode({ commit }, params = {}) {
  223. commit('component/REQUEST_COLLECTCODE')
  224. return axios.get('/produce/kindConcern/kindList', { params: params })
  225. .then(response => {
  226. commit('component/REQUEST_COLLECTCODE_SUCCESS', response.data)
  227. }, err => {
  228. commit('component/REQUEST_COLLECTCODE_FAILURE', err)
  229. })
  230. },
  231. // 修改当前选择的对象,是否已关注
  232. UpdateCollectCode({commit}, params = {}) {
  233. commit('component/UpdateOne_PRODUCTINFO', {key: params.key, status: params.status})
  234. },
  235. // 获取出入库所有记录数据
  236. getLoadStorageData({commit}, params = {}) {
  237. commit('storage/REQUEST_LIST')
  238. return axios.get('/CommodityInOutbound/page', {params: params})
  239. .then(res => {
  240. commit('storage/GET_LIST_SUCCESS', res.data)
  241. }, err => {
  242. commit('storage/GET_LIST_FAILURE', err)
  243. })
  244. },
  245. // 获取出入库单条记录数据
  246. getLoadStorageId({commit}, params = {}) {
  247. commit('storage/REQUEST_DETAIL')
  248. return axios.get('/CommodityInOutbound/id', {params: params})
  249. .then(res => {
  250. commit('storage/GET_DETAIL_SUCCESS', res.data.data)
  251. }, err => {
  252. commit('storage/GET_DETAIL_FAILURE', err)
  253. })
  254. },
  255. // 获取采购入库所有记录数据
  256. getLoadEnterpriseData({commit}, params = {}) {
  257. commit('storage/REQUEST_LIST')
  258. return axios.get('/trade/invoice/enterprise/inbound', {params: params})
  259. .then(res => {
  260. commit('storage/GET_LIST_SUCCESS', res.data)
  261. }, err => {
  262. commit('storage/GET_LIST_FAILURE', err)
  263. })
  264. },
  265. // 获取采购入库单条记录数据
  266. getLoadEnterpriseId({commit}, params = {}) {
  267. commit('storage/REQUEST_DETAIL')
  268. return axios.get(`/trade/invoice/${params.id}/find`)
  269. .then(res => {
  270. commit('storage/GET_DETAIL_SUCCESS', res.data)
  271. }, err => {
  272. commit('storage/GET_DETAIL_FAILURE', err)
  273. })
  274. },
  275. // 获取销售出库所有记录数据
  276. getLoadPurchaseData({commit}, params = {}) {
  277. commit('storage/REQUEST_LIST')
  278. return axios.get('/trade/purchase/status/createtime', {params: params})
  279. .then(res => {
  280. commit('storage/GET_LIST_SUCCESS', res.data)
  281. }, err => {
  282. commit('storage/GET_LIST_FAILURE', err)
  283. })
  284. },
  285. // 获取销售出库单条记录数据
  286. getLoadPurchaseId({commit}, params = {}) {
  287. commit('storage/REQUEST_DETAIL')
  288. return axios.get('/trade/purchase/purchaseId/' + params.id)
  289. .then(res => {
  290. commit('storage/GET_DETAIL_SUCCESS', res.data.data)
  291. }, err => {
  292. commit('storage/GET_DETAIL_FAILURE', err)
  293. })
  294. },
  295. // 获取销售出库物流信息
  296. getLoadLogistics({commit}, params = {}) {
  297. commit('storage/REQUEST_LOGISTICS')
  298. return axios.get('/trade/distributor/selected', { params })
  299. .then(res => {
  300. commit('storage/GET_LOGISTICS_SUCCESS', res.data)
  301. }, err => {
  302. commit('storage/GET_LOGISTICS_FAILURE', err)
  303. })
  304. }
  305. }