spec.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div id="spec">
  3. <template v-if="view === 'list'">
  4. <el-row>
  5. <el-col :span="24" style="padding: 10px">
  6. <el-button icon="el-icon-back" size="mini" @click="toBack()">返回</el-button>
  7. </el-col>
  8. </el-row>
  9. <data-search :fields="searchFields" v-model="searchInfo" @query="search">
  10. <template #status>
  11. <el-option v-for="i in statusList" :key="i.model" :label="i.label" :value="i.value"></el-option>
  12. </template>
  13. </data-search>
  14. <data-btn :fields="btnFields" @add="toAdd" />
  15. <data-table ref="dataTable" :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @delete="toDelete" @query="search">
  16. <template #code="{ row, item }">
  17. <el-link type="primary" @click="toData(row)">{{ row[item.model] }}</el-link>
  18. </template>
  19. </data-table>
  20. </template>
  21. <template v-else>
  22. <el-row>
  23. <el-col :span="24">
  24. <el-button icon="el-icon-back" size="mini" @click="toBackList()">返回</el-button>
  25. </el-col>
  26. <el-col :span="24">
  27. <data-form :span="12" :fields="infoFields" :rules="rules" v-model="form" labelWidth="150px" @save="toSave">
  28. <template #status>
  29. <el-option v-for="i in statusList" :key="i.model" :label="i.label" :value="i.value"></el-option>
  30. </template>
  31. <template #can_group>
  32. <el-option v-for="i in tfList" :key="i.model" :label="i.label" :value="i.value"></el-option>
  33. </template>
  34. </data-form>
  35. </el-col>
  36. </el-row>
  37. </template>
  38. </div>
  39. </template>
  40. <script>
  41. // 找到该商品下的规格定义
  42. const _ = require('lodash');
  43. import methodUtil from '@/util/opera';
  44. import { mapState, createNamespacedHelpers } from 'vuex';
  45. const { mapActions } = createNamespacedHelpers('goodsSpec');
  46. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  47. export default {
  48. name: 'spec',
  49. props: {},
  50. components: {},
  51. data: function () {
  52. return {
  53. view: 'list',
  54. fields: [
  55. { label: '规格名称', model: 'name' },
  56. { label: '库存', model: 'num' },
  57. { label: '实际销售价格', model: 'sell_money' },
  58. { label: '划掉销售价格', model: 'flow_money' },
  59. { label: '运费', model: 'freight' },
  60. { label: '状态', model: 'status', format: (i) => (i === '0' ? '使用中' : '已禁用') },
  61. {
  62. label: '是否可以团购',
  63. model: 'can_group',
  64. format: (i) => {
  65. let data = this.tfList.find((f) => f.value == i);
  66. if (data) return data.label;
  67. else return '暂无';
  68. },
  69. },
  70. { label: '团购金额', model: 'group_config.money' },
  71. { label: '开团人数', model: 'group_config.need_person' },
  72. ],
  73. opera: [
  74. { label: '修改', method: 'edit' },
  75. { label: '删除', method: 'delete', confirm: true, type: 'danger' },
  76. ],
  77. list: [],
  78. total: 0,
  79. limit: 10,
  80. btnFields: [{ label: '添加', method: 'add' }],
  81. defaultSearch: {},
  82. searchInfo: {},
  83. searchFields: [
  84. { label: '规格名称', model: 'name' },
  85. { label: '状态', model: 'status', type: 'select' },
  86. ],
  87. infoFields: [
  88. { label: '规格名称', model: 'name' },
  89. { label: '库存', model: 'num', type: 'number' },
  90. { label: '实际销售价格', model: 'sell_money', type: 'number' },
  91. { label: '划掉销售价格', model: 'flow_money', type: 'number' },
  92. { label: '运费', model: 'freight', type: 'number' },
  93. { label: '状态', model: 'status', type: 'select' },
  94. { label: '是否可以团购', model: 'can_group', type: 'select' },
  95. { label: '团购金额', model: 'money', type: 'number' },
  96. { label: '开团人数', model: 'need_person', type: 'number' },
  97. ],
  98. rules: {},
  99. form: {},
  100. statusList: [],
  101. // 是否可以团购
  102. tfList: [],
  103. };
  104. },
  105. computed: {
  106. ...mapState(['user']),
  107. goods() {
  108. return this.$route.params.id;
  109. },
  110. },
  111. created() {
  112. this.defaultSearch.goods = this.goods;
  113. this.searchOthers();
  114. this.search();
  115. },
  116. methods: {
  117. ...dictData({ getDict: 'query' }),
  118. ...mapActions(['query', 'fetch', 'update', 'delete', 'create']),
  119. ...methodUtil,
  120. initAddData() {
  121. const obj = { goods: this.goods, status: '0', can_group: '0' };
  122. this.$set(this, 'form', obj);
  123. },
  124. async toSave({ data }) {
  125. let group_config = {};
  126. group_config.money = data.money;
  127. group_config.need_person = data.need_person;
  128. data.group_config = group_config;
  129. let res;
  130. if (data.id) res = await this.update(data);
  131. else res = await this.create(data);
  132. if (this.$checkRes(res)) {
  133. this.$message({ type: `success`, message: `维护信息成功` });
  134. this.search();
  135. this.toBackList();
  136. }
  137. },
  138. async toEdit({ data }) {
  139. const res = await this.fetch(data._id);
  140. if (this.$checkRes(res)) {
  141. let data = res.data;
  142. const group_config = _.get(data, 'group_config', {});
  143. data = { ...data, ...group_config };
  144. delete data.group_config;
  145. this.$set(this, `form`, data);
  146. this.view = 'info';
  147. } else {
  148. this.$message.error('未找到指定数据');
  149. }
  150. },
  151. toBack() {
  152. window.history.go('-1');
  153. },
  154. toBackList() {
  155. this.view = 'list';
  156. this.form = {};
  157. },
  158. async searchOthers() {
  159. // 状态
  160. let res = await this.getDict({ code: 'status' });
  161. if (this.$checkRes(res)) this.$set(this, 'statusList', res.data);
  162. // 是否可以团购
  163. res = await this.getDict({ code: 'tf' });
  164. if (this.$checkRes(res)) this.$set(this, 'tfList', res.data);
  165. },
  166. },
  167. metaInfo() {
  168. return { title: this.$route.meta.title };
  169. },
  170. };
  171. </script>
  172. <style lang="less" scoped></style>