list.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 引入样式 -->
  9. <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  10. <link rel="stylesheet" href="../../styles/common.css" />
  11. <link rel="stylesheet" href="../../styles/page.css" />
  12. </head>
  13. <body>
  14. <div class="dashboard-container" id="food-app">
  15. <div class="container">
  16. <div class="tableBar">
  17. <el-input
  18. v-model="input"
  19. placeholder="请输入菜品名称"
  20. style="width: 250px"
  21. clearable
  22. @keyup.enter.native="handleQuery"
  23. >
  24. <i
  25. slot="prefix"
  26. class="el-input__icon el-icon-search"
  27. style="cursor: pointer"
  28. @click="init"
  29. ></i>
  30. </el-input>
  31. <div class="tableLab">
  32. <span class="span-btn delBut non" @click="deleteHandle('批量', null)">批量删除</span>
  33. <span class="span-btn blueBug non" @click="statusHandle('1')">批量启售</span>
  34. <span style="border:none;" class="span-btn delBut non" @click="statusHandle('0')">批量停售</span>
  35. <el-button
  36. type="primary"
  37. @click="addFoodtype('add')"
  38. >
  39. + 新建菜品
  40. </el-button>
  41. </div>
  42. </div>
  43. <el-table
  44. :data="tableData"
  45. stripe
  46. class="tableBox"
  47. @selection-change="handleSelectionChange"
  48. >
  49. <el-table-column
  50. type="selection"
  51. width="25"
  52. ></el-table-column>
  53. <el-table-column
  54. prop="name"
  55. label="菜品名称"
  56. ></el-table-column>
  57. <el-table-column prop="image" label="图片" align="center">
  58. <template slot-scope="{ row }">
  59. <el-image style="width: auto; height: 40px; border:none;cursor: pointer;"
  60. :src="getImage(row.image)"
  61. :preview-src-list="[ `/common/download?name=${row.image}` ]" >
  62. <div slot="error" class="image-slot">
  63. <img src="../../images/noImg.png" style="width: auto; height: 40px; border:none;" >
  64. </div>
  65. </el-image>
  66. </template>
  67. </el-table-column>
  68. <el-table-column
  69. prop="categoryName"
  70. label="菜品分类"
  71. ></el-table-column>
  72. <el-table-column label="售价">
  73. <template slot-scope="scope">
  74. <span style="margin-right: 10px;">¥{{ scope.row.price/100 }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="售卖状态">
  78. <template slot-scope="scope">
  79. <span style="margin-right: 10px;">{{ scope.row.status == '0' ? '停售' : '启售' }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column
  83. prop="updateTime"
  84. label="最后操作时间"
  85. >
  86. </el-table-column>
  87. <el-table-column
  88. label="操作"
  89. width="160"
  90. align="center"
  91. >
  92. <template slot-scope="scope">
  93. <el-button
  94. type="text"
  95. size="small"
  96. class="blueBug"
  97. @click="addFoodtype(scope.row.id)"
  98. >
  99. 修改
  100. </el-button>
  101. <el-button
  102. type="text"
  103. size="small"
  104. class="blueBug"
  105. @click="statusHandle(scope.row)"
  106. >
  107. {{ scope.row.status == '0' ? '启售' : '停售' }}
  108. </el-button>
  109. <el-button
  110. type="text"
  111. size="small"
  112. class="delBut non"
  113. @click="deleteHandle('单删', scope.row.id)"
  114. >
  115. 删除
  116. </el-button>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. <el-pagination
  121. class="pageList"
  122. :page-sizes="[10, 20, 30, 40]"
  123. :page-size="pageSize"
  124. layout="total, sizes, prev, pager, next, jumper"
  125. :total="counts"
  126. @size-change="handleSizeChange"
  127. :current-page.sync="page"
  128. @current-change="handleCurrentChange"
  129. ></el-pagination>
  130. </div>
  131. </div>
  132. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  133. <script src="../../plugins/vue/vue.js"></script>
  134. <!-- 引入组件库 -->
  135. <script src="../../plugins/element-ui/index.js"></script>
  136. <!-- 引入axios -->
  137. <script src="../../plugins/axios/axios.min.js"></script>
  138. <script src="../../js/request.js"></script>
  139. <script src="../../api/food.js"></script>
  140. <script>
  141. new Vue({
  142. el: '#food-app',
  143. data() {
  144. return {
  145. input: '',
  146. counts: 0,
  147. page: 1,
  148. pageSize: 10,
  149. tableData : [],
  150. dishState : '',
  151. checkList: []
  152. }
  153. },
  154. computed: {},
  155. created() {
  156. this.init()
  157. },
  158. mounted() {
  159. },
  160. methods: {
  161. async init () {
  162. const params = {
  163. page: this.page,
  164. pageSize: this.pageSize,
  165. name: this.input ? this.input : undefined
  166. }
  167. await getDishPage(params).then(res => {
  168. if (String(res.code) === '1') {
  169. this.tableData = res.data.records || []
  170. this.counts = res.data.total
  171. }
  172. }).catch(err => {
  173. this.$message.error('请求出错了:' + err)
  174. })
  175. },
  176. getImage (image) {
  177. return `/common/download?name=${image}`
  178. },
  179. handleQuery() {
  180. this.page = 1;
  181. this.init();
  182. },
  183. // 添加
  184. addFoodtype (st) {
  185. if (st === 'add'){
  186. window.parent.menuHandle({
  187. id: '4',
  188. url: '/backend/page/food/add.html',
  189. name: '添加菜品'
  190. },true)
  191. } else {
  192. window.parent.menuHandle({
  193. id: '4',
  194. url: '/backend/page/food/add.html?id='+st,
  195. name: '修改菜品'
  196. },true)
  197. }
  198. },
  199. // 删除
  200. deleteHandle (type, id) {
  201. if (type === '批量' && id === null) {
  202. if (this.checkList.length === 0) {
  203. return this.$message.error('请选择删除对象')
  204. }
  205. }
  206. this.$confirm('确认删除该菜品, 是否继续?', '确定删除', {
  207. 'confirmButtonText': '确定',
  208. 'cancelButtonText': '取消',
  209. }).then(() => {
  210. deleteDish(type === '批量' ? this.checkList.join(',') : id).then(res => {
  211. if (res.code === 1) {
  212. this.$message.success('删除成功!')
  213. this.handleQuery()
  214. } else {
  215. this.$message.error(res.msg || '操作失败')
  216. }
  217. }).catch(err => {
  218. this.$message.error('请求出错了:' + err)
  219. })
  220. })
  221. },
  222. //状态更改
  223. statusHandle (row) {
  224. let params = {}
  225. if (typeof row === 'string' ) {
  226. if (this.checkList.length === 0) {
  227. this.$message.error('批量操作,请先勾选操作菜品!')
  228. return false
  229. }
  230. params.id = this.checkList.join(',')
  231. params.status = row
  232. } else {
  233. params.id = row.id
  234. params.status = row.status ? '0' : '1'
  235. }
  236. this.dishState = params
  237. this.$confirm('确认更改该菜品状态?', '提示', {
  238. 'confirmButtonText': '确定',
  239. 'cancelButtonText': '取消',
  240. 'type': 'warning'
  241. }).then(() => {
  242. // 起售停售---批量起售停售接口
  243. dishStatusByStatus(this.dishState).then(res => {
  244. if (res.code === 1) {
  245. this.$message.success('菜品状态已经更改成功!')
  246. this.handleQuery()
  247. } else {
  248. this.$message.error(res.msg || '操作失败')
  249. }
  250. }).catch(err => {
  251. this.$message.error('请求出错了:' + err)
  252. })
  253. })
  254. },
  255. // 全部操作
  256. handleSelectionChange (val){
  257. let checkArr = []
  258. val.forEach((n) => {
  259. checkArr.push(n.id)
  260. })
  261. this.checkList = checkArr
  262. },
  263. handleSizeChange (val) {
  264. this.pageSize = val
  265. this.init()
  266. },
  267. handleCurrentChange (val) {
  268. this.page = val
  269. this.init()
  270. }
  271. }
  272. })
  273. </script>
  274. </body>
  275. </html>