importExcelDialog.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <!-- 添加或修改菜单对话框 -->
  3. <el-dialog
  4. title="合同导入"
  5. v-model="visible"
  6. width="680px"
  7. append-to-body
  8. draggable
  9. :close-on-click-modal = "false"
  10. >
  11. <el-form
  12. ref="menuRef"
  13. :model="form"
  14. size="small"
  15. :rules="rules"
  16. label-width="100px"
  17. >
  18. <el-row>
  19. <el-col :span="24">
  20. <el-radio-group v-model="addType">
  21. <el-radio-button :label="1">循环订单导入</el-radio-button>
  22. <el-radio-button :label="2">单次订单导入</el-radio-button>
  23. </el-radio-group>
  24. </el-col>
  25. <el-col :span="24">
  26. <el-form-item label="上传">
  27. <el-upload
  28. ref="uploadRef"
  29. :limit="1"
  30. accept=".xlsx, .xls"
  31. :headers="addType === 1 ? uploadLoop.headers : uploadOnce.headers"
  32. :action="
  33. (addType === 1 ? uploadLoop.url : uploadOnce.url) +
  34. '?updateSupport=' +
  35. (addType === 1
  36. ? uploadLoop.updateSupport
  37. : uploadOnce.updateSupport)
  38. "
  39. :fileList="fileList"
  40. :before-upload="handleBeforeUpload"
  41. :disabled="
  42. addType === 1 ? uploadLoop.isUploading : uploadOnce.isUploading
  43. "
  44. :on-progress="handleFileUploadProgress"
  45. :on-success="handleFileSuccess"
  46. :auto-upload="false"
  47. drag
  48. >
  49. <el-icon class="el-icon--upload">
  50. <upload-filled />
  51. </el-icon>
  52. <div class="el-upload__text">
  53. 将文件拖到此处,或<em>点击上传</em>
  54. </div>
  55. <template #tip>
  56. <div class="el-upload__tip text-center">
  57. <!-- <div class="el-upload__tip">
  58. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
  59. </div> -->
  60. <span
  61. >仅允许导入xls、xlsx格式文件。文件大小限制为&lt;50Mb</span
  62. >
  63. <el-link
  64. type="primary"
  65. :underline="false"
  66. style="font-size: 12px; vertical-align: baseline"
  67. @click="importTemplate"
  68. >下载模板</el-link
  69. >
  70. </div>
  71. </template>
  72. </el-upload>
  73. </el-form-item>
  74. </el-col>
  75. </el-row>
  76. </el-form>
  77. <template #footer>
  78. <div class="dialog-footer">
  79. <el-button
  80. v-loading.fullscreen.lock="fullscreenLoading"
  81. type="primary"
  82. icon="Finished"
  83. size="small"
  84. @click="submitForm"
  85. >确 定</el-button
  86. >
  87. <el-button icon="Clsoe" size="small" @click="cancel">取 消</el-button>
  88. </div>
  89. </template>
  90. </el-dialog>
  91. </template>
  92. <script setup>
  93. import { getToken, getTenant } from "@/utils/auth";
  94. import useUserStore from "@/store/modules/user";
  95. import { deepClone } from "@/utils";
  96. // import { incomeDefault, taxTypes, confirmDefault } from "@/utils/default"
  97. import {
  98. exportLoopTemplate,
  99. exportOnceTemplate,
  100. importLoop,
  101. importOnce,
  102. } from "@/api/upgrade/contract";
  103. const { proxy } = getCurrentInstance();
  104. /** 父组件传参 */
  105. const props = defineProps({
  106. getList: {
  107. type: Function,
  108. default: () => {},
  109. },
  110. });
  111. const { getList } = toRefs(props);
  112. /** 字典数组区 */
  113. /** 表单抽屉 页变量 */
  114. const fileList = ref([]);
  115. const visible = ref(false);
  116. const fullscreenLoading = ref(false);
  117. const addType = ref(1);
  118. const webHost = import.meta.env.VITE_APP_BASE_API;
  119. const setHeaders = {
  120. Authorization: getToken(),
  121. };
  122. const data = reactive({
  123. form: {},
  124. followData: {},
  125. });
  126. const addComRef = ref(null);
  127. /*** 客户导入参数 */
  128. const uploadLoop = reactive({
  129. // 是否禁用上传
  130. isUploading: false,
  131. // 设置上传的请求头部
  132. headers: { Authorization: "Bearer " + getToken(), tenantId: getTenant() },
  133. // 上传的地址
  134. url: "/ezhizao-yzbh-crm/upgrade/crm/order/importLoop",
  135. });
  136. const uploadOnce = reactive({
  137. // 是否禁用上传
  138. isUploading: false,
  139. // 设置上传的请求头部
  140. headers: { Authorization: "Bearer " + getToken(), tenantId: getTenant() },
  141. // 上传的地址
  142. url: "/ezhizao-yzbh-crm/upgrade/crm/order/importOnce",
  143. });
  144. const contactorEmptyData = {
  145. id: null,
  146. name: "",
  147. position: "",
  148. gender: "男",
  149. phone: "",
  150. email: "",
  151. isMain: "是",
  152. remark: "",
  153. };
  154. const companyEmptyData = {
  155. id: null,
  156. code: "",
  157. name: "",
  158. oldName: "",
  159. shortName: "",
  160. ownerId: "",
  161. ownerName: "",
  162. sourceCategoryId: "",
  163. sourceCategoryName: "",
  164. sourceId: "",
  165. sourceName: "",
  166. stageId: "",
  167. stageName: "",
  168. phone: "",
  169. email: "",
  170. contactAddress: "",
  171. remark: "",
  172. socialCreditCode: "",
  173. mainBusinessId: "",
  174. mainBusinessName: "",
  175. typeId: "",
  176. typeName: "",
  177. legalRepresentative: "",
  178. foundationDate: "",
  179. licenceDate: "",
  180. businessStartDate: "",
  181. collectionMethod: "",
  182. businessEndDate: "",
  183. isPermanentlyEffective: "",
  184. registerMoney: "",
  185. registerMoneyUnitId: "",
  186. registerMoneyUnitName: "",
  187. provinceCode: "",
  188. province: "",
  189. cityCode: "",
  190. city: "",
  191. districtCode: "",
  192. district: "",
  193. address: "",
  194. businessField: "",
  195. taxTypeId: "",
  196. taxTypeName: "",
  197. taxDeclarationCategoryId: "",
  198. taxDeclarationCategoryName: "",
  199. isZero: "",
  200. taxDishId: "",
  201. taxDishName: "",
  202. competentTaxAuthority: "",
  203. annualIncome: "",
  204. taxType: "",
  205. taxCollectorName: "",
  206. taxCollectorPhone: "",
  207. taxMonth: "",
  208. openingBank: "",
  209. bankAccount: "",
  210. companyTags: [],
  211. companyTagIds: [],
  212. contactors: [],
  213. serviceTeams: [],
  214. companyFiles: [],
  215. stores: [],
  216. creatorId: useUserStore().user.id,
  217. };
  218. const followQuery = ref({});
  219. const { form, rules, followData } = toRefs(data);
  220. /*********************** 表单页方法 ****************************/
  221. /** 抽屉打开 */
  222. function open() {
  223. reset();
  224. visible.value = true;
  225. }
  226. function reset() {
  227. form.value = deepClone(companyEmptyData);
  228. // console.log(addComRef.value)
  229. if (addComRef.value != null) addComRef.value.reset();
  230. }
  231. function cancel() {
  232. visible.value = false;
  233. }
  234. function submitForm() {
  235. submitFileForm();
  236. }
  237. const importTemplate = () => {
  238. if (addType.value === 1) {
  239. // 循环
  240. exportLoopTemplate();
  241. } else if (addType.value === 2) {
  242. // 单次
  243. exportOnceTemplate();
  244. }
  245. };
  246. function handleBeforeUpload(file) {
  247. console.log(file);
  248. if (
  249. file.type !==
  250. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" &&
  251. file.type !== "application/vnd.ms-excel"
  252. ) {
  253. proxy.$modal.msgError("请选择excel文件");
  254. return false;
  255. }
  256. return true;
  257. }
  258. /**文件上传中处理 */
  259. const handleFileUploadProgress = (event, file, fileList) => {
  260. if (addType === 1) {
  261. uploadLoop.isUploading = true;
  262. } else {
  263. uploadOnce.isUploading = true;
  264. }
  265. };
  266. /** 文件上传成功处理 */
  267. const handleFileSuccess = (response, file, fileList) => {
  268. if (addType === 1) {
  269. uploadLoop.open = false;
  270. uploadLoop.isUploading = false;
  271. proxy.$refs["uploadRef"].handleRemove(file);
  272. proxy.$alert(
  273. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  274. response.msg +
  275. "</div>",
  276. "导入结果",
  277. { dangerouslyUseHTMLString: true }
  278. );
  279. getList.value();
  280. } else {
  281. uploadOnce.open = false;
  282. uploadOnce.isUploading = false;
  283. proxy.$refs["uploadRef"].handleRemove(file);
  284. proxy.$alert(
  285. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  286. response.msg +
  287. "</div>",
  288. "导入结果",
  289. { dangerouslyUseHTMLString: true }
  290. );
  291. getList.value();
  292. }
  293. };
  294. /** 提交上传文件 */
  295. function submitFileForm() {
  296. fullscreenLoading.value = true;
  297. const promise = Promise.resolve(proxy.$refs["uploadRef"].submit());
  298. promise.then((result) => {
  299. fullscreenLoading.value = false;
  300. }).catch((err) => {
  301. fullscreenLoading.value = false;
  302. })
  303. }
  304. // 暴露给父组件的方法
  305. defineExpose({
  306. open,
  307. });
  308. </script>
  309. <style></style>