spec.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div id="spec">
  3. <template v-if="view === 'list'">
  4. <el-row>
  5. <el-col :span="24" class="btn">
  6. <el-col :span="2">
  7. <el-button size="mini" type="primary" @click="toBack()">返回</el-button>
  8. </el-col>
  9. <el-col :span="20">
  10. <el-breadcrumb separator-class="el-icon-arrow-right">
  11. <el-breadcrumb-item v-for="(item, index) in data" :key="index">{{ item.name }}</el-breadcrumb-item>
  12. </el-breadcrumb>
  13. </el-col>
  14. </el-col>
  15. </el-row>
  16. <data-search :fields="searchFields" v-model="searchInfo" @query="search">
  17. <template #status>
  18. <el-option v-for="i in statusList" :key="i.model" :label="i.label" :value="i.value"></el-option>
  19. </template>
  20. </data-search>
  21. <data-btn :fields="btnFields" @add="toAdd" />
  22. <data-table ref="dataTable" :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @delete="toDelete" @query="search" @copy="toCopy">
  23. <template #code="{ row, item }">
  24. <el-link type="primary" @click="toData(row)">{{ row[item.model] }}</el-link>
  25. </template>
  26. </data-table>
  27. </template>
  28. <template v-else>
  29. <el-row>
  30. <el-col :span="24">
  31. <el-button type="primary" size="mini" @click="toBackList()">返回</el-button>
  32. </el-col>
  33. <el-col :span="24">
  34. <data-form :span="12" :fields="infoFields" :rules="rules" v-model="form" labelWidth="150px" @save="toSave">
  35. <template #status>
  36. <el-option v-for="i in statusList" :key="i.model" :label="i.label" :value="i.value"></el-option>
  37. </template>
  38. <template #can_group>
  39. <el-option v-for="i in tfList" :key="i.model" :label="i.label" :value="i.value"></el-option>
  40. </template>
  41. </data-form>
  42. </el-col>
  43. </el-row>
  44. </template>
  45. </div>
  46. </template>
  47. <script>
  48. // 找到该商品下的规格定义
  49. const _ = require('lodash');
  50. import methodUtil from '@/util/opera';
  51. import { mapState, createNamespacedHelpers } from 'vuex';
  52. const { mapActions } = createNamespacedHelpers('goodsSpec');
  53. const { mapActions: goods } = createNamespacedHelpers('goods');
  54. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  55. export default {
  56. name: 'spec',
  57. props: {},
  58. components: {},
  59. data: function () {
  60. return {
  61. view: 'list',
  62. fields: [
  63. { label: '规格名称', model: 'name' },
  64. { label: '库存', model: 'num' },
  65. { label: '实际销售价格', model: 'sell_money' },
  66. { label: '划掉销售价格', model: 'flow_money' },
  67. { label: '运费', model: 'freight' },
  68. { label: '状态', model: 'status', format: (i) => (i === '0' ? '使用中' : '已禁用') },
  69. {
  70. label: '是否可以团购',
  71. model: 'can_group',
  72. format: (i) => {
  73. let data = this.tfList.find((f) => f.value == i);
  74. if (data) return data.label;
  75. else return '暂无';
  76. },
  77. },
  78. { label: '团购金额', model: 'group_config.money' },
  79. { label: '开团人数', model: 'group_config.need_person' },
  80. ],
  81. opera: [
  82. { label: '修改', method: 'edit' },
  83. { label: '复制', method: 'copy' },
  84. { label: '删除', method: 'delete', confirm: true, type: 'danger' },
  85. ],
  86. list: [],
  87. total: 0,
  88. limit: 10,
  89. btnFields: [{ label: '添加', method: 'add' }],
  90. defaultSearch: {},
  91. searchInfo: {},
  92. searchFields: [
  93. { label: '规格名称', model: 'name' },
  94. { label: '状态', model: 'status', type: 'select' },
  95. ],
  96. infoFields: [
  97. { label: '规格名称', model: 'name' },
  98. { label: '库存', model: 'num', type: 'number' },
  99. { label: '实际销售价格', model: 'sell_money', type: 'number' },
  100. { label: '划掉销售价格', model: 'flow_money', type: 'number' },
  101. { label: '运费', model: 'freight', type: 'number' },
  102. { label: '状态', model: 'status', type: 'select' },
  103. { label: '是否可以团购', model: 'can_group', type: 'select' },
  104. { label: '团购金额', model: 'money', type: 'number' },
  105. { label: '开团人数', model: 'need_person', type: 'number' },
  106. { label: '图片', model: 'file', type: 'upload', url: '/files/point/goodsSpec/upload' },
  107. ],
  108. rules: {
  109. freight: [{ required: true, message: '请输入运费', trigger: 'blur' }],
  110. },
  111. form: {},
  112. // 状态
  113. statusList: [],
  114. // 是否可以团购
  115. tfList: [],
  116. // 面包屑
  117. data: [],
  118. };
  119. },
  120. computed: {
  121. ...mapState(['user']),
  122. goods() {
  123. return this.$route.params.id;
  124. },
  125. },
  126. created() {
  127. this.defaultSearch.goods = this.goods;
  128. this.searchOthers();
  129. this.search();
  130. this.toData();
  131. },
  132. methods: {
  133. ...dictData({ getDict: 'query' }),
  134. ...mapActions(['query', 'fetch', 'update', 'delete', 'create']),
  135. ...goods({ goodsFetch: 'fetch' }),
  136. ...methodUtil,
  137. // 添加自定义
  138. initAddData() {
  139. const obj = { goods: this.goods, status: '0', can_group: '1', freight: 0 };
  140. this.$set(this, 'form', obj);
  141. },
  142. // 面包屑
  143. async toData(row) {
  144. let data = this.data;
  145. let res = await this.goodsFetch(this.goods);
  146. if (this.$checkRes(res)) {
  147. data.push(res.data);
  148. }
  149. this.search();
  150. },
  151. // 复制
  152. async toCopy({ data }) {
  153. this.$confirm('是否确认复制该商品?', '提示', {
  154. confirmButtonText: '确定',
  155. cancelButtonText: '取消',
  156. type: 'warning',
  157. }).then(async () => {
  158. data.name = data.name + '-复制';
  159. delete data.id;
  160. delete data._id;
  161. delete data.meta;
  162. delete data.__v;
  163. let res;
  164. res = await this.create(data);
  165. if (this.$checkRes(res)) {
  166. this.$message({ type: `success`, message: `复制成功` });
  167. this.search();
  168. this.toBackList();
  169. }
  170. });
  171. },
  172. // 保存
  173. async toSave({ data }) {
  174. let group_config = {};
  175. group_config.money = data.money;
  176. group_config.need_person = data.need_person;
  177. data.group_config = group_config;
  178. let res;
  179. if (data.id) res = await this.update(data);
  180. else res = await this.create(data);
  181. if (this.$checkRes(res)) {
  182. this.$message({ type: `success`, message: `维护信息成功` });
  183. this.search();
  184. this.toBackList();
  185. }
  186. },
  187. // 修改
  188. async toEdit({ data }) {
  189. const res = await this.fetch(data._id);
  190. if (this.$checkRes(res)) {
  191. let data = res.data;
  192. const group_config = _.get(data, 'group_config', {});
  193. data = { ...data, ...group_config };
  194. delete data.group_config;
  195. this.$set(this, `form`, data);
  196. this.view = 'info';
  197. } else {
  198. this.$message.error('未找到指定数据');
  199. }
  200. },
  201. // 返回
  202. toBack() {
  203. this.data.pop();
  204. window.history.go('-1');
  205. },
  206. // 返回列表
  207. toBackList() {
  208. this.view = 'list';
  209. this.form = {};
  210. },
  211. // 查询其他信息
  212. async searchOthers() {
  213. // 状态
  214. let res = await this.getDict({ code: 'status' });
  215. if (this.$checkRes(res)) this.$set(this, 'statusList', res.data);
  216. // 是否可以团购
  217. res = await this.getDict({ code: 'tf' });
  218. if (this.$checkRes(res)) this.$set(this, 'tfList', res.data);
  219. },
  220. },
  221. metaInfo() {
  222. return { title: this.$route.meta.title };
  223. },
  224. };
  225. </script>
  226. <style lang="less" scoped>
  227. .btn {
  228. margin: 10px 10px 20px 10px;
  229. .el-breadcrumb {
  230. font-size: 16px;
  231. line-height: 30px;
  232. }
  233. }
  234. </style>