index.vue 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div class="subPage">
  3. <div class="system-table-search">
  4. <div class="flex-h">
  5. <div class="flex-item flex-h">
  6. <el-button size="mini" type="success" @click="addGoodsSpec">新增商品规格</el-button>
  7. </div>
  8. <ul>
  9. <li>
  10. <!-- <span>选择案场:</span> -->
  11. <el-select v-model="CaseId" placeholder="请选择">
  12. <el-option
  13. key="all"
  14. label="所有案场"
  15. value="all">
  16. </el-option>
  17. <el-option
  18. v-for="item in cases"
  19. :key="item.CaseId"
  20. :label="item.CaseName"
  21. :value="item.CaseId">
  22. </el-option>
  23. </el-select>
  24. </li>
  25. </ul>
  26. <el-button
  27. size="mini"
  28. type="primary" @click="search">搜索</el-button>
  29. </div>
  30. <div class="moreFilter"></div>
  31. </div>
  32. <div class="system-table-box">
  33. <el-table
  34. :data="currentList"
  35. stripe
  36. style="width: 100%">
  37. <el-table-column
  38. prop="SpecName"
  39. label="规格名">
  40. </el-table-column>
  41. <el-table-column
  42. label="所属案场">
  43. <template slot-scope="scope">
  44. <label>{{getCaseName(scope.row.CaseId)}}</label>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="操作">
  48. <template slot-scope="scope">
  49. <el-button
  50. size="mini"
  51. type="warning"
  52. @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  53. <el-button
  54. size="mini"
  55. type="danger"
  56. @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. </div>
  61. <el-pagination
  62. @current-change="handleCurrentChange"
  63. :current-page.sync="postData.page"
  64. :page-size="postData.pagesize"
  65. layout="prev, pager, next, jumper"
  66. :total="total">
  67. </el-pagination>
  68. </div>
  69. </template>
  70. <script>
  71. import { mapState } from 'vuex'
  72. export default {
  73. name: '',
  74. data () {
  75. return {
  76. total: 0,
  77. postData: { // 表格搜索条件
  78. CaseId: '', // 案场id
  79. page: 1, // 当前页码
  80. pagesize: 10, // 请求数据量
  81. },
  82. currentList: []
  83. }
  84. },
  85. mounted () {
  86. this.$nextTick(function () {
  87. this.getList()
  88. })
  89. },
  90. computed: {
  91. ...mapState({
  92. cases: x => x.app.cases.list,
  93. defaultCaseId: x => x.app.cases.default
  94. }),
  95. CaseId: {
  96. get () {
  97. return this.postData.CaseId || this.defaultCaseId
  98. },
  99. set (val) {
  100. this.postData.CaseId = val
  101. }
  102. }
  103. },
  104. methods: {
  105. getCaseName (caseid) {
  106. return (this.cases.filter(x => x.CaseId === caseid)[0] || {}).CaseName
  107. },
  108. search () { // 搜索
  109. this.postData.page = 1
  110. this.currentList = []
  111. this.getList()
  112. },
  113. getList () { // 获取列表
  114. this.$ajax(this.$api.goodsManager.getGoodsSpecList.url, {
  115. method: this.$api.goodsManager.getGoodsSpecList.method,
  116. queryData: { ...this.postData, caseid: this.CaseId === 'all' ? '' : this.CaseId }
  117. }).then(res => {
  118. this.currentList = res.list
  119. this.postData.page = res.page
  120. this.total = res.pagenum
  121. })
  122. },
  123. handleCurrentChange (val) { // 跳转到分页
  124. this.getList()
  125. },
  126. handleEdit (index, row) { // 编辑
  127. this.$router.push({ name: 'editGoodsSpec', query: { id: row.SpecId } })
  128. },
  129. handleDelete (index, row) { // 删除
  130. let name = '确认删除规格“' + row.SpecName + '”?'
  131. this.$confirm(name, '提示', {
  132. confirmButtonText: '确定',
  133. cancelButtonText: '取消',
  134. type: 'warning'
  135. }).then(() => {
  136. this.$ajax(this.$api.goodsManager.deleteGoodsSpec.url, {
  137. method: this.$api.goodsManager.deleteGoodsSpec.method,
  138. urlData: { id: row.SpecId }
  139. }).then(res => {
  140. this.$message({
  141. type: 'success',
  142. message: '删除成功!'
  143. })
  144. this.search()
  145. })
  146. }).catch(() => {
  147. this.$message({
  148. type: 'info',
  149. message: '已取消删除'
  150. })
  151. })
  152. },
  153. addGoodsSpec () {
  154. this.$router.push({ name: 'addGoodsSpec' })
  155. }
  156. }
  157. }
  158. </script>
  159. <!-- Add "scoped" attribute to limit CSS to this component only -->
  160. <style lang="scss" scoped>
  161. </style>