opera.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const _ = require('lodash');
  2. export default {
  3. //执行查询
  4. async search({ skip = 0, limit = this.$limit || 10, ...others } = {}) {
  5. let query = { skip, limit, ...others };
  6. if (this.searchInfo && Object.keys(this.searchInfo).length > 0) query = { ...query, ...this.searchInfo };
  7. if (this.defaultSearch && Object.keys(this.defaultSearch).length > 0) query = { ...query, ...this.defaultSearch };
  8. const res = await this.query(query);
  9. if (this.$checkRes(res)) {
  10. this.$set(this, `list`, res.data);
  11. this.$set(this, `total`, res.total);
  12. if (res.total === 0) {
  13. let arr = await this.goodsUpdate({
  14. _id: this.defaultSearch.goods,
  15. status: '0',
  16. });
  17. // console.log(arr);
  18. }
  19. }
  20. },
  21. // 去添加
  22. async toAdd() {
  23. this.form = {};
  24. this.initAddData();
  25. this.view = 'info';
  26. },
  27. // 初始化添加数据,重写用
  28. initAddData() {},
  29. // 去编辑
  30. async toEdit({ data }) {
  31. const res = await this.fetch(data._id);
  32. if (this.$checkRes(res)) {
  33. this.$set(this, `form`, res.data);
  34. this.view = 'info';
  35. } else {
  36. this.$message.error('未找到指定数据');
  37. }
  38. },
  39. // 执行删除
  40. async toDelete({ data }) {
  41. const res = await this.delete(data._id);
  42. if (this.$checkRes(res, '操作成功', '操作失败')) this.toResearch();
  43. },
  44. // 执行返回
  45. toBack() {
  46. this.form = {};
  47. this.view = 'list';
  48. },
  49. //执行保存
  50. async toSave({ data }) {
  51. const id = _.get(data, 'id', _.get(data, '_id'));
  52. let res;
  53. if (id) res = await this.update(data);
  54. else res = await this.create(data);
  55. if (this.$checkRes(res, '操作成功', '操作失败')) {
  56. this.view = 'list';
  57. this.toResearch();
  58. }
  59. },
  60. //执行再查询
  61. toResearch() {
  62. if (this.search) this.search();
  63. },
  64. };