spec.vue 8.0 KB

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