spec.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. { label: '图片', model: 'file', type: 'upload', url: '/files/point/goodsSpec/upload' },
  98. ],
  99. rules: {
  100. freight: [{ required: true, message: '请输入运费', trigger: 'blur' }],
  101. },
  102. form: {},
  103. statusList: [],
  104. // 是否可以团购
  105. tfList: [],
  106. };
  107. },
  108. computed: {
  109. ...mapState(['user']),
  110. goods() {
  111. return this.$route.params.id;
  112. },
  113. },
  114. created() {
  115. this.defaultSearch.goods = this.goods;
  116. this.searchOthers();
  117. this.search();
  118. },
  119. methods: {
  120. ...dictData({ getDict: 'query' }),
  121. ...mapActions(['query', 'fetch', 'update', 'delete', 'create']),
  122. ...methodUtil,
  123. initAddData() {
  124. const obj = { goods: this.goods, status: '0', can_group: '1', freight: '0' };
  125. this.$set(this, 'form', obj);
  126. },
  127. async toSave({ data }) {
  128. let group_config = {};
  129. group_config.money = data.money;
  130. group_config.need_person = data.need_person;
  131. data.group_config = group_config;
  132. let res;
  133. if (data.id) res = await this.update(data);
  134. else res = await this.create(data);
  135. if (this.$checkRes(res)) {
  136. this.$message({ type: `success`, message: `维护信息成功` });
  137. this.search();
  138. this.toBackList();
  139. }
  140. },
  141. async toEdit({ data }) {
  142. const res = await this.fetch(data._id);
  143. if (this.$checkRes(res)) {
  144. let data = res.data;
  145. const group_config = _.get(data, 'group_config', {});
  146. data = { ...data, ...group_config };
  147. delete data.group_config;
  148. this.$set(this, `form`, data);
  149. this.view = 'info';
  150. } else {
  151. this.$message.error('未找到指定数据');
  152. }
  153. },
  154. toBack() {
  155. window.history.go('-1');
  156. },
  157. toBackList() {
  158. this.view = 'list';
  159. this.form = {};
  160. },
  161. async searchOthers() {
  162. // 状态
  163. let res = await this.getDict({ code: 'status' });
  164. if (this.$checkRes(res)) this.$set(this, 'statusList', res.data);
  165. // 是否可以团购
  166. res = await this.getDict({ code: 'tf' });
  167. if (this.$checkRes(res)) this.$set(this, 'tfList', res.data);
  168. },
  169. },
  170. metaInfo() {
  171. return { title: this.$route.meta.title };
  172. },
  173. };
  174. </script>
  175. <style lang="less" scoped></style>