posTasteForm.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  5. <a-row>
  6. <a-col :span="24">
  7. <a-form-model-item label="口味名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  8. <a-input v-model="model.name" placeholder="请输入口味名称"></a-input>
  9. </a-form-model-item>
  10. </a-col>
  11. <a-col :span="24">
  12. <a-form-model-item label="加价金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="money">
  13. <a-input-number v-model="model.money" placeholder="请输入加价金额" style="width: 100%" />
  14. </a-form-model-item>
  15. </a-col>
  16. <a-col :span="24">
  17. <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="">
  18. <a-input v-model="model.remark" placeholder="请输入备注"></a-input>
  19. </a-form-model-item>
  20. </a-col>
  21. <a-col :span="24">
  22. <a-form-model-item label="是否开启" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
  23. <a-switch v-model="model.state" checked-children="启用" un-checked-children="禁用" />
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :span="24">
  27. <a-form-model-item label="应用范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
  28. <a-radio-group :options="options" v-model="model.type" @change="onChange" />
  29. </a-form-model-item>
  30. </a-col>
  31. </a-row>
  32. <a-col :span="24" v-if="model.type==1">
  33. <a-button @click="handleAddClass" type="primary" icon="plus">选择分类</a-button>
  34. <a-table :columns="columnsTwo" :data-source="model.detailListClass || []" :pagination="false" rowKey="id">
  35. <template slot="num" slot-scope="text, record, index">
  36. <div>
  37. <a-input-number v-model="record.num" :min="1" :max="99" />
  38. </div>
  39. </template>
  40. <template slot="required" slot-scope="text, record, index">
  41. <div>
  42. <a-switch v-model="record.required" />
  43. </div>
  44. </template>
  45. <span slot="action" slot-scope="text, record, index">
  46. <a @click="handleDeleteClass(index)">删除</a>
  47. </span>
  48. </a-table>
  49. </a-col>
  50. <a-col :span="24" v-if="model.type==2">
  51. <a-button @click="handleAdd" type="primary" icon="plus">选择商品</a-button>
  52. <a-table :columns="columns" :data-source="model.detailList || []" :pagination="false" rowKey="id">
  53. <template slot="num" slot-scope="text, record, index">
  54. <div>
  55. <a-input-number v-model="record.num" :min="1" :max="99" />
  56. </div>
  57. </template>
  58. <template slot="required" slot-scope="text, record, index">
  59. <div>
  60. <a-switch v-model="record.required" />
  61. </div>
  62. </template>
  63. <span slot="action" slot-scope="text, record, index">
  64. <a @click="handleDelete(index)">删除</a>
  65. </span>
  66. </a-table>
  67. </a-col>
  68. </a-form-model>
  69. </j-form-container>
  70. <select-goods-modal ref="modalForm2" @ok="modalFormOk"></select-goods-modal>
  71. <classificationModal ref="modalForm3" @ok="modalFormOkClass" />
  72. </a-spin>
  73. </template>
  74. <script>
  75. import {
  76. httpAction,
  77. getAction
  78. } from "@/api/manage";
  79. import {
  80. validateDuplicateValue
  81. } from "@/utils/util";
  82. import SelectGoodsModal from "./SelectGoodsModal";
  83. import classificationModal from './classificationModal.vue';
  84. const columns = [{
  85. title: "商品名称",
  86. dataIndex: "name",
  87. },
  88. {
  89. title: "商品条码",
  90. dataIndex: "barCode",
  91. },
  92. {
  93. title: "库存",
  94. dataIndex: "inventory",
  95. },
  96. {
  97. title: "操作",
  98. dataIndex: "action",
  99. align: "center",
  100. fixed: "right",
  101. width: 70,
  102. scopedSlots: {
  103. customRender: "action"
  104. },
  105. },
  106. ];
  107. const columnsTwo = [{
  108. title: "分类名称",
  109. dataIndex: "name",
  110. },
  111. {
  112. title: "分类编号",
  113. dataIndex: "id",
  114. },
  115. {
  116. title: "操作",
  117. dataIndex: "action",
  118. align: "center",
  119. fixed: "right",
  120. width: 70,
  121. scopedSlots: {
  122. customRender: "action"
  123. },
  124. },
  125. ]
  126. export default {
  127. name: "PosTableForm",
  128. components: {
  129. SelectGoodsModal,
  130. classificationModal
  131. },
  132. props: {
  133. //表单禁用
  134. disabled: {
  135. type: Boolean,
  136. default: false,
  137. required: false,
  138. },
  139. },
  140. data() {
  141. return {
  142. //分类弹窗
  143. classification: false,
  144. columns,
  145. columnsTwo,
  146. options: [{
  147. label: '全部菜品',
  148. value: 0
  149. },
  150. {
  151. label: '菜品分类',
  152. value: 1
  153. },
  154. {
  155. label: '菜品',
  156. value: 2
  157. },
  158. ],
  159. value: 1,
  160. model: {
  161. state: false,
  162. type: 0,
  163. detailList: [],
  164. detailListClass:[],
  165. remark: "",
  166. id: ''
  167. },
  168. labelCol: {
  169. xs: {
  170. span: 24
  171. },
  172. sm: {
  173. span: 5
  174. },
  175. },
  176. wrapperCol: {
  177. xs: {
  178. span: 24
  179. },
  180. sm: {
  181. span: 16
  182. },
  183. },
  184. confirmLoading: false,
  185. validatorRules: {
  186. name: [{
  187. required: true,
  188. message: "请输入口味名称!"
  189. }],
  190. money: [{
  191. required: true,
  192. message: "请输入金额!"
  193. }],
  194. state: [{
  195. required: true,
  196. message: "请选择是否开启!"
  197. }],
  198. type: [{
  199. required: true,
  200. message: "请选择应用范围!"
  201. }],
  202. },
  203. url: {
  204. add: "/pos/posKwConfig/add",
  205. edit: "/pos/posKwConfig/edit",
  206. queryById: "/pos/posTable/queryById",
  207. },
  208. posTypeList: [],
  209. tableTypeList: [],
  210. regionList: []
  211. };
  212. },
  213. computed: {
  214. formDisabled() {
  215. return this.disabled;
  216. },
  217. },
  218. created() {
  219. var _info = JSON.parse(localStorage.getItem("storeInfo"));
  220. if (_info) {
  221. this.model.hotelId = _info.id;
  222. }
  223. //备份model原始值
  224. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  225. // getAction("/pos/posType/list", {
  226. // hotelId: _info.id,
  227. // pageNo: 1,
  228. // pageSize: 100,
  229. // }).then((res) => {
  230. // if (res.success) {
  231. // this.posTypeList = res.result.records;
  232. // }
  233. // });
  234. // getAction("/pos/posTableType/list", {
  235. // hotelId: _info.id,
  236. // pageNo: 1,
  237. // pageSize: 100,
  238. // }).then((res) => {
  239. // if (res.success) {
  240. // this.tableTypeList = res.result.records;
  241. // }
  242. // });
  243. // getAction("/pos/posRegion/list", {
  244. // hotelId: _info.id,
  245. // pageNo: 1,
  246. // pageSize: 100,
  247. // }).then((res) => {
  248. // if (res.success) {
  249. // this.regionList = res.result.records;
  250. // }
  251. // });
  252. },
  253. methods: {
  254. handleAddClass() {
  255. this.$refs.modalForm3.edit({
  256. formThali: true,
  257. });
  258. this.$refs.modalForm2.title = "分类选择";
  259. this.$refs.modalForm2.disableSubmit = false;
  260. },
  261. modalFormOkClass(e){
  262. console.log("e", e);
  263. //判断两个数组中是否有id相同的元素
  264. if (this.model.detailListClass.some((t) => e.some((ele) => ele.id == t.id))) {
  265. this.$message.warning("请勿重复添加");
  266. return;
  267. }
  268. this.model.detailListClass = this.model.detailListClass.concat(e);
  269. },
  270. onChange(e) {
  271. console.log(e);
  272. },
  273. add() {
  274. this.edit(this.modelDefault);
  275. },
  276. edit(record) {
  277. console.log(record);
  278. this.model = Object.assign({}, record);
  279. this.visible = true;
  280. },
  281. submitForm() {
  282. const that = this;
  283. // 触发表单验证
  284. this.$refs.form.validate((valid) => {
  285. if (valid) {
  286. that.confirmLoading = true;
  287. let httpurl = "";
  288. let method = "";
  289. if (!this.model.id) {
  290. httpurl += this.url.add;
  291. method = "post";
  292. } else {
  293. httpurl += this.url.edit;
  294. method = "put";
  295. }
  296. // this.model.state = this.model.status ? 1 : 0;
  297. this.model.money = parseInt(this.model.money)
  298. if (this.model.type==0) {
  299. this.model.detailList = []
  300. }
  301. if (this.model.type==1) {
  302. this.model.detailList = this.model.detailListClass.map(item=>({
  303. goodsId:item.id
  304. }))
  305. }
  306. if (this.model.type==2) {
  307. this.model.detailList = this.model.detailList.map(item=>({
  308. goodsId:item.id
  309. }))
  310. }
  311. console.log(this.model);
  312. httpAction(httpurl, this.model, method)
  313. .then((res) => {
  314. if (res.success) {
  315. that.$message.success(res.message);
  316. that.$emit("ok");
  317. } else {
  318. that.$message.warning(res.message);
  319. }
  320. })
  321. .finally(() => {
  322. that.confirmLoading = false;
  323. });
  324. }
  325. });
  326. },
  327. handleAdd() {
  328. this.$refs.modalForm2.edit({
  329. formThali: true,
  330. });
  331. this.$refs.modalForm2.title = "商品选择";
  332. this.$refs.modalForm2.disableSubmit = false;
  333. },
  334. modalFormOk(e) {
  335. console.log("e", e);
  336. e.forEach((t) => {
  337. this.$set(t, "required", false);
  338. this.$set(t, "num", 1);
  339. });
  340. //判断两个数组中是否有id相同的元素
  341. if (this.model.detailList.some((t) => e.some((ele) => ele.id == t.id))) {
  342. this.$message.warning("请勿重复添加");
  343. return;
  344. }
  345. this.model.detailList = this.model.detailList.concat(e);
  346. },
  347. handleDelete(index) {
  348. this.model.detailList.splice(index, 1);
  349. },
  350. handleDeleteClass(index){
  351. this.model.detailListClass.splice(index, 1);
  352. }
  353. },
  354. };
  355. </script>