detail.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main" v-loading="loadings" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
  5. <el-col :span="24" style="margin: 0 0 10px 0">
  6. <el-col :span="2"><el-button type="primary" size="mini" @click="toBack()">返回</el-button></el-col>
  7. </el-col>
  8. <el-col :span="24">
  9. <data-form :fields="infoFields" :rules="rules" v-model="form" labelWidth="150px" @save="toSave">
  10. <template #goods>
  11. <el-select
  12. v-model="form.goods"
  13. filterable
  14. remote
  15. reserve-keyword
  16. placeholder="请选择商品名称"
  17. :remote-method="querySearch"
  18. :loading="loading"
  19. @change="handleSelect"
  20. style="width: 100%"
  21. >
  22. <el-option v-for="item in goodsList" :key="item._id" :label="item.name" :value="item._id"> </el-option>
  23. </el-select>
  24. <p style="color: red">输入商品名称查询</p>
  25. </template>
  26. <template #spec>
  27. <el-option v-for="i in specList" :key="i._id" :label="i.name" :value="i._id"></el-option>
  28. </template>
  29. </data-form>
  30. </el-col>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. </template>
  35. <script>
  36. import { mapState, createNamespacedHelpers } from 'vuex';
  37. const { mapActions: goodsConfig } = createNamespacedHelpers('goodsConfig');
  38. const { mapActions: goods } = createNamespacedHelpers('goods');
  39. const { mapActions: goodsSpec } = createNamespacedHelpers('goodsSpec');
  40. export default {
  41. name: 'detail',
  42. props: { id: { type: String } },
  43. components: {},
  44. data: function () {
  45. return {
  46. loadings: true,
  47. // info部分
  48. infoFields: [
  49. { label: '商品名称', model: 'goods', custom: true },
  50. { label: '商品规格', model: 'spec', type: 'select' },
  51. { label: '团长价', model: 'leader_price', type: 'number' },
  52. { label: '团购价', model: 'price', type: 'number' },
  53. { label: '团长提成金额', model: 'leader_get', type: 'number' },
  54. ],
  55. rules: {
  56. goods: [{ required: true, message: '商品名称', trigger: 'change' }],
  57. spec: [{ required: true, message: '商品规格', trigger: 'change' }],
  58. leader_price: [{ required: true, message: '团长价', trigger: 'blur' }],
  59. price: [{ required: true, message: '团购价', trigger: 'blur' }],
  60. leader_get: [{ required: true, message: '团长提成金额', trigger: 'blur' }],
  61. },
  62. form: {},
  63. // 加载
  64. loading: false,
  65. // 远程搜索商品列表
  66. goodsList: [],
  67. // 规格列表
  68. specList: [],
  69. };
  70. },
  71. created() {
  72. this.search();
  73. },
  74. methods: {
  75. ...goods({ goodsQuery: 'query', goodsFetch: 'fetch' }),
  76. ...goodsSpec({ specQuery: 'query', specFetch: 'fetch' }),
  77. ...goodsConfig(['query', 'delete', 'fetch', 'update', 'create']),
  78. // 查询
  79. async search() {
  80. if (this.id) {
  81. const res = await this.fetch(this.id);
  82. if (this.$checkRes(res)) {
  83. let arr = await this.goodsFetch(res.data.goods);
  84. if (this.$checkRes(arr)) this.goodsList.push(arr.data);
  85. let aee = await this.specFetch(res.data.spec);
  86. if (this.$checkRes(aee)) this.specList.push(aee.data);
  87. this.$set(this, `form`, res.data);
  88. }
  89. } else {
  90. const obj = { shop: _.get(this.user.shop, '_id') };
  91. this.$set(this, 'form', obj);
  92. }
  93. this.loadings = false;
  94. },
  95. // 远程查询
  96. async querySearch(value) {
  97. this.loading = true;
  98. let res = await this.goodsQuery({ name: value });
  99. if (this.$checkRes(res)) this.$set(this, 'goodsList', res.data);
  100. this.loading = false;
  101. },
  102. // 选择-查询规格
  103. async handleSelect(value) {
  104. let res = await this.specQuery({ goods: value });
  105. if (this.$checkRes(res)) this.$set(this, 'specList', res.data);
  106. },
  107. // 保存
  108. async toSave({ data }) {
  109. let res;
  110. if (data._id) res = await this.update(data);
  111. else res = await this.create(data);
  112. if (this.$checkRes(res)) {
  113. this.$message({ type: `success`, message: `维护信息成功` });
  114. this.toBack();
  115. }
  116. },
  117. // 返回
  118. toBack() {
  119. this.$emit('toBack');
  120. },
  121. },
  122. computed: {
  123. ...mapState(['user']),
  124. },
  125. metaInfo() {
  126. return { title: this.$route.meta.title };
  127. },
  128. watch: {
  129. test: {
  130. deep: true,
  131. immediate: true,
  132. handler(val) {},
  133. },
  134. },
  135. };
  136. </script>
  137. <style lang="less" scoped></style>