Order.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <div class="order">
  3. <z-title title="点餐项目设置" ref="title"></z-title>
  4. <el-card class="content1" ref="search">
  5. <div class="flex-n fac fjb">
  6. <div class=" flex-n fac">
  7. <el-input
  8. size="medium"
  9. class="ele-input mr-10"
  10. maxlength="16"
  11. placeholder="输入所属分类"
  12. title="输入所属分类"
  13. clearable
  14. prefix-icon="el-icon-search"
  15. v-model="foodTypeName">
  16. </el-input>
  17. <el-input
  18. size="medium"
  19. class="ele-input mr-10"
  20. maxlength="16"
  21. clearable
  22. placeholder="输入菜品名称"
  23. title="输入菜品名称"
  24. prefix-icon="el-icon-search"
  25. v-model="foodName">
  26. </el-input>
  27. </div>
  28. <div class="flex-n fac">
  29. <el-button type="primary" class="ele-btn1" @click="addFood">新增菜品</el-button>
  30. <el-upload
  31. class="upload-demo"
  32. ref="fileUpload"
  33. action="#"
  34. :http-request="httpRequest"
  35. accept=".xlsx,.xls"
  36. :show-file-list="false"
  37. >
  38. <el-button type="primary" class="ele-btn1 ml-10 mr-10" >导入菜品</el-button>
  39. </el-upload>
  40. <el-button type="primary" class="ele-btn1" @click="editFenlei">编辑分类</el-button>
  41. <el-button type="primary" class="ele-btn2" @click="searchFood">查询</el-button>
  42. </div>
  43. </div>
  44. </el-card>
  45. <el-card class="mt-10">
  46. <el-table
  47. v-loading="loading"
  48. :height="height+'px'"
  49. highlight-current-row
  50. element-loading-text="列表刷新中"
  51. header-cell-class-name="headerrow"
  52. cell-class-name="cellclass"
  53. :data="dataList"
  54. style="width: 100%">
  55. <el-table-column
  56. fixed
  57. prop="foodName"
  58. label="菜品名称"
  59. width="150"
  60. align="center">
  61. </el-table-column>
  62. <el-table-column
  63. align="center"
  64. prop="foodTypeName"
  65. label="所属分类"
  66. min-width="150">
  67. </el-table-column>
  68. <el-table-column
  69. prop="foodPrice"
  70. label="菜品价格"
  71. min-width="150"
  72. align="center">
  73. </el-table-column>
  74. <el-table-column
  75. prop="remark"
  76. label="备 注"
  77. min-width="150"
  78. align="center">
  79. </el-table-column>
  80. <el-table-column
  81. fixed="right"
  82. label="操作"
  83. width="130"
  84. align="center">
  85. <template slot-scope="scope">
  86. <div style="margin: 5px 0">
  87. <el-button type="primary" class="ele-btn-small mr-10" @click="editFood(scope.row.id)">编辑</el-button>
  88. <el-popconfirm
  89. title="确定删除该点餐项目吗?"
  90. @confirm="delFood(scope.row.id)"
  91. >
  92. <el-button slot="reference" type="primary" class="ele-btn-small">删除</el-button>
  93. </el-popconfirm>
  94. </div>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <!--分页-->
  99. <pagination :current-page="currentPage" :page-size="pageSize" :total="total" @sizeChange="handleSizeChange"
  100. @currentChange="handleCurrentChange"></pagination>
  101. </el-card>
  102. <!--新增-->
  103. <el-dialog :visible.sync="showedit"
  104. class="ele-toast" :close-on-click-modal="false">
  105. <div slot="title" >
  106. <z-title :title="editstate+'点餐项目'"></z-title>
  107. </div>
  108. <el-form :model="dataForm" :rules="rules" ref="ruleForm" class="rulefrom">
  109. <el-form-item label="菜品名称" prop="foodName" label-width="80px">
  110. <el-input maxlength="32" v-model="dataForm.foodName" placeholder="请输入菜品名称"></el-input>
  111. </el-form-item>
  112. <el-form-item label="所属分类" prop="foodTypeCode" label-width="80px">
  113. <div class="flex-n fjb fac">
  114. <el-select v-model="dataForm.foodTypeCode" placeholder="请选择所属分类" style="width: 100%"
  115. @visible-change="visiblechange" class="mr-10">
  116. <el-option
  117. v-for="item,index in classifyList"
  118. :key="item.foodTypeCode"
  119. :label="item.foodTypeName"
  120. :value="item.foodTypeCode">
  121. </el-option>
  122. </el-select>
  123. <el-button type="primary" @click="editFenlei">编辑分类</el-button>
  124. </div>
  125. </el-form-item>
  126. <el-form-item label="是否推荐" prop="isStar" label-width="80px">
  127. <el-radio-group v-model="dataForm.isStar">
  128. <el-radio label="1">是</el-radio>
  129. <el-radio label="0">否</el-radio>
  130. </el-radio-group>
  131. </el-form-item>
  132. <el-form-item label="菜品价格" prop="foodPrice" label-width="80px">
  133. <el-input-number placeholder="请输入菜品价格" v-model="dataForm.foodPrice" :precision="2" :step="0.1"
  134. controls-position="right" :max="9999999999"></el-input-number>
  135. </el-form-item>
  136. <el-form-item label="备 注" prop="remark" label-width="80px">
  137. <el-input type="textarea" rows="6" show-word-limit v-model="dataForm.remark" resize="none"
  138. maxlength="512"></el-input>
  139. </el-form-item>
  140. <el-form-item class="mt-10 flex-n fje">
  141. <el-button type="primary" @click="submitForm('ruleForm')">保 存</el-button>
  142. <el-button @click="showedit = false">取 消</el-button>
  143. </el-form-item>
  144. </el-form>
  145. </el-dialog>
  146. <!--编辑分类-->
  147. <el-dialog :visible.sync="showfenlei" width="30%" top="20vh" :close-on-click-modal="false" class="editfenlei">
  148. <div slot="title" class="flex-n fac">
  149. <z-title title="编辑分类"></z-title>
  150. <el-button type="text" size="mini" @click="classify.typeList.push({foodTypeName:'',foodTypeCode:''})">添加</el-button>
  151. </div>
  152. <el-form :model="classify" ref="ruleForm2">
  153. <div class="tips">注意:如果分类下已经添加菜品,则删除此分类,其分类下的所有菜品也将一同删除</div>
  154. <el-form-item
  155. v-for="(item, index) in classify.typeList"
  156. label="分类名称"
  157. :key="index"
  158. :prop="'typeList.' + index + '.foodTypeName'"
  159. :rules="{required: true, message: '分类名称不能为空', trigger: 'blur'}" >
  160. <div class="flex-n fac fjb">
  161. <el-input v-model="item.foodTypeName" size="mini" class="mr-20"></el-input>
  162. <!--<el-button type="primary" v-if="index==0" @click="classify.typeList.push({foodTypeName:'',foodTypeCode:''})" class="btn flex-n fac fjc">-->
  163. <!--<i class="el-icon-plus"></i>-->
  164. <!--</el-button>-->
  165. <el-button type="primary" @click="classify.typeList.splice(index,1)" class="btn flex-n fac fjc">
  166. <i class="el-icon-minus"></i>
  167. </el-button>
  168. </div>
  169. </el-form-item>
  170. <el-form-item class="mt-10 flex-n fje">
  171. <el-button type="primary" @click="submitForm2('ruleForm2')">保 存</el-button>
  172. <el-button @click="showfenlei = false">取 消</el-button>
  173. </el-form-item>
  174. </el-form>
  175. </el-dialog>
  176. </div>
  177. </template>
  178. <script>
  179. import ZTitle from "../../components/ZTitle";
  180. import ElFormItem from "element-ui/packages/form/src/form-item";
  181. import Pagination from "../../components/pagination/pagination";
  182. export default {
  183. components: {
  184. Pagination,
  185. ElFormItem,
  186. ZTitle},
  187. name: "order",
  188. data() {
  189. return {
  190. loading: false,
  191. pageSize: 20,
  192. currentPage: 1,
  193. total: 0,
  194. height: 250,
  195. dataForm: {
  196. foodTypeCode:'',
  197. isStar:'0'
  198. },
  199. editstate: '新增',
  200. showedit: false,
  201. dataList: [],
  202. foodName: '',
  203. foodTypeName : '',
  204. id: '',
  205. showfenlei: false,
  206. classify:{
  207. typeList:[]
  208. },
  209. classifyList:[],
  210. rules: {
  211. foodName: [{required: true, message: '菜品名称不能为空', trigger: 'blur'}],
  212. foodTypeCode: [{required: true, message: '所属分类不能为空', trigger: 'blur'}]
  213. },
  214. }
  215. },
  216. watch: {
  217. showedit(newval, oldval) {
  218. if (!newval) {
  219. this.$refs.ruleForm.resetFields();
  220. this.dataForm={
  221. foodTypeCode:''
  222. };
  223. }else{
  224. if(this.editstate=='新增'){
  225. this.$set(this.dataForm,'isStar','0');
  226. }
  227. }
  228. },
  229. showfenlei(newval,oldval){
  230. if(!newval){
  231. this.$refs.ruleForm2.resetFields();
  232. this.classify={
  233. typeList:[]
  234. }
  235. }
  236. },
  237. },
  238. mounted() {
  239. setTimeout(()=>{
  240. this.height=document.body.offsetHeight -this.$refs.title.$el.offsetHeight-this.$refs.search.$el.offsetHeight - 200;
  241. console.log(this.height)
  242. },0)
  243. this.getFood();
  244. this.getClassifyList();
  245. },
  246. methods: {
  247. //查询点餐项目列表
  248. getFood() {
  249. this.loading = true;
  250. this.$axios.post('/itemsFood/itemsFoodList', {
  251. "storeId": this.$root.getStorage('storeId'),
  252. "foodName": this.foodName,
  253. "foodTypeName": this.foodTypeName,
  254. "currentPage":this.currentPage,
  255. "pageSize":this.pageSize,
  256. }).then(res => {
  257. console.log('点餐项目列表', res);
  258. this.dataList = res.data.list;
  259. this.total = res.data.total;
  260. this.loading = false;
  261. }).catch(err => {
  262. this.$message.error(err.msg);
  263. this.loading = false;
  264. })
  265. },
  266. //搜索
  267. searchFood(){
  268. this.currentPage=1;
  269. this.getFood();
  270. },
  271. getClassifyList(){
  272. this.$axios.post('/itemsFood/itemsFoodTypeListByStoreId',{
  273. "storeId": this.$root.getStorage('storeId')
  274. }).then(res=>{
  275. console.log('点餐项目下拉列表',res)
  276. this.classifyList=res.data.list;
  277. if(this.showfenlei){
  278. if(res.data.total==0){
  279. this.classify.typeList=[{foodTypeName:'',foodTypeCode:''}];
  280. }else{
  281. this.classify.typeList=[].concat(res.data.list)
  282. }
  283. }
  284. }).catch(err=>{
  285. this.$message.error(err.msg);
  286. })
  287. },
  288. //查看分类列表
  289. visiblechange(isshow) {
  290. if (isshow) {
  291. this.getClassifyList();
  292. }
  293. },
  294. editFenlei(){
  295. this.showfenlei=true;
  296. this.getClassifyList();
  297. },
  298. //添加
  299. addFood() {
  300. this.showedit = true;
  301. this.editstate = '新增'
  302. },
  303. //编辑
  304. editFood(id) {
  305. console.log('编辑',id)
  306. this.id=id;
  307. this.showedit = true;
  308. this.editstate = '编辑';
  309. this.$axios.get('/itemsFood/itemsFoodById/'+id).then(res=>{
  310. console.log(res)
  311. this.dataForm=res.data;
  312. }).catch(err=>{
  313. this.$message.error(err.msg);
  314. })
  315. },
  316. //删除
  317. delFood(id){
  318. console.log('删除',id)
  319. this.$axios.post('/itemsFood/itemsFoodDeleteByIds',id).then(res=>{
  320. this.$message.success('删除点餐项目成功!');
  321. this.getFood();
  322. }).catch(err=>{
  323. this.$message.error(err.msg);
  324. })
  325. },
  326. //添加提交
  327. addSubmit() {
  328. let {isStar, foodName, foodTypeCode, foodPrice, remark} = this.dataForm;
  329. console.log(isStar)
  330. this.$axios.post('/itemsFood/itemsFoodAdd', {
  331. "storeId": this.$root.getStorage('storeId'),
  332. "isStar": isStar,
  333. "foodName": foodName,
  334. "foodTypeCode": foodTypeCode,
  335. "foodPrice": foodPrice,
  336. "remark": remark
  337. }).then(res => {
  338. this.currentPage = 1;
  339. this.getFood();
  340. this.$message.success('新增点餐项目成功!');
  341. this.showedit = false;
  342. }).catch(err => {
  343. this.$message.error(err.msg);
  344. })
  345. },
  346. //编辑提交
  347. editSubmit() {
  348. let {isStar, foodName, foodTypeCode,foodPrice, remark} = this.dataForm;
  349. this.$axios.post('/itemsFood/itemsFoodUpdate', {
  350. "storeId": this.$root.getStorage('storeId'),
  351. "id": this.id,
  352. "isStar": isStar,
  353. "foodName": foodName,
  354. "foodTypeCode": foodTypeCode,
  355. "foodPrice": foodPrice,
  356. "remark": remark
  357. }).then(res => {
  358. this.$message.success('编辑点餐项目成功!');
  359. this.getFood();
  360. this.showedit = false;
  361. }).catch(err => {
  362. this.$message.error(err.msg);
  363. })
  364. },
  365. //验证表单
  366. submitForm(formName) {
  367. this.$refs[formName].validate((valid) => {
  368. if (valid) {
  369. if (this.editstate == '新增') {
  370. this.addSubmit();
  371. } else {
  372. this.editSubmit();
  373. }
  374. } else {
  375. this.$message.error('表单填写有误');
  376. return false;
  377. }
  378. });
  379. },
  380. //验证表单2
  381. submitForm2(formName) {
  382. this.$refs[formName].validate((valid) => {
  383. if (valid) {
  384. var typeList=[];
  385. for(var i=0;i<this.classify.typeList.length;i++ ){
  386. typeList.push({'typeName':this.classify.typeList[i].foodTypeName,'id':this.classify.typeList[i].foodTypeCode})
  387. }
  388. console.log(typeList)
  389. this.$axios.post('/itemsFoodType/itemsFoodTypeUpdate',{
  390. "storeId": this.$root.getStorage('storeId'),
  391. "typeList":typeList
  392. }).then(res=>{
  393. this.$message.success('编辑分类成功!');
  394. this.dataForm.foodTypeCode='';
  395. this.showfenlei = false;
  396. this.searchFood();
  397. }).catch(err=>{
  398. this.$message.error(err.msg);
  399. })
  400. } else {
  401. this.$message.error('表单填写有误');
  402. return false;
  403. }
  404. });
  405. },
  406. httpRequest(file) {
  407. console.log(file)
  408. var fileData=file.file;
  409. var msg = fileData.name.substring(fileData.name.lastIndexOf('.') + 1)
  410. //判断文件格式
  411. if (!(msg === 'xlsx' || msg === 'xls')) {
  412. this.$refs.fileUpload.clearFiles()
  413. this.$notify.error({
  414. title: '错误',
  415. message: '上传文件只能是 xlsx,xls格式!',
  416. duration: 2000
  417. })
  418. return
  419. }
  420. let formData = new FormData();
  421. formData.append('file', fileData);
  422. formData.append('type', 1)
  423. this.$axios.post('/importExcel/uploadFoodItemsExcel', formData).then(res => {
  424. console.log(res)
  425. this.$message.success('附件上传成功');
  426. this.searchFood();
  427. }).catch(err => {
  428. this.$message.success('附件上传失败')
  429. })
  430. },
  431. handleSizeChange(val) {
  432. this.pageSize = val;
  433. this.getFood();
  434. console.log(`每页 ${val} 条`);
  435. },
  436. handleCurrentChange(val) {
  437. this.currentPage = val;
  438. this.getFood();
  439. console.log(`当前页: ${val}`);
  440. },
  441. },
  442. }
  443. </script>
  444. <style scoped lang="scss">
  445. .order {
  446. .content1 {
  447. .textnowrap {
  448. font-size: 13px;
  449. color: #333;
  450. }
  451. .date {
  452. min-width: 100px;
  453. }
  454. }
  455. .editfenlei {
  456. padding: 0 20px !important;
  457. .tips {
  458. font-size: 12px;
  459. color: #F56C6C;
  460. }
  461. .btn {
  462. padding: 0 !important;
  463. width: 28px;
  464. min-width: 28px;
  465. height: 28px;
  466. font-size: 20px;
  467. font-weight: bold;
  468. }
  469. }
  470. }
  471. </style>