importExcelDialog.vue 7.8 KB

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