roomNumForm.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model
  5. ref="form"
  6. :model="model"
  7. :rules="validatorRules"
  8. slot="detail"
  9. >
  10. <a-form-model-item
  11. label="房间楼层"
  12. :labelCol="labelCol"
  13. :wrapperCol="wrapperCol"
  14. prop="floorId"
  15. >
  16. <a-select
  17. placeholder="请选择"
  18. style="width: 200px"
  19. v-model="model.floorId"
  20. @change="onFloorChange($event)"
  21. >
  22. <template v-for="item in buildingTreeData">
  23. <a-select-opt-group v-if="item.children" :key="item.id">
  24. <span slot="label"><a-icon type="tags" />{{ item.name }}</span>
  25. <a-select-option
  26. :value="child.id"
  27. v-for="child in item.children"
  28. :key="child.id"
  29. >
  30. {{ child.name }}
  31. </a-select-option>
  32. </a-select-opt-group>
  33. </template>
  34. </a-select>
  35. </a-form-model-item>
  36. <a-form-model-item
  37. label="房间房型"
  38. :labelCol="labelCol"
  39. :wrapperCol="wrapperCol"
  40. prop="layoutId"
  41. >
  42. <a-select
  43. placeholder="请选择"
  44. style="width: 200px"
  45. v-model="model.layoutId"
  46. >
  47. <a-select-option
  48. :value="item.id"
  49. v-for="item in layouts"
  50. :key="item.id"
  51. >
  52. {{ item.name }}
  53. </a-select-option>
  54. </a-select>
  55. </a-form-model-item>
  56. <a-form-model-item
  57. label="房间前缀"
  58. :labelCol="labelCol"
  59. :wrapperCol="wrapperCol"
  60. prop="prefix"
  61. >
  62. <a-input
  63. style="width: 50%"
  64. v-model="model.prefix"
  65. placeholder="请填写房间前缀"
  66. />
  67. </a-form-model-item>
  68. <a-form-model-item
  69. label="房间房号"
  70. :labelCol="labelCol"
  71. :wrapperCol="wrapperCol"
  72. prop="name"
  73. >
  74. <a-input
  75. style="width: 50%"
  76. v-model="model.name"
  77. placeholder="请填写房号"
  78. />
  79. </a-form-model-item>
  80. <a-form-model-item
  81. label="房间描述"
  82. :labelCol="labelCol"
  83. :wrapperCol="wrapperCol"
  84. prop="remark"
  85. >
  86. <a-textarea
  87. style="width: 50%"
  88. v-model="model.remark"
  89. placeholder="请填写房间描述"
  90. />
  91. </a-form-model-item>
  92. </a-form-model>
  93. </j-form-container>
  94. </a-spin>
  95. </template>
  96. <script>
  97. import { getRoomPlans, getSelectList } from "@/api/api";
  98. import { buildingTree } from "@/api/roomBuildingApi";
  99. import { getAllLayouts } from "../../../../../api/roomLayout";
  100. import { httpAction, getAction } from "@/api/manage";
  101. import { validateDuplicateValue } from "@/utils/util";
  102. export default {
  103. name: "BusMarketMemberForm",
  104. props: {
  105. disabled: {
  106. type: Boolean,
  107. default: false,
  108. required: false,
  109. },
  110. },
  111. data() {
  112. return {
  113. model: {
  114. id: "",
  115. floorId: undefined,
  116. buildId: null,
  117. layoutId: undefined,
  118. prefix: null,
  119. name: null,
  120. remark: null,
  121. },
  122. labelCol: {
  123. xs: { span: 24 },
  124. sm: { span: 5 },
  125. },
  126. wrapperCol: {
  127. xs: { span: 24 },
  128. sm: { span: 16 },
  129. },
  130. confirmLoading: false,
  131. validatorRules: {
  132. name: [{ required: true, message: "请输入房型!" }],
  133. floorId: [{ required: true, message: "请选择楼层!" }],
  134. layoutId: [{ required: true, message: "请选择房型!" }],
  135. },
  136. url: {
  137. add: "/rooms/cesRooms/save",
  138. edit: "/rooms/cesRooms/modify",
  139. queryById: "/rooms/cesRooms/queryById",
  140. },
  141. iconChooseVisible: false,
  142. roomPlans: [],
  143. members: [],
  144. buildingTreeData: [],
  145. layouts: [],
  146. };
  147. },
  148. computed: {
  149. formDisabled() {
  150. return this.disabled;
  151. },
  152. },
  153. created() {
  154. buildingTree().then((res) => {
  155. if (res.code == 200) {
  156. this.buildingTreeData = res.result;
  157. }
  158. });
  159. getAllLayouts().then((res) => {
  160. if (res.code == 200) {
  161. this.layouts = res.result.records;
  162. }
  163. });
  164. var _info = JSON.parse(localStorage.getItem("storeInfo"));
  165. if (_info) {
  166. this.model.hotelId = _info.id;
  167. this.initData();
  168. }
  169. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  170. },
  171. methods: {
  172. // 下拉框改变之后找到楼栋id
  173. onFloorChange(e) {
  174. this.buildingTreeData.forEach((s) => {
  175. if (s.children) {
  176. s.children.forEach((t) => {
  177. if (t.id == e) this.model.buildId = s.id;
  178. });
  179. }
  180. });
  181. },
  182. initData() {
  183. getRoomPlans(this.model.hotelId, null).then((res) => {
  184. if (res.success) {
  185. this.roomPlans = res.result;
  186. }
  187. });
  188. },
  189. selectIcons() {
  190. this.iconChooseVisible = true;
  191. },
  192. handleIconCancel() {
  193. this.iconChooseVisible = false;
  194. },
  195. handleIconChoose(value) {
  196. console.log(value);
  197. this.model.icon = value;
  198. this.iconChooseVisible = false;
  199. },
  200. add() {
  201. this.edit(this.modelDefault);
  202. },
  203. edit(record) {
  204. this.model = Object.assign({}, record);
  205. this.visible = true;
  206. getSelectList({ id: this.model.id }).then((res) => {
  207. if (res.success) {
  208. this.members = res.result;
  209. }
  210. });
  211. },
  212. submitForm() {
  213. const that = this;
  214. // 触发表单验证
  215. this.$refs.form.validate((valid) => {
  216. if (valid) {
  217. that.confirmLoading = true;
  218. let httpurl = "";
  219. let method = "";
  220. if (!this.model.id) {
  221. httpurl += this.url.add;
  222. method = "post";
  223. } else {
  224. httpurl += this.url.edit;
  225. method = "put";
  226. }
  227. if (this.model.payFlag == 0) {
  228. this.model.payAmount = 0;
  229. }
  230. httpAction(httpurl, this.model, method)
  231. .then((res) => {
  232. if (res.success) {
  233. that.$message.success(res.message);
  234. that.$emit("ok");
  235. } else {
  236. that.$message.warning(res.message);
  237. }
  238. })
  239. .finally(() => {
  240. that.confirmLoading = false;
  241. });
  242. }
  243. });
  244. },
  245. },
  246. };
  247. </script>
  248. <style scoped>
  249. .avatar-uploader > .ant-upload {
  250. width: 104px;
  251. height: 104px;
  252. }
  253. </style>