export.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="system-edit-user-container">
  3. <el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="400px" draggable
  4. :close-on-click-modal="false">
  5. <div>确定要导出物品记录表吗?</div>
  6. <template #footer>
  7. <span class="dialog-footer">
  8. <el-button @click="onCancel">取 消</el-button>
  9. <el-button type="primary" @click="onSubmit()">
  10. {{ state.dialog.submitTxt }}
  11. </el-button>
  12. </span>
  13. </template>
  14. </el-dialog>
  15. </div>
  16. </template>
  17. <script lang="ts" setup name="payrollModuleAttendanceImport">
  18. import { reactive, ref, nextTick } from 'vue';
  19. import { ElMessageBox, ElMessage } from 'element-plus';
  20. import type { ElForm, UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
  21. import { UploadFilled } from '@element-plus/icons-vue';
  22. import noPacking from '/@/api/noPacking/noPacking';
  23. import Good from '/@/api/model/Good'; //gzs:引入模型
  24. import config from '/@/config';
  25. import { ElLoading } from "element-plus";
  26. type FormInstance = InstanceType<typeof ElForm>;
  27. // 定义子组件向父组件传值/事件
  28. const emit = defineEmits(['refresh']);
  29. const deptDialogFormRef = ref();
  30. const upload = ref<UploadInstance>();
  31. const refForm = ref<FormInstance>();
  32. const uploadEle = ref<any>(null);
  33. const state = reactive<any>({
  34. productOptions: [],
  35. ruleForm: {
  36. path: '',
  37. },
  38. dialog: {
  39. isShowDialog: false,
  40. type: '',
  41. title: '',
  42. submitTxt: '',
  43. },
  44. isTips: false,
  45. fileUrl: '',
  46. uploadUrl: config.host + '/admin/upload/file',
  47. download_file_url: config.file + '/static/salaryRateItem.xlsx',
  48. param: {},
  49. });
  50. // 打开弹窗
  51. const openDialog = (param: any) => {
  52. //param 导出参数
  53. state.param = param;
  54. state.dialog.isShowDialog = true;
  55. state.dialog.title = '导出物品记录表';
  56. state.dialog.submitTxt = '导 出';
  57. console.log("param", param);
  58. };
  59. // 关闭弹窗
  60. const closeDialog = () => {
  61. state.dialog.isShowDialog = false;
  62. };
  63. // 取消
  64. const onCancel = () => {
  65. closeDialog();
  66. };
  67. // 清除文件缓存
  68. const ClearFiles = () => {
  69. console.log('uploadEle.value=>', uploadEle.value);
  70. if (uploadEle.value != null) {
  71. state.isTips = false;
  72. state.ruleForm.path = '';
  73. uploadEle.value.clearFiles();
  74. }
  75. };
  76. // 导出
  77. const onSubmit = async () => {
  78. const loadingInstance = ElLoading.service({ fullscreen: true, text: "正在导出,请耐心等待" });
  79. let res = await Good.export(state.param);
  80. if (res.code != 0) {
  81. nextTick(() => {
  82. loadingInstance.close();
  83. });
  84. return ElMessage.error(res.msg);
  85. }
  86. state.download_file_url = res.data.url;
  87. console.log('state.download_file_url', state.download_file_url);
  88. window.open(state.download_file_url);
  89. nextTick(() => {
  90. loadingInstance.close();
  91. });
  92. setTimeout(() => {
  93. ElMessage.success('导出成功,请留意浏览器下载列表');
  94. console.log('submit succ!');
  95. }, 500)
  96. closeDialog();
  97. emit('refresh');
  98. };
  99. // 上传文件成功的事件
  100. const handleAvatarSuccess = (res: any, file: any) => {
  101. console.log('res=>', res);
  102. console.log('file=>', file);
  103. state.ruleForm.path = res.data.file;
  104. state.fileUrl = res.data.url;
  105. state.isTips = true;
  106. };
  107. // 暴露变量
  108. defineExpose({
  109. openDialog,
  110. });
  111. </script>
  112. <style lang="scss" scoped>
  113. .down-a {
  114. text-decoration: none;
  115. color: #FFFFFF;
  116. }
  117. .tips {
  118. font-size: 12px;
  119. line-height: 1.2;
  120. color: #666;
  121. }
  122. .two {
  123. margin: 8px 0px;
  124. }
  125. .download-file {
  126. margin-top: 10px;
  127. a {
  128. text-decoration: none;
  129. color: #409eff;
  130. }
  131. }
  132. .avatar-uploader .avatar {
  133. width: 178px;
  134. height: 178px;
  135. display: block;
  136. }
  137. .avatar-uploader .el-upload {
  138. border: 1px dashed var(--el-border-color);
  139. border-radius: 6px;
  140. cursor: pointer;
  141. position: relative;
  142. overflow: hidden;
  143. transition: var(--el-transition-duration-fast);
  144. }
  145. .avatar-uploader .el-upload:hover {
  146. border-color: var(--el-color-primary);
  147. }
  148. .el-icon.avatar-uploader-icon {
  149. font-size: 28px;
  150. color: #8c939d;
  151. width: 178px;
  152. height: 178px;
  153. text-align: center;
  154. }
  155. </style>