InvoiceUpload.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <el-row>
  3. <el-col :span="24">
  4. <el-form
  5. ref="ruleForm"
  6. :model="ruleForm"
  7. :rules="feedbacksThis"
  8. label-width="130px"
  9. class="demo-ruleForm"
  10. >
  11. <el-row :gutter="10">
  12. <el-col :span="24">
  13. <el-form-item label="发票照片" prop="image" class="activity-upload">
  14. <div v-viewer class="img-list-main clearfix">
  15. <div
  16. class="img-item"
  17. :class="{ error: item.status === '4' || item.status === '2' }"
  18. v-for="(item, index) in ruleForm.image"
  19. :key="item.image + index"
  20. @mouseenter="item.show = true"
  21. @mouseout="item.show = false"
  22. >
  23. <img
  24. :src="item.image"
  25. class="avatar"
  26. :class="{
  27. error: item.status === '4' || item.status === '2',
  28. }"
  29. />
  30. <p class="img_name">{{ item.name }}</p>
  31. <i
  32. class="el-icon-close"
  33. @click="closeImg(index, item.id)"
  34. ></i>
  35. <ul
  36. @mouseenter="item.show = true"
  37. @mouseout="item.show = false"
  38. class="error-m"
  39. :class="{ show: item.show, close: !item.show }"
  40. v-if="item.status === '4' || item.status === '2'"
  41. >
  42. <li
  43. @mouseenter="item.show = true"
  44. @mouseout="item.show = false"
  45. v-for="v in item.remark"
  46. :key="v"
  47. >
  48. {{ v }}
  49. </li>
  50. </ul>
  51. </div>
  52. <div
  53. class="btnupload"
  54. v-if="ruleForm.image.length < 101"
  55. style="position: relative"
  56. @click="open"
  57. >
  58. <i class="el-icon-plus avatar-uploader-icon"></i>
  59. <Upload
  60. class="Upload"
  61. :accept="'.jpg,.png,.bmp,.jpeg'"
  62. :multiple="true"
  63. :uploadcondition="beforeAvatarUpload"
  64. @UploadErrorEvent="UploadErrorEvent"
  65. @UploadSuccessEvent="UploadSuccessEvent"
  66. ></Upload>
  67. </div>
  68. </div>
  69. <div class="txt-tips fl">
  70. <p>
  71. <span sty>大小:小于1MB;</span><span>尺寸:250*160;</span
  72. ><span>类型:jpg.png.bmp.jpeg</span>
  73. </p>
  74. </div>
  75. </el-form-item>
  76. </el-col>
  77. </el-row>
  78. </el-form>
  79. </el-col>
  80. <el-col :span="24" style="text-align: right">
  81. <el-button type="primary" @click="submitForm">保 存 </el-button>
  82. </el-col>
  83. </el-row>
  84. </template>
  85. <script>
  86. import asyncRequest from "@/apis/service/purchase/orderRecord";
  87. import Upload from "@/components/Upload";
  88. import resToken from "@/mixins/resToken";
  89. export default {
  90. name: "orderRecord",
  91. props: ["id", "newTime", "payNo", "dstatus", "companyNo"],
  92. components: {
  93. Upload,
  94. },
  95. mixins: [resToken],
  96. data() {
  97. return {
  98. image: [],
  99. loading: false,
  100. show: false,
  101. ruleForm: {
  102. sid: this.id,
  103. image: [],
  104. },
  105. feedbacksThis: this.feedbacks,
  106. feedbacks: {
  107. image: [
  108. {
  109. required: true,
  110. message: "请选择发票照片",
  111. trigger: "change",
  112. },
  113. ],
  114. },
  115. };
  116. },
  117. watch: {
  118. newTime: function (old, val) {
  119. if (old !== val) {
  120. this.initForm();
  121. }
  122. },
  123. },
  124. mounted() {
  125. this.initForm();
  126. },
  127. methods: {
  128. open() {
  129. this.show = true;
  130. },
  131. async initForm() {
  132. this.loading = true;
  133. // console.log(this.dstatus);
  134. this.feedbacksThis = this.feedbacks;
  135. await this.resetForm();
  136. await this.initData();
  137. this.loading = false;
  138. },
  139. async resetForm() {
  140. // 重置
  141. await this.$nextTick(() => {
  142. if (this.$refs.ruleForm) {
  143. this.$refs.ruleForm.resetFields();
  144. this.$refs.ruleForm.clearValidate();
  145. this.ruleForm = {
  146. sid: this.id,
  147. image: [],
  148. };
  149. }
  150. });
  151. },
  152. async initData() {
  153. const res = await asyncRequest.invoiceinfo({ sid: this.id });
  154. if (res && res.code === 0 && res.data && res.data.invoice) {
  155. const data = res.data.invoice || [];
  156. let arr = [];
  157. if (data.length > 0) {
  158. data.forEach((v) => {
  159. let model = {
  160. id: v.id,
  161. image: v.image,
  162. status: v.status,
  163. name: v.name,
  164. remark: v.remark ? v.remark.split(";") : "",
  165. show: false,
  166. };
  167. arr.push(model);
  168. });
  169. }
  170. this.ruleForm = {
  171. sid: this.id,
  172. image: arr,
  173. };
  174. this.$refs.ruleForm.clearValidate();
  175. } else if (res && res.code >= 100 && res.code <= 104) {
  176. await this.logout();
  177. } else {
  178. this.$message.warning(res.message);
  179. }
  180. },
  181. async submitForm() {
  182. await this.$refs.ruleForm.validate(async (valid) => {
  183. if (valid) {
  184. this.loading = true;
  185. const obj = JSON.parse(JSON.stringify(this.ruleForm));
  186. let isOk = true;
  187. console.log(obj.image);
  188. let arr = [];
  189. obj.image.forEach((v) => {
  190. if (v.status === "3" || v.status === "4") {
  191. isOk = false;
  192. }
  193. if (v.id === "") {
  194. let itemA = {
  195. url: v.image,
  196. name: v.name,
  197. };
  198. arr.push(itemA);
  199. }
  200. });
  201. if (!isOk) {
  202. this.$message.error("存在识别异常或审核失败图片!");
  203. return;
  204. }
  205. if (arr.length > 0) {
  206. obj.image = arr;
  207. let res = {};
  208. res = await asyncRequest.invoiceadd(obj);
  209. if (res && res.code === 0) {
  210. await this.invoicecheck();
  211. } else if (res && res.code >= 100 && res.code <= 104) {
  212. await this.logout();
  213. } else {
  214. this.$message.warning(res.message);
  215. }
  216. } else {
  217. await this.invoicecheck();
  218. }
  219. } else {
  220. console.log("error submit!!");
  221. return false;
  222. }
  223. });
  224. },
  225. async invoicecheck() {
  226. let res = await asyncRequest.invoicecheck({ sid: this.id,type:1 });
  227. if (res && res.code === 0) {
  228. await this.invoiceSuccess();
  229. } else if (res && res.code >= 100 && res.code <= 104) {
  230. await this.logout();
  231. } else {
  232. this.$message.warning(res.message);
  233. }
  234. this.loading = false;
  235. },
  236. async invoiceSuccess() {
  237. const title = "发票上传成功!";
  238. this.$notify.success({
  239. title,
  240. message: "系统正在努力识别发票,请等待识别结果!",
  241. });
  242. this.showModelThis = false;
  243. // 刷新
  244. this.$emit("refreshAll");
  245. },
  246. async closeImg(index, id) {
  247. if (id) {
  248. this.loading = true;
  249. let res = await asyncRequest.invoicedel({ id: id });
  250. if (res && res.code === 0) {
  251. this.ruleForm.image.splice(index, 1);
  252. this.$refs.ruleForm.validateField("image");
  253. } else if (res && res.code >= 100 && res.code <= 104) {
  254. await this.logout();
  255. } else {
  256. this.$message.warning(res.message);
  257. }
  258. this.loading = false;
  259. } else {
  260. this.ruleForm.image.splice(index, 1);
  261. this.$refs.ruleForm.validateField("image");
  262. }
  263. },
  264. //图片上传失败
  265. UploadErrorEvent() {
  266. this.$message.error("图片上传失败!");
  267. this.$refs.ruleForm.validateField("image");
  268. },
  269. //图片上传成功
  270. UploadSuccessEvent(data) {
  271. if (data && data.url && data.url !== "break") {
  272. const { url, name } = data.url;
  273. this.ruleForm.image.push({ id: "", image: url, name: name });
  274. this.$message.success("图片上传成功!");
  275. this.$refs.ruleForm.validateField("image");
  276. }
  277. },
  278. //判断图片规格
  279. beforeAvatarUpload(file) {
  280. let isJPG = false,
  281. isLt2M = false;
  282. if (file) {
  283. if (
  284. file.type === "image/jpg" ||
  285. file.type === "image/png" ||
  286. file.type === "image/bmp" ||
  287. file.type === "image/jpeg"
  288. ) {
  289. isJPG = true;
  290. }
  291. isLt2M = file.size / 1024 / 1024 < 1;
  292. if (!isJPG) {
  293. this.$message.error("图片格式不正确!");
  294. }
  295. if (!isLt2M) {
  296. this.$message.error("图片大小不能超过 1MB!");
  297. }
  298. }
  299. return isJPG && isLt2M;
  300. },
  301. },
  302. };
  303. </script>
  304. <style lang="scss" scoped>
  305. .orderRecord {
  306. .setWidth {
  307. width: 100% !important;
  308. // display: flex;
  309. // display: block !important;
  310. // .el-input__inner {
  311. // display: flex;
  312. // width: 1000px !important;
  313. // display: block !important;
  314. // }
  315. }
  316. .activity-upload {
  317. position: relative;
  318. .img-list-main {
  319. position: relative;
  320. width: auto;
  321. vertical-align: top;
  322. // border-left: 1px solid rgb(220, 223, 230);
  323. .img-item {
  324. vertical-align: top;
  325. float: left;
  326. width: 254px;
  327. height: 186px;
  328. position: relative;
  329. // background: chartreuse;
  330. border: 0;
  331. // border: 1px solid rgb(220, 223, 230);
  332. // border-left: 0;
  333. .img_name {
  334. height: 20px;
  335. line-height: 20px;
  336. text-align: center;
  337. font-size: 12px;
  338. width: 100%;
  339. display: inline-block;
  340. vertical-align: top;
  341. overflow: hidden;
  342. margin: -15px 0 0 0;
  343. // background: chartreuse;
  344. padding: 0;
  345. }
  346. &.error {
  347. .error-m {
  348. position: absolute;
  349. background: #f2f2f2;
  350. left: 0;
  351. top: 0;
  352. z-index: 20;
  353. width: 254px;
  354. height: 164px;
  355. line-height: 164px;
  356. text-align: left;
  357. display: flex;
  358. border: 1px solid #c03639;
  359. box-sizing: border-box;
  360. align-items: center;
  361. padding: 16px;
  362. box-sizing: border-box;
  363. li {
  364. width: 100%;
  365. padding: 5px 0;
  366. max-height: 160px;
  367. color: #c03639;
  368. text-align: center;
  369. box-sizing: border-box;
  370. }
  371. &.show {
  372. opacity: 1;
  373. transition: opacity 0.3s;
  374. }
  375. &.close {
  376. opacity: 0;
  377. transition: opacity 0.3s;
  378. }
  379. }
  380. }
  381. img {
  382. display: inline-block;
  383. width: 100%;
  384. height: 164px;
  385. border: 1px solid rgb(220, 223, 230);
  386. &.error {
  387. border: 1px solid #c03639;
  388. }
  389. }
  390. i {
  391. position: absolute;
  392. right: 6px;
  393. font-size: 16px;
  394. top: 6px;
  395. z-index: 30;
  396. color: #909399;
  397. &:hover {
  398. cursor: pointer;
  399. color: rgb(56, 193, 231);
  400. }
  401. }
  402. }
  403. }
  404. .btnupload {
  405. float: left;
  406. border: 1px solid rgb(220, 223, 230);
  407. // border-left: 0;
  408. box-sizing: border-box;
  409. width: 254px;
  410. height: 164px;
  411. line-height: 164px;
  412. text-align: center;
  413. }
  414. .Upload {
  415. width: 254px;
  416. height: 164px;
  417. line-height: 164px;
  418. text-align: center;
  419. position: absolute;
  420. line-height: 0px;
  421. top: 0;
  422. left: 0;
  423. z-index: 2;
  424. line-height: 164px;
  425. }
  426. .fileUp {
  427. vertical-align: top;
  428. }
  429. .avatar {
  430. width: 254px;
  431. height: 164px;
  432. line-height: 164px;
  433. text-align: center;
  434. }
  435. .avatar-uploader .el-upload:hover {
  436. border-color: #409eff;
  437. }
  438. .avatar-uploader-icon {
  439. font-size: 33px;
  440. color: #8c939d;
  441. width: 50px;
  442. height: 50px;
  443. line-height: 50px;
  444. text-align: center;
  445. }
  446. .avatar {
  447. width: 100%;
  448. height: 100%;
  449. display: block;
  450. }
  451. .txt-tips {
  452. display: inline-block;
  453. font-size: 13px;
  454. color: #606266;
  455. padding: 15px 0 0 15px;
  456. p {
  457. margin: 0;
  458. line-height: 30px;
  459. span {
  460. padding: 0 15px 0 0;
  461. }
  462. }
  463. }
  464. .avatar-uploader .el-upload {
  465. border: 1px dashed #d9d9d9;
  466. border-radius: 6px;
  467. cursor: pointer;
  468. position: relative;
  469. overflow: hidden;
  470. }
  471. }
  472. }
  473. </style>