batchAddForm.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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
  8. label="餐桌名称"
  9. :labelCol="labelCol"
  10. :wrapperCol="wrapperCol"
  11. prop="name"
  12. >
  13. <a-input
  14. v-model="model.name"
  15. placeholder="请输入餐桌名称"
  16. ></a-input>
  17. </a-form-model-item>
  18. </a-col> -->
  19. <a-col :span="24">
  20. <a-form-model-item label="pos类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="posTypeId">
  21. <a-select v-model="model.posTypeId" placeholder="请选择pos类型">
  22. <a-select-option :value="item.id" v-for="item in posTypeList" :key="item.id">
  23. {{ item.name }}
  24. </a-select-option>
  25. </a-select>
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :span="24">
  29. <a-form-model-item label="桌型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="posTableTypeId">
  30. <a-select v-model="model.posTableTypeId" placeholder="请选择pos类型">
  31. <a-select-option :value="item.id" v-for="item in tableTypeList" :key="item.id">
  32. {{ item.name }}
  33. </a-select-option>
  34. </a-select>
  35. </a-form-model-item>
  36. </a-col>
  37. <a-col :span="24">
  38. <a-form-model-item label="餐桌区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="posRegionId">
  39. <a-select v-model="model.posRegionId" placeholder="请选择pos类型">
  40. <a-select-option :value="item.id" v-for="item in regionList" :key="item.id">
  41. {{ item.name }}
  42. </a-select-option>
  43. </a-select>
  44. </a-form-model-item>
  45. </a-col>
  46. <a-col :span="24">
  47. <a-form-model-item label="餐桌名前缀" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qz">
  48. <a-input v-model="model.qz" placeholder="请输入餐桌名前缀" style="width: 100%" />
  49. </a-form-model-item>
  50. </a-col>
  51. <a-col :span="24">
  52. <a-form-model-item label="座位数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
  53. <a-input-number v-model="model.num" placeholder="请输入座位数" style="width: 100%" />
  54. </a-form-model-item>
  55. </a-col>
  56. <a-col :span="24">
  57. <a-form-model-item label="餐桌序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tableNo">
  58. <a-row>
  59. <a-col :span="10">
  60. <a-input v-model="model.tableNo" placeholder="开始序号"></a-input>
  61. </a-col>
  62. <a-col :span="2">
  63. </a-col>
  64. <a-col :span="10">
  65. <a-input v-model="model.tableNoEnd" placeholder="结束序号"></a-input>
  66. </a-col>
  67. </a-row>
  68. </a-form-model-item>
  69. </a-col>
  70. </a-row>
  71. </a-form-model>
  72. </j-form-container>
  73. </a-spin>
  74. </template>
  75. <script>
  76. import {
  77. httpAction,
  78. getAction
  79. } from "@/api/manage";
  80. import {
  81. validateDuplicateValue
  82. } from "@/utils/util";
  83. export default {
  84. name: "PosTableForm",
  85. components: {},
  86. props: {
  87. //表单禁用
  88. disabled: {
  89. type: Boolean,
  90. default: false,
  91. required: false,
  92. },
  93. },
  94. data() {
  95. return {
  96. model: {},
  97. labelCol: {
  98. xs: {
  99. span: 24
  100. },
  101. sm: {
  102. span: 5
  103. },
  104. },
  105. wrapperCol: {
  106. xs: {
  107. span: 24
  108. },
  109. sm: {
  110. span: 16
  111. },
  112. },
  113. confirmLoading: false,
  114. validatorRules: {
  115. tenantId: [{
  116. required: true,
  117. message: "请输入关联租户!"
  118. }],
  119. qz: [{
  120. required: true,
  121. message: "请输入餐桌名前缀!"
  122. }],
  123. hotelId: [{
  124. required: true,
  125. message: "请输入关联酒店!"
  126. }],
  127. name: [{
  128. required: true,
  129. message: "请输入餐桌名称!"
  130. }],
  131. posTypeId: [{
  132. required: true,
  133. message: "请输入pos类型id!"
  134. }],
  135. posTableTypeId: [{
  136. required: true,
  137. message: "请输入pos桌型id!"
  138. }],
  139. posRegionId: [{
  140. required: true,
  141. message: "请输入pos餐桌区域id!"
  142. }],
  143. num: [{
  144. required: true,
  145. message: "请输入座位数!"
  146. }],
  147. tableNo: [{
  148. required: true,
  149. message: "请输入餐桌序号!"
  150. }],
  151. state: [{
  152. required: true,
  153. message: "请输入状态!"
  154. }],
  155. },
  156. url: {
  157. add: "/pos/posTable/add",
  158. edit: "/pos/posTable/edit",
  159. queryById: "/pos/posTable/queryById",
  160. },
  161. posTypeList: [],
  162. tableTypeList: [],
  163. regionList: []
  164. };
  165. },
  166. computed: {
  167. formDisabled() {
  168. return this.disabled;
  169. },
  170. },
  171. created() {
  172. var _info = JSON.parse(localStorage.getItem("storeInfo"));
  173. if (_info) {
  174. this.model.hotelId = _info.id;
  175. }
  176. //备份model原始值
  177. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  178. getAction("/pos/posType/list", {
  179. hotelId: _info.id,
  180. pageNo: 1,
  181. pageSize: 100,
  182. }).then((res) => {
  183. if (res.success) {
  184. this.posTypeList = res.result.records;
  185. // this.model.posTypeId = this.posTypeList[0].id;
  186. }
  187. });
  188. getAction("/pos/posTableType/list", {
  189. hotelId: _info.id,
  190. pageNo: 1,
  191. pageSize: 100,
  192. }).then((res) => {
  193. if (res.success) {
  194. this.tableTypeList = res.result.records;
  195. }
  196. });
  197. getAction("/pos/posRegion/list", {
  198. hotelId: _info.id,
  199. pageNo: 1,
  200. pageSize: 100,
  201. }).then((res) => {
  202. if (res.success) {
  203. this.regionList = res.result.records;
  204. }
  205. });
  206. },
  207. methods: {
  208. add() {
  209. this.edit(this.modelDefault);
  210. },
  211. edit(record) {
  212. this.model = Object.assign({}, record);
  213. this.visible = true;
  214. },
  215. submitForm() {
  216. const that = this;
  217. // 触发表单验证
  218. this.$refs.form.validate((valid) => {
  219. if (valid) {
  220. // that.confirmLoading = true;
  221. let httpurl = "";
  222. let method = "";
  223. if (!this.model.id) {
  224. httpurl += this.url.add;
  225. method = "post";
  226. } else {
  227. httpurl += this.url.edit;
  228. method = "put";
  229. }
  230. let arr = [];
  231. let num = parseInt(this.model.tableNoEnd)
  232. this.model.tableNo = parseInt(this.model.tableNo)
  233. this.model.tableNoEnd = parseInt(this.model.tableNoEnd)
  234. console.log(typeof num);
  235. for(let i=0; i<num; i++){
  236. // console.log(i);
  237. arr.push({
  238. hotelId: this.model.hotelId,
  239. num: this.model.num,
  240. posRegionId: this.model.posRegionId,
  241. posTableTypeId: this.model.posTableTypeId,
  242. posTypeId: this.model.posTypeId,
  243. name: this.model.qz + (this.model.tableNo*1 + i*1),
  244. tableNo: (this.model.tableNo*1 + i*1),
  245. })
  246. }
  247. console.log(this.model);
  248. console.log(arr);
  249. // this.$emit("ok", arr);
  250. httpAction('/pos/posTable/addBatch', arr, 'post')
  251. .then((res) => {
  252. if (res.success) {
  253. that.$message.success(res.message);
  254. that.$emit("ok");
  255. } else {
  256. that.$message.warning(res.message);
  257. }
  258. })
  259. .finally(() => {
  260. that.confirmLoading = false;
  261. });
  262. }
  263. });
  264. },
  265. },
  266. };
  267. </script>