discountManage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div class='m-container'>
  3. <!-- <h2>折扣设置</h2> -->
  4. <div class="m-core">
  5. <el-form :inline="true"
  6. :model="searchForm">
  7. <el-form-item>
  8. <el-select v-model.trim="searchForm.subjectId"
  9. filterable
  10. placeholder="请选择声部组合"
  11. clearable>
  12. <el-option-group v-for="group in subjectList"
  13. :key="group.label"
  14. :label="group.label">
  15. <el-option v-for="item in group.options"
  16. :key="item.value"
  17. :label="item.label"
  18. :value="item.value">
  19. </el-option>
  20. </el-option-group>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-select v-model.trim="searchForm.chargeTypeId"
  25. filterable
  26. placeholder="请选择收费类型"
  27. clearable>
  28. <el-option v-for="item in typesList"
  29. :key="item.value"
  30. :label="item.label"
  31. :value="item.value">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="danger"
  37. @click="search">搜索</el-button>
  38. <el-button @click="onReSet"
  39. type="primary">重置</el-button>
  40. </el-form-item>
  41. </el-form>
  42. <div class='newBand'
  43. v-permission="'chargeTypeSubjectMapper/insert'"
  44. @click="createVisible = true">添加</div>
  45. <!-- 列表 -->
  46. <div class="tableWrap">
  47. <el-table :data='tableList'
  48. :header-cell-style="{background:'#EDEEF0',color:'#444'}">
  49. <el-table-column align='center'
  50. prop="chargeTypeId"
  51. label="收费类型">
  52. <template slot-scope="scope">{{ typesListById[scope.row.chargeTypeId] }}</template>
  53. </el-table-column>
  54. <el-table-column align='center'
  55. prop="subjectId"
  56. label="声部">
  57. <template slot-scope="scope">{{ subjectListById[scope.row.subjectId] }}</template>
  58. </el-table-column>
  59. <el-table-column align='center'
  60. prop="goodsDiscountRate"
  61. label="折扣(%)">
  62. </el-table-column>
  63. <el-table-column align='center'
  64. label="操作">
  65. <template slot-scope="scope">
  66. <el-button @click="openTypes('update', scope.row)"
  67. v-permission="'chargeTypeSubjectMapper/update'"
  68. type="text">修改</el-button>
  69. <el-button @click="onTypesDel(scope.row)"
  70. v-permission="'chargeTypeSubjectMapper/del'"
  71. type="text">删除</el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <pagination :total="pageInfo.total"
  76. :page.sync="pageInfo.page"
  77. :limit.sync="pageInfo.limit"
  78. :page-sizes="pageInfo.page_size"
  79. @pagination="getList" />
  80. </div>
  81. </div>
  82. <el-dialog :title="formTitle[formActionTitle]"
  83. :visible.sync="typeStatus"
  84. @close="onFormClose('ruleForm')"
  85. width="500px">
  86. <el-form :model="form"
  87. :rules="rules"
  88. ref="ruleForm">
  89. <el-form-item label="收费类型"
  90. prop="chargeTypeId"
  91. :label-width="formLabelWidth">
  92. <el-select v-model.trim="form.chargeTypeId"
  93. filterable
  94. disabled
  95. placeholder="请选择收费类型"
  96. clearable>
  97. <el-option v-for="item in typesList"
  98. :key="item.value"
  99. :label="item.label"
  100. :value="item.value">
  101. </el-option>
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="声部选择"
  105. v-if="form.classGroupType != 'MIX'"
  106. prop="subjectId"
  107. :label-width="formLabelWidth">
  108. <el-select v-model.trim="form.subjectId"
  109. filterable
  110. disabled
  111. placeholder="请选择声部组合"
  112. clearable>
  113. <el-option-group v-for="group in subjectList"
  114. :key="group.label"
  115. :label="group.label">
  116. <el-option v-for="item in group.options"
  117. :key="item.value"
  118. :label="item.label"
  119. :value="item.value">
  120. </el-option>
  121. </el-option-group>
  122. </el-select>
  123. </el-form-item>
  124. <el-form-item label="折扣(%)"
  125. prop="goodsDiscountRate"
  126. :label-width="formLabelWidth">
  127. <el-input-number v-model.trim="form.goodsDiscountRate"
  128. autocomplete="off"
  129. placeholder="请输入折扣 1%-100%"
  130. controls-position="right"
  131. class="number-input"
  132. :min="0"
  133. :max="100"
  134. :precision="2"></el-input-number>
  135. </el-form-item>
  136. </el-form>
  137. <span slot="footer"
  138. class="dialog-footer">
  139. <el-button @click="typeStatus = false">取 消</el-button>
  140. <el-button type="primary"
  141. @click="onTypesSubmit('ruleForm')">确 定</el-button>
  142. </span>
  143. </el-dialog>
  144. <el-dialog :visible.sync="createVisible"
  145. title="添加折扣商品"
  146. width="400px">
  147. <createDiscount @close="createVisible = false"
  148. :typesList="typesList"
  149. :subjectList="subjectList" />
  150. </el-dialog>
  151. </div>
  152. </template>
  153. <script>
  154. import pagination from '@/components/Pagination/index'
  155. import { chargeTypeList, subjectListTree, insertChargeTypeSubjectMapper, updateChargeTypeSubjectMapper, delChargeTypeSubjectMapper, chargeTypeSubjectMapper } from '@/api/specialSetting'
  156. import createDiscount from './modals/create-discount'
  157. export default {
  158. name: 'typesManager',
  159. components: { pagination, createDiscount },
  160. data () {
  161. return {
  162. tableList: [],
  163. typesList: [],
  164. typesListById: {},
  165. subjectList: [], // 声部列表
  166. subjectListById: {}, // 声部列表
  167. formActionTitle: 'create',
  168. formTitle: {
  169. create: '添加折扣',
  170. update: '修改折扣'
  171. },
  172. createVisible: false,
  173. typeStatus: false, // 添加教学点
  174. formLabelWidth: '100px',
  175. form: {
  176. name: null, //
  177. subjectId: null,
  178. goodsDiscountRate: null,
  179. },
  180. searchForm: {
  181. subjectId: null,
  182. chargeTypeId: null,
  183. },
  184. rules: {
  185. chargeTypeId: [{ required: true, message: '请选择收费类型', trigger: 'blur' }],
  186. subjectId: [{ required: true, message: '请选择声部组合', trigger: 'change' }],
  187. goodsDiscountRate: [{ required: true, message: '请输入折扣', trigger: 'blur' }],
  188. },
  189. pageInfo: {
  190. // 分页规则
  191. limit: 10, // 限制显示条数
  192. page: 1, // 当前页
  193. total: 0, // 总条数
  194. page_size: [10, 20, 40, 50] // 选择限制显示条数
  195. }
  196. }
  197. },
  198. mounted () {
  199. this.getList()
  200. this.getChargeTypeList()
  201. this.getSubjectTree()
  202. },
  203. methods: {
  204. search () {
  205. this.pageInfo.page = 1;
  206. this.getList();
  207. },
  208. onReSet () {
  209. this.searchForm = {
  210. subjectId: null,
  211. chargeTypeId: null,
  212. };
  213. this.search();
  214. },
  215. onTypesSubmit (formName) { // 添加数据
  216. this.$refs[formName].validate((valid) => {
  217. if (valid) {
  218. if (this.formActionTitle == 'create') {
  219. if (this.form.id) { // 判断有没有Id,如果有则删除
  220. delete this.form.id
  221. }
  222. insertChargeTypeSubjectMapper(this.form).then(res => {
  223. this.messageTips('添加', res)
  224. })
  225. } else if (this.formActionTitle == 'update') {
  226. updateChargeTypeSubjectMapper([this.form]).then(res => {
  227. this.messageTips('修改', res)
  228. })
  229. }
  230. } else {
  231. return false;
  232. }
  233. })
  234. },
  235. messageTips (title, res) {
  236. if (res.code == 200) {
  237. this.$message.success(title + '成功')
  238. this.typeStatus = false
  239. this.getList()
  240. } else {
  241. this.$message.error(res.msg)
  242. }
  243. },
  244. async onTypesDel (row) {
  245. try {
  246. await this.$confirm('是否删除此条数据?', '提示', {
  247. confirmButtonText: '确定',
  248. cancelButtonText: '取消',
  249. type: 'warning'
  250. })
  251. delChargeTypeSubjectMapper({ id: row.id }).then(res => {
  252. this.messageTips('删除', res)
  253. })
  254. } catch (error) { }
  255. },
  256. getChargeTypeList () {
  257. chargeTypeList({
  258. rows: 9999,
  259. page: 1
  260. }).then(res => {
  261. if (res.code == 200) {
  262. const typesListById = {}
  263. res.data.rows.forEach(item => {
  264. typesListById[item.id] = item.name
  265. this.typesList.push({
  266. label: item.name,
  267. value: item.id
  268. })
  269. })
  270. this.typesListById = typesListById
  271. }
  272. })
  273. },
  274. getList () {
  275. chargeTypeSubjectMapper({
  276. rows: this.pageInfo.limit,
  277. page: this.pageInfo.page,
  278. ...this.searchForm
  279. }).then(res => {
  280. let result = res.data
  281. this.tableList = result.rows
  282. // if (res.code == 200) {
  283. // result.data.rows.forEach(row => {
  284. // let subjectname = [],
  285. // subjectIds = []
  286. // row.subjects.forEach(item => {
  287. // subjectname.push(item.name)
  288. // subjectIds.push(item.id)
  289. // })
  290. // row.subjectName = subjectname
  291. // row.subjectIds = subjectIds
  292. // })
  293. // this.tableList = result.rows
  294. this.pageInfo.total = result.total
  295. // }
  296. })
  297. },
  298. openTypes (type, row) {
  299. this.typeStatus = true
  300. this.formActionTitle = type
  301. // 修改的时候赋值
  302. if (type == 'update') {
  303. this.form = {
  304. id: row.id,
  305. chargeTypeId: row.chargeTypeId,
  306. subjectId: row.subjectId,
  307. goodsDiscountRate: row.goodsDiscountRate,
  308. }
  309. }
  310. },
  311. onFormClose (formName) { // 关闭弹窗重置验证
  312. this.form = {
  313. name: null, // 作业模块名称
  314. subjectId: null,
  315. goodsDiscountRate: null,
  316. }
  317. this.$refs[formName].resetFields()
  318. },
  319. getSubjectTree () { // 获取声部列表
  320. subjectListTree({
  321. delFlag: 0,
  322. rows: 9999
  323. }).then(res => {
  324. const subjectListById = {}
  325. let result = res.data
  326. if (res.code == 200) {
  327. let tempArray = []
  328. result.rows.forEach((item, index) => {
  329. let subject = []
  330. if (item.subjects) {
  331. item.subjects.forEach(s => {
  332. subjectListById[s.id] = s.name
  333. subject.push({
  334. value: s.id,
  335. label: s.name
  336. })
  337. })
  338. }
  339. tempArray[index] = {
  340. label: item.name,
  341. options: subject
  342. }
  343. })
  344. this.subjectListById = subjectListById
  345. this.subjectList = tempArray
  346. }
  347. })
  348. }
  349. }
  350. }
  351. </script>
  352. <style lang="scss" scoped>
  353. .el-button--primary {
  354. background: #14928a;
  355. border-color: #14928a;
  356. color: #fff;
  357. &:hover,
  358. &:active,
  359. &:focus {
  360. background: #14928a;
  361. border-color: #14928a;
  362. color: #fff;
  363. }
  364. }
  365. /deep/.el-date-editor.el-input {
  366. width: 100% !important;
  367. }
  368. .el-select {
  369. width: 100% !important;
  370. }
  371. .number-input {
  372. /deep/ .el-input__inner {
  373. text-align: left;
  374. }
  375. width: 100%;
  376. }
  377. </style>