importExcelDialog.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <!-- 添加或修改菜单对话框 -->
  3. <el-dialog
  4. title="公积金导入"
  5. v-model="visible"
  6. width="680px"
  7. append-to-body
  8. draggable
  9. >
  10. <el-form
  11. ref="menuRef"
  12. :model="form"
  13. size="small"
  14. :rules="rules"
  15. label-width="100px"
  16. >
  17. <el-row>
  18. <el-col :span="24">
  19. <el-form-item label="选择导入月份" prop="year">
  20. <el-date-picker
  21. v-model="currentMonth"
  22. type="month"
  23. format="YYYY年MM月"
  24. style="width: 150px"
  25. :clearable="false"
  26. value-format="YYYY-MM-01"
  27. :disabled-date="disabledDateHandler"
  28. @change="monthChangeHandler"
  29. />
  30. </el-form-item>
  31. </el-col>
  32. </el-row>
  33. <el-row>
  34. <el-col :span="24">
  35. <el-form-item label="上传">
  36. <el-upload
  37. ref="uploadRef"
  38. :limit="1"
  39. accept=".xlsx, .xls"
  40. :headers="upload.headers"
  41. :action="upload.url + `?year=${year}&month=${month}`"
  42. :fileList="fileList"
  43. :before-upload="handleBeforeUpload"
  44. :disabled="upload.isUploading"
  45. :on-progress="handleFileUploadProgress"
  46. :on-success="handleFileSuccess"
  47. :auto-upload="false"
  48. drag
  49. >
  50. <el-icon class="el-icon--upload">
  51. <upload-filled />
  52. </el-icon>
  53. <div class="el-upload__text">
  54. 将文件拖到此处,或<em>点击上传</em>
  55. </div>
  56. <template #tip>
  57. <div class="el-upload__tip text-center">
  58. <span
  59. >仅允许导入xls、xlsx格式文件。文件大小限制为&lt;50Mb</span
  60. >
  61. <el-link
  62. type="primary"
  63. :underline="false"
  64. style="font-size: 12px; vertical-align: baseline"
  65. @click="importTemplate"
  66. >下载模板</el-link
  67. >
  68. </div>
  69. </template>
  70. </el-upload>
  71. </el-form-item>
  72. </el-col>
  73. </el-row>
  74. </el-form>
  75. <template #footer>
  76. <div class="dialog-footer">
  77. <el-button type="primary" @click="submitForm">确 定</el-button>
  78. <el-button @click="cancel">取 消</el-button>
  79. </div>
  80. </template>
  81. </el-dialog>
  82. </template>
  83. <script setup>
  84. import { exportHousingFundTemplate } from "@/api/business/production/housingFundConfirm";
  85. import { getToken, getTenant } from "@/utils/auth";
  86. import useUserStore from "@/store/modules/user";
  87. import { deepClone } from "@/utils";
  88. const { proxy } = getCurrentInstance();
  89. /** 父组件传参 */
  90. const props = defineProps({
  91. getList: {
  92. type: Function,
  93. default: () => {},
  94. },
  95. });
  96. const { getList } = toRefs(props);
  97. /** 字典数组区 */
  98. /** 表单抽屉 页变量 */
  99. const fileList = ref([]);
  100. const visible = ref(false);
  101. const currentMonth = ref(proxy.moment().subtract("month").format("YYYY-MM-01"));
  102. const year = ref(proxy.moment().format("YYYY"));
  103. const month = ref(proxy.moment().format("MM"));
  104. const addType = ref(1);
  105. const webHost = import.meta.env.VITE_APP_BASE_API;
  106. const setHeaders = {
  107. Authorization: getToken(),
  108. };
  109. const data = reactive({
  110. form: {
  111. year: proxy.moment().format("YYYY"),
  112. month: proxy.moment().format("MM"),
  113. },
  114. followData: {},
  115. });
  116. const addComRef = ref(null);
  117. /*** 客户导入参数 */
  118. const upload = reactive({
  119. // 是否禁用上传
  120. isUploading: false,
  121. // 设置上传的请求头部
  122. headers: { Authorization: "Bearer " + getToken(), tenantId: getTenant() },
  123. // 上传的地址
  124. url: `/ezhizao-yzbh-production/business/housingFundConfirm/importData`,
  125. });
  126. /** 查询对象 */
  127. const queryParams = ref({});
  128. const followQuery = ref({});
  129. const { form, rules, followData } = toRefs(data);
  130. /*********************** 表单页方法 ****************************/
  131. /** 抽屉打开 */
  132. function open() {
  133. // reset();
  134. visible.value = true;
  135. }
  136. //下载模板
  137. const importTemplate = () => {
  138. exportHousingFundTemplate();
  139. };
  140. function reset() {
  141. // console.log(addComRef.value)
  142. if (addComRef.value != null) addComRef.value.reset();
  143. }
  144. function cancel() {
  145. visible.value = false;
  146. }
  147. function submitForm() {
  148. submitFileForm();
  149. }
  150. function handleBeforeUpload(file) {
  151. console.log(file);
  152. if (
  153. file.type !==
  154. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" &&
  155. file.type !== "application/vnd.ms-excel"
  156. ) {
  157. proxy.$modal.msgError("请选择excel文件");
  158. return false;
  159. }
  160. return true;
  161. }
  162. /**文件上传中处理 */
  163. const handleFileUploadProgress = (event, file, fileList) => {
  164. upload.isUploading = true;
  165. };
  166. /** 文件上传成功处理 */
  167. const handleFileSuccess = (response, file, fileList) => {
  168. upload.open = false;
  169. upload.isUploading = false;
  170. proxy.$refs["uploadRef"].handleRemove(file);
  171. proxy.$alert(
  172. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  173. response.msg +
  174. "</div>",
  175. "导入结果",
  176. { dangerouslyUseHTMLString: true }
  177. );
  178. getList.value();
  179. };
  180. /** 提交上传文件 */
  181. function submitFileForm() {
  182. proxy.$refs["uploadRef"].submit();
  183. }
  184. function monthChangeHandler(arg) {
  185. year.value = proxy.moment(arg).format("YYYY");
  186. month.value = proxy.moment(arg).format("MM");
  187. }
  188. function disabledDateHandler(date) {
  189. if (date <= proxy.moment().subtract("month")) {
  190. return false;
  191. } else {
  192. return true;
  193. }
  194. }
  195. // 暴露给父组件的方法
  196. defineExpose({
  197. open,
  198. });
  199. </script>
  200. <style></style>