windsitetolead.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="导入文件"
  5. :visible.sync="localtolead"
  6. width="400px"
  7. @close="handleClose"
  8. >
  9. <el-alert title="请点击模板下载文件附件" type="success" :closable="false">
  10. </el-alert>
  11. <p class="model-center" @click="download">模板下载</p>
  12. <div class="UPcondition">
  13. <p>所属公司:</p>
  14. <selecttree
  15. placeholder="请选择所属公司"
  16. :list="parentOptdata"
  17. v-model="companyCode"
  18. @change="parentChange"
  19. >
  20. </selecttree>
  21. </div>
  22. <el-upload
  23. class="upload-demo"
  24. :file-list="fileList"
  25. drag
  26. action
  27. :multiple="false"
  28. :before-upload="beforeUpload"
  29. :limit="1"
  30. :auto-upload="false"
  31. :on-change="handleOnChange"
  32. accept=".xlsx"
  33. >
  34. <i class="el-icon-upload"></i>
  35. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  36. <div class="el-upload__tip" slot="tip">
  37. 只能上传xlsx文件,且不超过5MB
  38. </div>
  39. </el-upload>
  40. <span slot="footer" class="dialog-footer">
  41. <el-button type="primary" @click="filesubmit" size="small"
  42. >提交</el-button
  43. >
  44. </span>
  45. </el-dialog>
  46. </div>
  47. </template>
  48. <script>
  49. import selecttree from "../../../components/selecttree.vue";
  50. import { windFieldImportData } from "@/api/ledger.js";
  51. export default {
  52. components: {
  53. selecttree,
  54. },
  55. props: {
  56. tolead: {
  57. type: Boolean,
  58. default: false,
  59. },
  60. parentOptdata: {
  61. type: Array,
  62. default: () => [],
  63. },
  64. AllTemplateurl: {
  65. type: Object,
  66. default: () => {},
  67. },
  68. },
  69. computed: {
  70. localtolead: {
  71. get() {
  72. console.log(this.tolead);
  73. return this.tolead;
  74. },
  75. set(value) {
  76. // 在这里不进行任何修改
  77. },
  78. },
  79. },
  80. data() {
  81. return {
  82. companyCode: "",
  83. superior: "",
  84. superiorOptions: [],
  85. fileList: [],
  86. };
  87. },
  88. methods: {
  89. rowStyle() {
  90. return "text-align:center";
  91. },
  92. // 下载附件
  93. download() {
  94. if (this.AllTemplateurl.field) {
  95. const link = document.createElement("a");
  96. link.href = this.AllTemplateurl.field;
  97. link.download = ""; // 可以设置默认下载文件名
  98. link.target = "_blank"; // 新窗口打开
  99. document.body.appendChild(link);
  100. link.click();
  101. document.body.removeChild(link);
  102. } else {
  103. console.error("URL is not set");
  104. }
  105. },
  106. handleClose() {
  107. console.log(111);
  108. this.companyCode = "";
  109. this.fileList = [];
  110. this.globalFileList = null;
  111. this.localtolead = false;
  112. this.$emit("handleClose", false, "tolead");
  113. },
  114. // 附件提交
  115. filesubmit() {
  116. let filedata = {
  117. companyCode: this.companyCode,
  118. file: this.globalFileList,
  119. };
  120. if (
  121. !this.companyCode ||
  122. this.companyCode === "" ||
  123. this.companyCode === undefined
  124. ) {
  125. this.$message({
  126. message: "请选择所属公司",
  127. type: "warning",
  128. });
  129. return;
  130. }
  131. if (filedata.file == undefined) {
  132. this.$message({
  133. message: "请先上传附件",
  134. type: "warning",
  135. });
  136. return;
  137. }
  138. windFieldImportData(filedata)
  139. .then((res) => {
  140. if (res.code === -1) {
  141. // Assuming -1 indicates success, adjust according to actual API response
  142. this.$message.error(" 上传失败 ");
  143. } else {
  144. this.$message.success("上传成功");
  145. }
  146. this.companyCode = "";
  147. this.$emit("handleClose", false, "tolead");
  148. this.$emit("onSubmit");
  149. })
  150. .catch((error) => {
  151. // this.$message.error("上传失败");
  152. // console.error(error);
  153. // this.$emit("handleClose", false, "tolead");
  154. // this.$emit("onSubmit");
  155. });
  156. },
  157. parentChange(data) {
  158. //data为当前选中对象`
  159. console.log(data);
  160. },
  161. // 附件验证
  162. beforeUpload(fileList) {
  163. const isXLSX =
  164. fileList.type ===
  165. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  166. if (!isXLSX) {
  167. this.$message.error("只能上传xlsx文件");
  168. }
  169. const isLt5MB = fileList.size / 1024 / 1024 < 5;
  170. if (!isLt5MB) {
  171. this.$message.error("文件大小不能超过5MB");
  172. }
  173. console.log(fileList, "fileList");
  174. return isXLSX && isLt5MB;
  175. },
  176. handleOnChange(fileList) {
  177. console.log(fileList);
  178. this.globalFileList = fileList.raw;
  179. },
  180. },
  181. };
  182. </script>
  183. <style lang="scss" scoped>
  184. .UPcondition {
  185. display: flex;
  186. margin-bottom: 10px;
  187. p {
  188. width: 74px;
  189. text-align: right;
  190. line-height: 40px;
  191. }
  192. .el-select {
  193. width: 100%;
  194. margin-bottom: 20px;
  195. }
  196. .el-input {
  197. margin-bottom: 20px;
  198. }
  199. }
  200. .model-center {
  201. color: #409eff;
  202. cursor: pointer;
  203. line-height: 40px;
  204. height: 40px;
  205. font-size: 14px;
  206. }
  207. </style>