BusMarketCouponsEventDetailForm.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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-row>
  11. <!-- <a-col :span="24">
  12. <a-form-model-item label="关联租户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenantId">
  13. <a-input v-model="model.tenantId" placeholder="请输入关联租户" ></a-input>
  14. </a-form-model-item>
  15. </a-col>
  16. <a-col :span="24">
  17. <a-form-model-item label="关联酒店" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hotelId">
  18. <a-input v-model="model.hotelId" 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="eventId">
  23. <a-input v-model="model.eventId" placeholder="请输入关联事件" ></a-input>
  24. </a-form-model-item>
  25. </a-col> -->
  26. <a-col :span="24">
  27. <a-form-model-item
  28. label="类型"
  29. :labelCol="labelCol"
  30. :wrapperCol="wrapperCol"
  31. prop="type"
  32. >
  33. <a-radio-group v-model="model.type" @change="typeChange">
  34. <a-radio :value="1">优惠券</a-radio>
  35. <a-radio :value="3">免房券</a-radio>
  36. </a-radio-group>
  37. </a-form-model-item>
  38. </a-col>
  39. <a-col :span="24">
  40. <a-form-model-item
  41. label="会员等级"
  42. :labelCol="labelCol"
  43. :wrapperCol="wrapperCol"
  44. prop="levelId"
  45. >
  46. <a-select
  47. v-model="model.levelId"
  48. placeholder="请选择"
  49. style="width: 120px"
  50. :allowClear="true"
  51. >
  52. <a-select-option
  53. :value="item.value"
  54. v-for="(item, index) in members"
  55. :key="index"
  56. >{{ item.label }}</a-select-option
  57. >
  58. </a-select>
  59. </a-form-model-item>
  60. </a-col>
  61. <a-col :span="24">
  62. <a-form-model-item
  63. label="选择券"
  64. :labelCol="labelCol"
  65. :wrapperCol="wrapperCol"
  66. prop="couponsCashId"
  67. >
  68. <a-select
  69. v-model="model.couponsCashId"
  70. placeholder="请选择"
  71. style="width: 120px"
  72. :allowClear="true"
  73. >
  74. <a-select-option
  75. :value="item.id"
  76. v-for="(item, index) in coupons"
  77. :key="index"
  78. >{{ item.name }}</a-select-option
  79. >
  80. </a-select>
  81. </a-form-model-item>
  82. </a-col>
  83. <a-col :span="24">
  84. <a-form-model-item
  85. label="数量"
  86. :labelCol="labelCol"
  87. :wrapperCol="wrapperCol"
  88. prop="count"
  89. >
  90. <a-input-number
  91. v-model="model.count"
  92. :min="1"
  93. :max="1000000"
  94. :precision="0"
  95. style="width: 20%"
  96. />
  97. </a-form-model-item>
  98. </a-col>
  99. </a-row>
  100. </a-form-model>
  101. </j-form-container>
  102. </a-spin>
  103. </template>
  104. <script>
  105. import { httpAction, getAction } from "@/api/manage";
  106. import { validateDuplicateValue } from "@/utils/util";
  107. import {
  108. getSelectList,
  109. getBusMarketCouponsList,
  110. getBusMarketCouponsCashList,
  111. } from "@/api/api";
  112. export default {
  113. name: "BusMarketCouponsEventDetailForm",
  114. components: {},
  115. props: {
  116. //表单禁用
  117. disabled: {
  118. type: Boolean,
  119. default: false,
  120. required: false,
  121. },
  122. },
  123. data() {
  124. return {
  125. model: { type: 1, eventId: "", couponsCashId: undefined },
  126. labelCol: {
  127. xs: { span: 24 },
  128. sm: { span: 5 },
  129. },
  130. wrapperCol: {
  131. xs: { span: 24 },
  132. sm: { span: 16 },
  133. },
  134. confirmLoading: false,
  135. validatorRules: {
  136. // tenantId: [{ required: true, message: "请输入关联租户!" }],
  137. // hotelId: [{ required: true, message: "请输入关联酒店!" }],
  138. // eventId: [{ required: true, message: "请输入关联事件!" }],
  139. type: [{ required: true, message: "请选择类型!" }],
  140. levelId: [{ required: true, message: "请选择会员等级!" }],
  141. couponsCashId: [{ required: true, message: "请选择券!" }],
  142. count: [{ required: true, message: "请输入数量!" }],
  143. },
  144. url: {
  145. add: "/business/busMarketCouponsEventDetail/add",
  146. edit: "/business/busMarketCouponsEventDetail/edit",
  147. queryById: "/business/busMarketCouponsEventDetail/queryById",
  148. },
  149. members: [],
  150. coupons: [],
  151. };
  152. },
  153. computed: {
  154. formDisabled() {
  155. return this.disabled;
  156. },
  157. },
  158. created() {
  159. var _info = JSON.parse(localStorage.getItem("storeInfo"));
  160. if (_info) {
  161. this.model.hotelId = _info.id;
  162. }
  163. //备份model原始值
  164. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  165. getSelectList({ id: "" }).then((res) => {
  166. if (res.success) {
  167. this.members = res.result;
  168. }
  169. });
  170. },
  171. methods: {
  172. typeChange(e) {
  173. this.coupons = [];
  174. this.model.couponsCashId = undefined;
  175. if (e.target.value == 3) {
  176. getBusMarketCouponsList({ pageNo: 1, pageSize: 100 }).then((res) => {
  177. if (res.success) {
  178. this.coupons = res.result.records;
  179. }
  180. });
  181. } else {
  182. getBusMarketCouponsCashList({ pageNo: 1, pageSize: 100 }).then(
  183. (res) => {
  184. if (res.success) {
  185. this.coupons = res.result.records;
  186. }
  187. }
  188. );
  189. }
  190. },
  191. add(eventId) {
  192. console.log("eventId2", eventId);
  193. this.modelDefault.eventId = eventId;
  194. this.edit(this.modelDefault);
  195. },
  196. edit(record) {
  197. this.model = Object.assign({}, record);
  198. this.visible = true;
  199. if (this.model.type == 3) {
  200. getBusMarketCouponsList({ pageNo: 1, pageSize: 100 }).then((res) => {
  201. if (res.success) {
  202. this.coupons = res.result.records;
  203. }
  204. });
  205. } else {
  206. getBusMarketCouponsCashList({ pageNo: 1, pageSize: 100 }).then(
  207. (res) => {
  208. if (res.success) {
  209. this.coupons = res.result.records;
  210. }
  211. }
  212. );
  213. }
  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. 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>