shopCategory.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class='m-container'>
  3. <h2>商品类型管理</h2>
  4. <div class="m-core">
  5. <div class='newBand' @click="openTypes('create')">添加</div>
  6. <!-- 列表 -->
  7. <div class="tableWrap">
  8. <el-table :data='tableList'>
  9. <el-table-column align='center' prop="name"
  10. label="分类名称">
  11. </el-table-column>
  12. <el-table-column align='center'
  13. label="声部属性">
  14. <template slot-scope="scope">
  15. {{ scope.row.subjectName | joinArray(',') }}
  16. </template>
  17. </el-table-column>
  18. <el-table-column align='center'
  19. label="操作">
  20. <template slot-scope="scope">
  21. <el-button @click="openTypes('update', scope.row)" type="text">修改</el-button>
  22. <el-button @click="onTypesDel(scope.row)" type="text">删除</el-button>
  23. </template>
  24. </el-table-column>
  25. </el-table>
  26. <pagination :total="pageInfo.total"
  27. :page.sync="pageInfo.page"
  28. :limit.sync="pageInfo.limit"
  29. :page-sizes="pageInfo.page_size"
  30. @pagination="getList" />
  31. </div>
  32. </div>
  33. <el-dialog :title="formTitle[formActionTitle]" :visible.sync="typeStatus"
  34. @close="onFormClose('ruleForm')" width="500px">
  35. <el-form :model="form" :rules="rules" ref="ruleForm">
  36. <el-form-item label="商品分类名称" prop="name" :label-width="formLabelWidth">
  37. <el-input v-model="form.name" autocomplete="off"></el-input>
  38. </el-form-item>
  39. <el-form-item label="声部属性" v-if="form.classGroupType != 'MIX'"
  40. prop="subjectIds" :label-width="formLabelWidth">
  41. <el-select v-model="form.subjectIds" multiple>
  42. <el-option-group
  43. v-for="group in subjectList"
  44. :key="group.label"
  45. :label="group.label">
  46. <el-option
  47. v-for="item in group.options"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.value">
  51. </el-option>
  52. </el-option-group>
  53. </el-select>
  54. </el-form-item>
  55. </el-form>
  56. <span slot="footer"
  57. class="dialog-footer">
  58. <el-button @click="typeStatus = false">取 消</el-button>
  59. <el-button type="primary" @click="onTypesSubmit('ruleForm')">确 定</el-button>
  60. </span>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. import pagination from '@/components/Pagination/index'
  66. import store from '@/store'
  67. import { subjectListTree } from '@/api/specialSetting'
  68. import { categoryListTree, categoryUpSet, categorydel } from '@/api/businessManager'
  69. export default {
  70. components: { pagination },
  71. name: 'adminManager',
  72. data () {
  73. return {
  74. tableList: [],
  75. subjectList: [], // 声部列表
  76. formActionTitle: 'create',
  77. formTitle: {
  78. create: '添加商品分类',
  79. update: '修改商品分类'
  80. },
  81. typeStatus: false, // 添加教学点
  82. formLabelWidth: '120px',
  83. form: {
  84. name: null, // 作业模块名称
  85. subjectIds: [],
  86. organId: store.getters.organ
  87. },
  88. rules: {
  89. name: [{ required: true, message: '请输入类型名称', trigger: 'blur' }],
  90. subjectIds: [{ required: true, message: '请选择声部组合', trigger: 'change' }]
  91. },
  92. pageInfo: {
  93. // 分页规则
  94. limit: 10, // 限制显示条数
  95. page: 1, // 当前页
  96. total: 0, // 总条数
  97. page_size: [10, 20, 40, 50] // 选择限制显示条数
  98. }
  99. }
  100. },
  101. mounted() {
  102. this.getList()
  103. this.getSubjectTree()
  104. },
  105. methods: {
  106. onTypesSubmit (formName) { // 添加数据
  107. this.$refs[formName].validate((valid) => {
  108. if (valid) {
  109. if (this.formActionTitle == 'create') {
  110. if(this.form.id) { // 判断有没有Id,如果有则删除
  111. delete this.form.id
  112. }
  113. categoryUpSet(this.form).then(res => {
  114. this.messageTips('添加', res)
  115. })
  116. } else if (this.formActionTitle == 'update') {
  117. categoryUpSet(this.form).then(res => {
  118. this.messageTips('修改', res)
  119. })
  120. }
  121. } else {
  122. return false;
  123. }
  124. })
  125. },
  126. onTypesDel(row) {
  127. categoryDel(row.id).then(res => {
  128. this.messageTips('删除', res)
  129. })
  130. },
  131. messageTips(title, res) {
  132. if(res.code == 200) {
  133. this.$message({
  134. message: title + '成功',
  135. type: 'success'
  136. })
  137. this.typeStatus = false
  138. this.getList()
  139. } else {
  140. this.$message.error(res.msg)
  141. }
  142. },
  143. getList () {
  144. categoryListTree({
  145. delFlag: 0,
  146. rows: this.pageInfo.limit,
  147. page: this.pageInfo.page
  148. }).then(res => {
  149. let result = res.data
  150. if(res.code == 200) {
  151. result.rows.forEach(row => {
  152. let subjectname = [],
  153. subjectIds = []
  154. row.subjects.forEach(item => {
  155. subjectname.push(item.name)
  156. subjectIds.push(item.id)
  157. })
  158. row.subjectName = subjectname
  159. row.subjectIds = subjectIds
  160. })
  161. this.tableList = result.rows
  162. this.pageInfo.total = result.total
  163. }
  164. })
  165. },
  166. openTypes(type, row) {
  167. this.typeStatus = true
  168. this.formActionTitle = type
  169. // 修改的时候赋值
  170. if (type == 'update') {
  171. this.form = {
  172. id: row.id,
  173. name: row.name,
  174. subjectIds: row.subjectIds,
  175. organId: store.getters.organ
  176. }
  177. }
  178. },
  179. onFormClose (formName) { // 关闭弹窗重置验证
  180. this.form = {
  181. name: null, // 作业模块名称
  182. subjectIds: [],
  183. organId: store.getters.organ
  184. }
  185. this.$refs[formName].resetFields()
  186. },
  187. getSubjectTree() { // 获取声部列表
  188. subjectListTree({
  189. delFlag: 0,
  190. rows: 9999
  191. }).then(res => {
  192. let result = res.data
  193. if(res.code == 200) {
  194. let tempArray = []
  195. result.rows.forEach((item, index) => {
  196. let subject = []
  197. item.subjects.forEach(s => {
  198. subject.push({
  199. value: s.id,
  200. label: s.name
  201. })
  202. })
  203. tempArray[index] = {
  204. label: item.name,
  205. options: subject
  206. }
  207. })
  208. this.subjectList = tempArray
  209. }
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .el-input-group__append, .el-button--primary {
  217. background: #14928a;
  218. border-color: #14928a;
  219. color: #fff;
  220. &:hover, &:active, &:focus {
  221. background: #14928a;
  222. border-color: #14928a;
  223. color: #FFF;
  224. }
  225. }
  226. .el-date-editor.el-input{
  227. width: 100% !important;
  228. }
  229. .el-select {
  230. width: 98% !important;
  231. }
  232. </style>