list.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <div class="app-list-content">
  3. <x-crud class="liu-crud-wrap" @load="onLoad">
  4. <template #slot-tabs>
  5. <el-tabs
  6. class="liu-tabs"
  7. type="border-card"
  8. v-model="tabIndex"
  9. @tab-click="handleClick"
  10. >
  11. <el-tab-pane
  12. v-for="(item, index) in tabsData"
  13. :key="index"
  14. :label="item.text"
  15. :name="item.key"
  16. >
  17. </el-tab-pane>
  18. </el-tabs>
  19. </template>
  20. <template #table-column-num="{scope}">
  21. <el-link
  22. @click="getItemList(scope.row)"
  23. >{{ scope.row.num }}</el-link>
  24. </template>
  25. <template #table-column-name="{scope}">
  26. <el-link
  27. @click="getItemList(scope.row)"
  28. >{{ scope.row.name }}</el-link>
  29. </template>
  30. <template #table-column-inTurn="{scope}">
  31. <span v-if="!sort.status">{{ scope.row.inTurn }}</span>
  32. <el-input
  33. ref="sort-input"
  34. focus
  35. size="mini"
  36. v-else
  37. v-model="scope.row.inTurn"
  38. @blur="changeSort(scope.row)"
  39. ></el-input>
  40. </template>
  41. <!-- 排序 -->
  42. <template #table-header-inTurn>
  43. <div class="set-sort">
  44. <span>排序</span>
  45. <el-button
  46. v-if="!sort.status"
  47. icon="el-icon-edit-outline"
  48. size="small"
  49. type="text"
  50. @click="showSort"
  51. class="show"
  52. ></el-button>
  53. <el-button class="hide" v-else size="mini" @click="hideSort" type="primary"
  54. >完成</el-button
  55. >
  56. </div>
  57. </template>
  58. <!-- 添加分类 -->
  59. <template #slot-add-goods-btn>
  60. <el-button type="primary" size="mini" @click="replaceBtnFn(0)">添加</el-button>
  61. </template>
  62. <template #slot-item-list="{scope}">
  63. <el-button type="text" @click.native.stop="getItemList(scope.row)">花材列表</el-button>
  64. </template>
  65. <template #slot-modify="{scope}">
  66. <el-button type="text" @click.native.stop="replaceBtnFn(scope.row.id,scope.row.name)">修改</el-button>
  67. </template>
  68. </x-crud>
  69. <!-- 新增弹窗 -->
  70. <el-dialog
  71. :title="`${id == 0 ? '添加' : '修改'}花材`"
  72. :visible.sync="replaceDialog"
  73. :close-on-click-modal="false"
  74. width="600px"
  75. >
  76. <div class="ad-modal-content">
  77. <el-form :model="replaceForm" :rules="ruleForm" ref="replaceForm" label-width="100px" class="demo-form">
  78. <el-form-item label="分类名称" prop="name">
  79. <el-input v-model="replaceForm.name" placeholder="请输入名称" size="small"></el-input>
  80. </el-form-item>
  81. </el-form>
  82. </div>
  83. <div slot="footer" class="dialog-footer">
  84. <el-button size="small" @click="resetForm">取 消</el-button>
  85. <el-button type="primary" size="small" @click="submitForm('replaceForm')">确认</el-button>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. import { mapGetters } from 'vuex';
  92. export default {
  93. data() {
  94. return {
  95. app: null,
  96. sortLink: '',
  97. operateData: {},
  98. tabIndex: '0',
  99. tabsData: [
  100. {
  101. text: '花材分类',
  102. key: '0'
  103. }
  104. ],
  105. selects: {},
  106. sort: {
  107. status: false
  108. },
  109. replaceDialog:false,
  110. id:0,
  111. replaceForm: {
  112. name: ''
  113. },
  114. ruleForm: {
  115. name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  116. },
  117. };
  118. },
  119. computed: {
  120. },
  121. methods: {
  122. deleteFn(id){
  123. let self = this
  124. this.$confirm('确认删除?', '提示', {
  125. confirmButtonText: '确定',
  126. cancelButtonText: '取消',
  127. type: 'warning'
  128. }).then(() => {
  129. this.$service.itemClass.deleteClass({id:id}).then(res => {
  130. self.replaceDialog = false
  131. self.app.refresh();
  132. });
  133. });
  134. },
  135. resetForm(){
  136. this.$refs['replaceForm'].resetFields();
  137. this.replaceDialog = false
  138. },
  139. replaceFn() {
  140. let replaceForm = JSON.parse(JSON.stringify(this.replaceForm));
  141. let self = this
  142. if (self.id == 0) {
  143. this.$service.itemClass.addClass(replaceForm).then(res => {
  144. self.replaceDialog = false
  145. self.resetForm();
  146. self.app.refresh();
  147. });
  148. } else {
  149. this.$service.itemClass.updateClass({id:self.id,...replaceForm}).then(res => {
  150. self.replaceDialog = false
  151. self.resetForm();
  152. self.app.refresh();
  153. });
  154. }
  155. },
  156. submitForm(formName) {
  157. this.$refs[formName].validate(valid => {
  158. if (valid) {
  159. this.replaceFn();
  160. } else {
  161. console.log('error submit!!');
  162. return false;
  163. }
  164. });
  165. },
  166. replaceBtnFn(id,name) {
  167. this.id = id
  168. this.replaceForm.name = name
  169. this.replaceDialog = true
  170. },
  171. handleClick(tab, e) {
  172. this.app.refresh({ type: this.tabIndex });
  173. },
  174. //添加花材
  175. getItemList(data) {
  176. let query = {};
  177. query.classId = data.id
  178. query.className = data.name
  179. this.$router.push({ path: '/item/list', query });
  180. },
  181. // x-crud 组件
  182. onLoad({ ctx, app }) {
  183. this.app = app;
  184. ctx.service(this.$service.itemClass)
  185. .set('table', {
  186. columns: [
  187. {
  188. prop: 'id',
  189. label: 'ID',
  190. align: 'center'
  191. },
  192. {
  193. prop: 'name',
  194. label: '标题',
  195. align: 'center',
  196. 'min-width': 180
  197. },
  198. // {
  199. // prop: 'num',
  200. // label: '花材数量',
  201. // align: 'center',
  202. // 'min-width': 100
  203. // },
  204. {
  205. prop: 'inTurn',
  206. label: '排序',
  207. align: 'center',
  208. minWidth: 100
  209. },
  210. {
  211. prop: 'addTime',
  212. label: '创建时间',
  213. align: 'center',
  214. minWidth: 180
  215. }
  216. ],
  217. on: {
  218. 'row-click': (row, column) => {
  219. this.getItemList(row)
  220. }
  221. },
  222. op: {
  223. visible: true,
  224. props: {
  225. width: 300,
  226. align: 'center',
  227. fixed: 'right',
  228. label: '操作'
  229. },
  230. layout: ['slot-item-list','slot-modify']
  231. }
  232. })
  233. .set('dict', {
  234. search: {
  235. keyWord: 'goodsName'
  236. }
  237. })
  238. .set('search', {
  239. key: {
  240. placeholder: '分类名称'
  241. }
  242. })
  243. .set('layout', [
  244. ['slot-tabs'],
  245. ['flex1', 'slot-add-goods-btn', 'refresh-btn'],
  246. ['data-table'],
  247. ['flex1', 'pagination']
  248. ])
  249. .on('delete', (selection, { next }) => {
  250. next({
  251. id: selection.map(e => e.id).join(',')
  252. });
  253. })
  254. .done();
  255. app.refresh({ status: this.tabIndex });
  256. },
  257. refresh(params) {
  258. this.app.refresh(params);
  259. },
  260. showSort(e) {
  261. this.sort.status = true;
  262. },
  263. hideSort(e) {
  264. this.sort.status = false;
  265. },
  266. changeSort(d) {
  267. this.$service.goods
  268. .sort({
  269. inTurn: d.inTurn,
  270. id: d.id
  271. })
  272. .then(() => {
  273. this.$message.success('修改成功');
  274. this.refresh();
  275. })
  276. .catch(err => {
  277. this.$message.error(err);
  278. });
  279. }
  280. }
  281. };
  282. </script>
  283. <style lang="scss" scoped>
  284. .short-link {
  285. color: $mainColor;
  286. margin-left: 10px;
  287. cursor: pointer;
  288. }
  289. .set-sort {
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. .el-button {
  294. margin-left: 10px;
  295. }
  296. .show {
  297. font-size: 16px;
  298. }
  299. .hide {
  300. padding: 2px 5px;
  301. }
  302. }
  303. </style>