windsiteup.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="上传文件"
  5. :visible.sync="localuploadingPOP"
  6. width="400px"
  7. @close="handleClose"
  8. >
  9. <div class="UPcondition">
  10. <p>文件类型:</p>
  11. <el-select
  12. v-model="superior"
  13. clearable
  14. @change="handleSelectClick"
  15. placeholder="请选择"
  16. >
  17. <el-option
  18. v-for="item in superiorOptions"
  19. :key="item.value"
  20. :label="item.label"
  21. :value="item.value"
  22. >
  23. </el-option>
  24. </el-select>
  25. </div>
  26. <div class="UPcondition" v-show="JXshow">
  27. <p>机型信息:</p>
  28. <el-select v-model="jixingval" clearable placeholder="请选择">
  29. <el-option
  30. v-for="item in millTypeCodeOptions"
  31. :key="item.millTypeCode"
  32. :label="item.machineTypeCode"
  33. :value="item.millTypeCode"
  34. >
  35. </el-option>
  36. </el-select>
  37. </div>
  38. <div v-if="fileShow">
  39. <el-alert
  40. title="请点击模板下载文件附件"
  41. type="success"
  42. :closable="false"
  43. >
  44. </el-alert>
  45. <p class="model-center" @click="download">模板下载</p>
  46. <el-upload
  47. class="upload-demo"
  48. :file-list="fileList"
  49. drag
  50. action
  51. :multiple="false"
  52. :before-upload="beforeUpload"
  53. :limit="1"
  54. :auto-upload="false"
  55. :on-change="handleOnChange"
  56. accept=".xlsx"
  57. >
  58. <i class="el-icon-upload"></i>
  59. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  60. <div class="el-upload__tip" slot="tip">
  61. 只能上传xlsx文件,且不超过5MB
  62. </div>
  63. </el-upload>
  64. <span slot="footer" class="dialog-footer">
  65. <el-button type="primary" @click="filesubmit" size="small"
  66. >提交</el-button
  67. >
  68. </span>
  69. </div>
  70. <div v-if="resourceShow">
  71. <el-upload
  72. class="uploaddemo2"
  73. :file-list="resourcefileList"
  74. :action="uploadUrl"
  75. :multiple="false"
  76. :before-upload="resourcebeforeUpload"
  77. :limit="1"
  78. :auto-upload="false"
  79. :on-change="resourcehandleOnChange"
  80. accept=".jpg,.png,.pdf,.docx"
  81. ref="upload"
  82. >
  83. <i class="el-icon-upload"></i>
  84. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  85. </el-upload>
  86. <div class="el-upload__tip" slot="tip">
  87. 只能上传jpg,png,pdf,docx文件,且不超过5MB
  88. </div>
  89. <span slot="footer" class="dialog-footer">
  90. <el-button type="primary" @click="resourcefilesubmit" size="small"
  91. >提交</el-button
  92. >
  93. </span>
  94. </div>
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. import {
  100. powerWordContractImportData,
  101. saveWindFieldResource,
  102. getWindEngineMillList,
  103. } from "@/api/ledger.js";
  104. export default {
  105. props: {
  106. uploadingPOP: {
  107. type: Boolean,
  108. default: false,
  109. },
  110. rowdata: {
  111. type: Object,
  112. default: () => {},
  113. },
  114. AllTemplateurlDR: {
  115. type: Object,
  116. default: () => {},
  117. },
  118. },
  119. computed: {
  120. localuploadingPOP: {
  121. get() {
  122. return this.uploadingPOP;
  123. },
  124. set(value) {
  125. // 在这里不进行任何修改
  126. },
  127. },
  128. },
  129. data() {
  130. return {
  131. superior: "",
  132. uploadUrl: process.env.VUE_APP_UPLOAD,
  133. superiorOptions: [
  134. {
  135. value: "1",
  136. label: "合同功率曲线",
  137. },
  138. {
  139. value: "2",
  140. label: "资源文件",
  141. },
  142. ],
  143. fileList: [],
  144. resourcefileList: [],
  145. fileShow: true,
  146. resourceShow: false,
  147. globalFileList: [],
  148. succeed: {},
  149. jixingval: "",
  150. millTypeCodeOptions: [],
  151. JXshow: false,
  152. };
  153. },
  154. watch: {
  155. superior(newVal) {
  156. if (newVal === "1" || newVal === "") {
  157. this.fileShow = true;
  158. this.resourceShow = false;
  159. } else {
  160. this.fileShow = false;
  161. this.resourceShow = true;
  162. }
  163. },
  164. },
  165. created() {
  166. this.relevancy();
  167. },
  168. methods: {
  169. rowStyle() {
  170. return "text-align:center";
  171. },
  172. // 下载附件
  173. download() {
  174. if (this.AllTemplateurlDR.htPower) {
  175. const link = document.createElement("a");
  176. link.href = this.AllTemplateurlDR.htPower;
  177. link.download = ""; // 可以设置默认下载文件名
  178. link.target = "_blank"; // 新窗口打开
  179. document.body.appendChild(link);
  180. link.click();
  181. document.body.removeChild(link);
  182. } else {
  183. }
  184. },
  185. beforeUpload(fileList) {
  186. const isXLSX =
  187. fileList.type ===
  188. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  189. if (!isXLSX) {
  190. this.$message.error("只能上传xlsx文件");
  191. }
  192. const isLt5MB = fileList.size / 1024 / 1024 < 5;
  193. if (!isLt5MB) {
  194. this.$message.error("文件大小不能超过5MB");
  195. }
  196. return isXLSX && isLt5MB;
  197. },
  198. handleOnChange(fileList) {
  199. this.globalFileList = fileList.raw;
  200. console.log(fileList);
  201. },
  202. // 附件提交
  203. filesubmit() {
  204. let filedata = {
  205. fieldCode: this.rowdata.fieldCode,
  206. file: this.globalFileList,
  207. millTypeCode: this.jixingval,
  208. machineTypeCode: this.millTypeCodeOptions.find(
  209. (option) => option.millTypeCode === this.jixingval
  210. ).machineTypeCode,
  211. };
  212. if (
  213. !this.superior ||
  214. this.superior === "" ||
  215. this.superior === undefined
  216. ) {
  217. this.$message({
  218. message: "请选择文件类型",
  219. type: "warning",
  220. });
  221. return;
  222. }
  223. let contractPowerCurveOption = this.superiorOptions.find(
  224. (opt) => opt.label === "合同功率曲线"
  225. );
  226. if (
  227. contractPowerCurveOption &&
  228. this.superior === contractPowerCurveOption.value &&
  229. this.jixingval === ""
  230. ) {
  231. this.$message({
  232. message: "请选择机型信息",
  233. type: "warning",
  234. });
  235. return;
  236. }
  237. if (!filedata.file || filedata.file.length === 0) {
  238. this.$message({
  239. message: "上传附件不能为空",
  240. type: "warning",
  241. });
  242. return;
  243. }
  244. powerWordContractImportData(filedata).then((res) => {
  245. this.$message.success("上传成功");
  246. // this.$emit("handleClose", false, "tolead");
  247. this.$emit("handleClose", false, "uploadingPOP");
  248. });
  249. },
  250. handleClose() {
  251. this.superior = "";
  252. this.fileList = [];
  253. this.jixingval = "";
  254. this.globalFileList = null;
  255. this.$emit("handleClose", false, "uploadingPOP");
  256. },
  257. // 资源文件
  258. resourcebeforeUpload(file) {
  259. const allowedTypes = [
  260. "image/jpeg", // jpg
  261. "image/png", // png
  262. "application/pdf", // pdf
  263. "application/vnd.openxmlformats-officedocument.wordprocessingml.document", // docx
  264. ];
  265. const isAllowedType = allowedTypes.includes(file.type);
  266. if (!isAllowedType) {
  267. this.$message.error("只能上传jpg, png, pdf, docx文件");
  268. return false; // 阻止文件上传
  269. }
  270. const isLt5MB = file.size / 1024 / 1024 < 5;
  271. if (!isLt5MB) {
  272. this.$message.error("文件大小不能超过5MB");
  273. return false; // 阻止文件上传
  274. }
  275. return true; // 允许文件上传
  276. },
  277. resourcehandleOnChange(file, fileList) {
  278. this.globalFileList = file.raw;
  279. this.succeed = file.response;
  280. // 手动触发上传
  281. if (file.status === "ready") {
  282. this.$refs.upload.submit();
  283. }
  284. },
  285. resourcefilesubmit() {
  286. let filedata = {
  287. fieldCode: this.rowdata.fieldCode,
  288. fileName: this.globalFileList.name,
  289. resourceUrl: this.succeed.data,
  290. type: this.globalFileList.type,
  291. };
  292. if (
  293. !this.superior ||
  294. this.superior === "" ||
  295. this.superior === undefined
  296. ) {
  297. this.$message({
  298. message: "请选择文件类型",
  299. type: "warning",
  300. });
  301. return;
  302. }
  303. if (filedata.resourceUrl == "") {
  304. this.$message({
  305. message: "请先上传附件在点击提交",
  306. type: "warning",
  307. });
  308. return;
  309. }
  310. saveWindFieldResource(filedata)
  311. .then((res) => {
  312. this.$message.success("上传成功");
  313. this.$emit("handleClose", false, "tolead");
  314. })
  315. .catch((error) => {});
  316. },
  317. handleSelectClick(value) {
  318. const selectedOption = this.superiorOptions.find(
  319. (option) => option.value === value
  320. );
  321. if (selectedOption && selectedOption.label === "合同功率曲线") {
  322. this.JXshow = true;
  323. } else {
  324. this.JXshow = false;
  325. }
  326. },
  327. // 选择机型
  328. async relevancy() {
  329. try {
  330. const res = await getWindEngineMillList();
  331. this.millTypeCodeOptions = res.data;
  332. } catch (error) {
  333. console.error("Error fetching wind engine mill list:", error);
  334. }
  335. },
  336. },
  337. };
  338. </script>
  339. <style lang="scss" scoped>
  340. .UPcondition {
  341. display: flex;
  342. p {
  343. width: 74px;
  344. text-align: right;
  345. line-height: 40px;
  346. }
  347. .el-select {
  348. width: 100%;
  349. margin-bottom: 20px;
  350. }
  351. .el-input {
  352. margin-bottom: 20px;
  353. }
  354. }
  355. .model-center {
  356. color: #409eff;
  357. cursor: pointer;
  358. line-height: 40px;
  359. height: 40px;
  360. font-size: 14px;
  361. }
  362. .uploaddemo2 {
  363. width: 360px;
  364. height: 200px;
  365. border: 1px dashed rgb(196, 196, 196);
  366. text-align: center;
  367. padding-top: 50px;
  368. .el-icon-upload {
  369. font-size: 50px;
  370. }
  371. }
  372. .uploaddemo2:hover {
  373. border: 1px dashed #409eff;
  374. }
  375. </style>