index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-input
  5. v-model="wine.query.cond"
  6. placeholder="酒名、描述"
  7. style="width: 300px;"
  8. class="filter-item"
  9. />
  10. <el-button
  11. class="filter-item"
  12. style="margin-left: 10px;"
  13. type="primary"
  14. icon="el-icon-search"
  15. @click="handleQuery"
  16. >
  17. 查询
  18. </el-button>
  19. <el-button
  20. plain
  21. class="filter-item"
  22. style="margin-left: 10px;"
  23. type="success"
  24. icon="el-icon-plus"
  25. @click="handleShowCreate"
  26. >
  27. 添加
  28. </el-button>
  29. <el-button
  30. plain
  31. class="filter-item"
  32. style="margin-left: 10px;"
  33. icon="el-icon-delete"
  34. type="danger"
  35. @click="handleBatchDelete"
  36. >
  37. 删除
  38. </el-button>
  39. </div>
  40. <el-table
  41. :key="tableKey"
  42. v-loading="wine.loading"
  43. :data="wine.list"
  44. border
  45. fit
  46. highlight-current-row
  47. style="width: 100%;"
  48. @sort-change="sortChange"
  49. @selection-change="selectionChange"
  50. >
  51. <el-table-column type="selection" width="80" align="center" :selectable="selectableList" />
  52. <el-table-column type="index" label="序号" width="80" align="center" />
  53. <el-table-column
  54. label="酒名"
  55. prop="name"
  56. align="center"
  57. width="250"
  58. />
  59. <el-table-column
  60. label="上架时间"
  61. width="200"
  62. prop="time"
  63. align="center"
  64. sortable="custom"
  65. :class-name="wine.sort.time"
  66. >
  67. <template slot-scope="{row}">
  68. <span>{{ row.time | parseTime }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. label="价格(¥分/两)"
  73. prop="price"
  74. align="center"
  75. sortable="custom"
  76. min-width="250"
  77. :class-name="wine.sort.price"
  78. />
  79. <el-table-column
  80. label="浓度(×100 度)"
  81. prop="degree"
  82. width="200"
  83. align="center"
  84. sortable="custom"
  85. :class-name="wine.sort.degree"
  86. />
  87. <el-table-column
  88. label="密度(×1000 g/ml)"
  89. width="200"
  90. prop="density"
  91. align="center"
  92. sortable="custom"
  93. :class-name="wine.sort.density"
  94. />
  95. <el-table-column
  96. label="图片"
  97. width="200"
  98. align="center"
  99. >
  100. <template #default="scope">
  101. <img style="width: 50px" :src="scope.row.picture" alt="">
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="操作" align="center" width="240" class-name="small-padding fixed-width">
  105. <template slot-scope="{row}">
  106. <el-button plain type="primary" size="mini" icon="el-icon-edit" @click="handleShowDetail(row)">
  107. 编辑
  108. </el-button>
  109. <el-button
  110. v-if="canDelete(row.id)"
  111. plain
  112. type="danger"
  113. size="mini"
  114. icon="el-icon-delete"
  115. @click="handleDeleteOne(row.id)"
  116. >
  117. 删除
  118. </el-button>
  119. </template>
  120. </el-table-column>
  121. </el-table>
  122. <pagination
  123. hide-on-single-page
  124. :total="wine.total"
  125. :page.sync="wine.query.page"
  126. :limit.sync="wine.query.limit"
  127. @pagination="getList"
  128. />
  129. <el-dialog
  130. :visible.sync="detailVisible"
  131. :title="detail.title"
  132. :close-on-click-modal="false"
  133. center
  134. />
  135. </div>
  136. </template>
  137. <script>
  138. import api from '@/api/super/config/wine'
  139. import { parseTime } from '@/utils'
  140. import Pagination from '@/components/Pagination'
  141. const InitWineId = 10100
  142. export default {
  143. name: 'WineConfig',
  144. components: { Pagination },
  145. data() {
  146. return {
  147. tableKey: 0,
  148. wine: {
  149. list: [],
  150. total: 0,
  151. loading: true,
  152. sort: {
  153. time: 'ascending',
  154. price: 'ascending',
  155. degree: 'ascending',
  156. density: 'ascending'
  157. },
  158. query: {
  159. page: 1,
  160. limit: 10,
  161. cond: ''
  162. }
  163. },
  164. batch: [],
  165. detailVisible: false,
  166. detail: {
  167. title: '',
  168. id: 0,
  169. name: '',
  170. time: new Date(),
  171. price: 0,
  172. degree: 0,
  173. density: 0,
  174. picture: '',
  175. describe: ''
  176. }
  177. }
  178. },
  179. created() {
  180. this.getList()
  181. },
  182. methods: {
  183. selectableList(row) {
  184. return row.id !== InitWineId
  185. },
  186. canDelete(id) {
  187. return id !== InitWineId
  188. },
  189. handleDeleteOne(id) {
  190. this.$confirm('此操作将删除该酒品, 是否继续?', '提示', {
  191. confirmButtonText: '确定',
  192. cancelButtonText: '取消',
  193. type: 'warning'
  194. }).then(() => {
  195. api.Delete([id]).then(() => {
  196. this.$notify({
  197. title: '成功',
  198. message: '删除酒品信息成功',
  199. type: 'success',
  200. duration: 2000
  201. })
  202. this.getList()
  203. }).catch(msg => {
  204. this.$notify({
  205. title: '失败',
  206. message: msg,
  207. type: 'error',
  208. duration: 0
  209. })
  210. })
  211. })
  212. },
  213. handleBatchDelete() {
  214. if (this.batch.length === 0) return this.$message.info('请勾选需要删除的酒品')
  215. this.$confirm('此操作将删除选中的酒品, 是否继续?', '提示', {
  216. confirmButtonText: '确定',
  217. cancelButtonText: '取消',
  218. type: 'warning'
  219. }).then(() => {
  220. api.Delete(this.batch).then(() => {
  221. this.$notify({
  222. title: '成功',
  223. message: '删除酒品信息成功',
  224. type: 'success',
  225. duration: 2000
  226. })
  227. this.getList()
  228. }).catch(msg => {
  229. this.$notify({
  230. title: '失败',
  231. message: msg,
  232. type: 'error',
  233. duration: 0
  234. })
  235. })
  236. })
  237. },
  238. handleShowDetail(row) {
  239. this.detail = Object.assign({}, row)
  240. this.detail.time = parseTime(row.time)
  241. this.detail.title = '酒品详情'
  242. this.detailVisible = true
  243. },
  244. handleShowCreate() {
  245. this.resetDetail()
  246. this.detail.title = '新增酒品'
  247. this.detailVisible = true
  248. },
  249. getList() {
  250. this.wine.loading = true
  251. api.Query(this.wine.query).then(res => {
  252. for (let i = 0; i < res.wines.length; ++i) {
  253. res.wines[i].time = new Date(res.wines[i].time)
  254. }
  255. this.wine.list = res.wines
  256. this.wine.total = res.total
  257. this.wine.loading = false
  258. })
  259. },
  260. handleQuery() {
  261. this.wine.query.page = 1
  262. this.getList()
  263. },
  264. sortChange(data) {
  265. const { prop, order } = data
  266. this.wine.sort[prop] = order
  267. const cmp = order === 'ascending' ? (a, b) => a[prop] - b[prop] : (a, b) => b[prop] - a[prop]
  268. this.wine.list.sort(cmp)
  269. },
  270. selectionChange(val) {
  271. this.batch = val.map(e => e.id)
  272. },
  273. resetDetail() {
  274. this.detail = {
  275. title: '',
  276. id: 0,
  277. name: '',
  278. time: new Date(),
  279. price: 0,
  280. degree: 0,
  281. density: 0,
  282. picture: '',
  283. describe: ''
  284. }
  285. }
  286. }
  287. }
  288. </script>
  289. <style scoped>
  290. </style>