addGiftDetail.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <!--
  2. * 部门表单 弹窗
  3. *
  4. * @Author: BoundLink
  5. * @Date: 2022-08-08 20:46:18
  6. -->
  7. <template>
  8. <a-modal v-model:open="visible" width="50%" title="礼品新增" @ok="onSubmit" @cancel="closeModal" destroyOnClose>
  9. <a-form class="smart-query-form" ref="formRef" labelWrap :label-col="labelCol" :model="form" :rules="rules">
  10. <div class="cost-compose">
  11. <div class="basic-info">
  12. <div class="basic-info-form">
  13. <a-row :gutter="16" class="smart-query-form-row">
  14. <a-col :span="12">
  15. <a-form-item label="物品名称" name="presentName" class="smart-query-form-item">
  16. <a-input v-model:value="form.presentName" placeholder="请输入物品名称" />
  17. </a-form-item>
  18. </a-col>
  19. <a-col :span="12">
  20. <a-form-item label="物品类别" name="presentType" class="smart-query-form-item">
  21. <a-input v-model:value="form.presentType" placeholder="请输入物品类别" />
  22. </a-form-item>
  23. </a-col>
  24. </a-row>
  25. <a-row :gutter="16" class="smart-query-form-row">
  26. <a-col :span="12">
  27. <a-form-item label="物品单位" name="presentUnit" class="smart-query-form-item">
  28. <a-input v-model:value="form.presentUnit" placeholder="请输入物品单位" />
  29. </a-form-item>
  30. </a-col>
  31. <a-col :span="12">
  32. <a-form-item label="物品品牌" name="presentBrand" class="smart-query-form-item">
  33. <a-input v-model:value="form.presentBrand" placeholder="请输入物品品牌" />
  34. </a-form-item>
  35. </a-col>
  36. </a-row>
  37. <a-row :gutter="16" class="smart-query-form-row">
  38. <a-col :span="12">
  39. <a-form-item label="市场价格" name="presentPrice" class="smart-query-form-item">
  40. <a-input v-model:value="form.presentPrice" placeholder="请输入物品市场价" />
  41. </a-form-item>
  42. </a-col>
  43. <a-col :span="12">
  44. <a-form-item label="库存数量" name="stockQuantity" class="smart-query-form-item">
  45. <a-input-number style="width: 100%" v-model:value="form.stockQuantity" placeholder="请输入库存数量" />
  46. </a-form-item>
  47. </a-col>
  48. </a-row>
  49. <a-row :gutter="16" class="smart-query-form-row">
  50. <a-col :span="24">
  51. <a-form-item label="物品略缩图" name="form.presentAttachment" class="smart-query-form-item">
  52. <Upload
  53. ref="UploadRef"
  54. :defaultFileList="defaultFileList"
  55. :maxUploadSize="10"
  56. :folder="FILE_FOLDER_TYPE_ENUM.COMMON.value"
  57. buttonText="上传物品略缩图"
  58. @change="changeAttachment"
  59. />
  60. </a-form-item>
  61. </a-col>
  62. </a-row>
  63. </div>
  64. </div>
  65. </div>
  66. </a-form>
  67. </a-modal>
  68. </template>
  69. <script setup>
  70. import { reactive, ref } from 'vue';
  71. import { theme, message, Modal } from 'ant-design-vue';
  72. import _ from 'lodash';
  73. import Upload from '/@/components/support/file-upload/index.vue';
  74. import { giftApi } from '/@/api/project/gift-api';
  75. import { FILE_FOLDER_TYPE_ENUM } from '/@/constants/support/file-const';
  76. // ----------------------- 对外暴漏 ---------------------
  77. defineExpose({
  78. showModal,
  79. });
  80. // ----------------------- modal 的显示与隐藏 ---------------------
  81. const labelCol = { style: { width: '90px' } };
  82. const emits = defineEmits(['refresh']);
  83. const visible = ref(false);
  84. const UploadRef = ref();
  85. function showModal(params) {
  86. //判断如果params.id存在且有值,则将params赋给form
  87. if (params?.id) {
  88. form = { ...params };
  89. //删除params中的某些字段
  90. delete form.deletedFlag;
  91. delete form.updateTime;
  92. delete form.updateUserId;
  93. delete form.createTime;
  94. delete form.createUserId;
  95. defaultFileList.value = params.presentAttachment;
  96. form.presentAttachment = params.presentAttachment;
  97. }
  98. visible.value = true;
  99. }
  100. function closeModal() {
  101. UploadRef.value.clear();
  102. visible.value = false;
  103. resetFormData();
  104. }
  105. // ----------------------- form 表单操作 ---------------------
  106. const formRef = ref();
  107. const formDefault = {
  108. presentName: undefined, // 物品名称
  109. presentAttachment: undefined, // 物品略缩图
  110. presentUnit: undefined, // 单位
  111. presentBrand: undefined, // 品牌
  112. presentPrice: undefined, // 市场价
  113. presentType: undefined, // 物品类别
  114. stockQuantity: undefined, // 库存数量
  115. };
  116. let form = reactive({
  117. ...formDefault,
  118. });
  119. // 表单校验规则
  120. const fromRules = {
  121. // decisionName: [{ required: true, message: '决策人姓名不能为空' }],
  122. };
  123. // 重置表单数据
  124. function resetFormData() {
  125. Object.assign(form, formDefault);
  126. }
  127. // ----------------------- 上传附件 ----------------------------
  128. // 已上传的附件列表
  129. const defaultFileList = ref([]);
  130. function changeAttachment(fileList) {
  131. defaultFileList.value = fileList;
  132. form.presentAttachment = _.isEmpty(fileList) ? [] : fileList;
  133. }
  134. // ----------------------- form 表单 ajax 操作 ---------------------
  135. function onSubmit() {
  136. formRef.value
  137. .validateFields()
  138. .then((values) => {
  139. console.log('form', form);
  140. Modal.confirm({
  141. title: '提示',
  142. content: '确定要提交吗?',
  143. okText: '确认',
  144. onOk() {
  145. if (form?.id) {
  146. editGiftData();
  147. } else {
  148. addGiftInfo();
  149. }
  150. },
  151. cancelText: '取消',
  152. onCancel() {},
  153. });
  154. })
  155. .catch((error) => {
  156. console.log('step1_error', error);
  157. });
  158. }
  159. const addGiftInfo = async () => {
  160. await giftApi.addGiftInfo(form);
  161. message.success('新增成功');
  162. emits('refreshTable');
  163. onClose();
  164. };
  165. const editGiftData = async () => {
  166. await giftApi.editGiftInfo(form);
  167. message.success('修改成功');
  168. emits('refreshTable');
  169. onClose();
  170. };
  171. function onClose() {
  172. Object.assign(form, formDefault);
  173. visible.value = false;
  174. }
  175. </script>