list.html 8.8 KB

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