receipt.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 class="img-list-main clearfix">
  15. <div
  16. class="img-item"
  17. :class="{}"
  18. v-for="(item, index) in ruleForm.image"
  19. :key="item.image + index"
  20. >
  21. <img v-viewer :src="item.image" class="avatar" />
  22. <i
  23. class="el-icon-close"
  24. @click="closeImg(index, item.id)"
  25. ></i>
  26. </div>
  27. <div
  28. class="btnupload"
  29. v-if="ruleForm.image.length < 101"
  30. style="position: relative"
  31. @click="open"
  32. >
  33. <i class="el-icon-plus avatar-uploader-icon"></i>
  34. <!-- ,.gif -->
  35. <Upload
  36. class="Upload"
  37. :accept="'.jpg,.png,.bmp,.jpeg'"
  38. :multiple="true"
  39. :uploadcondition="beforeAvatarUpload"
  40. @UploadErrorEvent="UploadErrorEvent"
  41. @UploadSuccessEvent="UploadSuccessEvent"
  42. ></Upload>
  43. </div>
  44. </div>
  45. <div class="txt-tips fl">
  46. <p>
  47. <span sty>大小:小于1M;</span><span>尺寸:100*100;</span
  48. ><span>类型:jpg.png.bmp.jpeg</span>
  49. </p>
  50. </div>
  51. </el-form-item>
  52. <el-form-item label="回执时间" prop="paytime">
  53. <el-date-picker
  54. v-model="ruleForm.paytime"
  55. type="datetime"
  56. :picker-options="pickerOptions"
  57. value-format="yyyy-MM-dd HH:mm:ss"
  58. placeholder="选择回执时间"
  59. >
  60. </el-date-picker>
  61. </el-form-item>
  62. </el-col>
  63. </el-row>
  64. </el-form>
  65. </el-col>
  66. <el-col :span="24" style="text-align: right">
  67. <el-button type="primary" @click="submitForm">保 存 </el-button>
  68. </el-col>
  69. </el-row>
  70. </template>
  71. <script>
  72. import asyncRequest from "@/apis/service/purchase/orderRecord";
  73. import Upload from "@/components/Upload";
  74. import resToken from "@/mixins/resToken";
  75. export default {
  76. name: "orderRecord",
  77. props: ["id", "newTime", "payNo", "dstatus", "companyNo"],
  78. components: {
  79. Upload,
  80. },
  81. mixins: [resToken],
  82. data() {
  83. return {
  84. pickerOptions: {
  85. disabledDate: (time) => {
  86. if (time) {
  87. return time.getTime() >= new Date().valueOf();
  88. }
  89. },
  90. },
  91. image: [],
  92. loading: false,
  93. show: false,
  94. ruleForm: {
  95. sid: this.id,
  96. image: [],
  97. paytime: "",
  98. },
  99. feedbacksThis: this.feedbacks,
  100. feedbacks: {
  101. image: [
  102. {
  103. required: true,
  104. message: "请选择发票照片",
  105. trigger: "change",
  106. },
  107. ],
  108. paytime: [
  109. {
  110. required: true,
  111. message: "请选择回执时间",
  112. trigger: "change",
  113. },
  114. ],
  115. },
  116. };
  117. },
  118. watch: {
  119. newTime: function (old, val) {
  120. if (old !== val) {
  121. this.initForm();
  122. }
  123. },
  124. },
  125. mounted() {
  126. this.initForm();
  127. },
  128. methods: {
  129. transformTime(tTime) {
  130. // console.log(tTime);
  131. let time = new Date(tTime);
  132. // console.log(time);
  133. let y = this.setNum(time.getFullYear());
  134. let M = this.setNum(time.getMonth() + 1);
  135. let d = this.setNum(time.getDate());
  136. let H = this.setNum(time.getHours());
  137. let m = this.setNum(time.getMinutes());
  138. let s = this.setNum(time.getSeconds());
  139. return `${y}-${M}-${d} ${H}:${m}:${s}`;
  140. },
  141. setNum(num) {
  142. return num < 10 ? `0${num}` : num + "";
  143. },
  144. open() {
  145. this.show = true;
  146. },
  147. async initForm() {
  148. this.loading = true;
  149. console.log(this.dstatus);
  150. this.feedbacksThis = this.feedbacks;
  151. await this.resetForm();
  152. this.loading = false;
  153. },
  154. async resetForm() {
  155. // 重置
  156. await this.$nextTick(() => {
  157. if (this.$refs.ruleForm) {
  158. this.$refs.ruleForm.resetFields();
  159. this.$refs.ruleForm.clearValidate();
  160. this.ruleForm = {
  161. sid: this.id,
  162. image: [],
  163. paytime: new Date(),
  164. };
  165. }
  166. });
  167. },
  168. async submitForm() {
  169. await this.$refs.ruleForm.validate(async (valid) => {
  170. if (valid) {
  171. this.loading = true;
  172. const obj = JSON.parse(JSON.stringify(this.ruleForm));
  173. let arr = [];
  174. obj.image.forEach((v1) => {
  175. arr.push(v1.image);
  176. });
  177. obj.image = arr.join(",");
  178. obj.status = "4";
  179. obj.sid = this.id;
  180. obj.paytime = this.transformTime(obj.paytime);
  181. // console.log(obj);
  182. // console.log(this.ruleForm);
  183. // return;
  184. let res = await asyncRequest.paymentexam(obj);
  185. if (res && res.code === 0) {
  186. const title = "回执上传成功!";
  187. this.$notify.success({
  188. title,
  189. message: "",
  190. });
  191. this.showModelThis = false;
  192. // 刷新
  193. this.$emit("refreshAll");
  194. } else if (res && res.code >= 100 && res.code <= 104) {
  195. await this.logout();
  196. } else {
  197. this.$message.warning(res.message);
  198. }
  199. } else {
  200. console.log("error submit!!");
  201. return false;
  202. }
  203. });
  204. },
  205. async closeImg(index, id) {
  206. if (id) {
  207. this.loading = true;
  208. let res = await asyncRequest.invoicedel({ id: id });
  209. if (res && res.code === 0) {
  210. this.ruleForm.image.splice(index, 1);
  211. this.$refs.ruleForm.validateField("image");
  212. } else if (res && res.code >= 100 && res.code <= 104) {
  213. await this.logout();
  214. } else {
  215. this.$message.warning(res.message);
  216. }
  217. this.loading = false;
  218. } else {
  219. this.ruleForm.image.splice(index, 1);
  220. this.$refs.ruleForm.validateField("image");
  221. }
  222. },
  223. //图片上传失败
  224. UploadErrorEvent() {
  225. this.$message.error("图片上传失败!");
  226. this.$refs.ruleForm.validateField("image");
  227. },
  228. //图片上传成功
  229. UploadSuccessEvent(data) {
  230. if (data.url !== "break") {
  231. const { url } = data.url;
  232. this.ruleForm.image.push({ id: "", image: url });
  233. this.$message.success("图片上传成功!");
  234. this.$refs.ruleForm.validateField("image");
  235. }
  236. },
  237. //判断图片规格
  238. beforeAvatarUpload(file) {
  239. console.log(file);
  240. let isJPG = false;
  241. // ||
  242. // file.type === "image/gif"
  243. if (
  244. file.type === "image/jpg" ||
  245. file.type === "image/png" ||
  246. file.type === "image/bmp" ||
  247. file.type === "image/jpeg"
  248. ) {
  249. isJPG = true;
  250. }
  251. const isLt2M = file.size / 1024 / 1024 < 1;
  252. if (!isJPG) {
  253. this.$message.error("图片格式不正确!");
  254. }
  255. if (!isLt2M) {
  256. this.$message.error("图片大小不能超过 1MB!");
  257. }
  258. return isJPG && isLt2M;
  259. },
  260. },
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .orderRecord {
  265. .setWidth {
  266. width: 100% !important;
  267. // display: flex;
  268. // display: block !important;
  269. // .el-input__inner {
  270. // display: flex;
  271. // width: 1000px !important;
  272. // display: block !important;
  273. // }
  274. }
  275. .activity-upload {
  276. position: relative;
  277. .img-list-main {
  278. position: relative;
  279. width: auto;
  280. // border-left: 1px solid rgb(220, 223, 230);
  281. .img-item {
  282. float: left;
  283. width: 202px;
  284. height: 167px;
  285. border: 1px solid rgb(220, 223, 230);
  286. // border-left: 0;
  287. position: relative;
  288. img {
  289. display: inline-block;
  290. width: 100%;
  291. height: 100%;
  292. }
  293. i {
  294. position: absolute;
  295. right: 6px;
  296. font-size: 16px;
  297. top: 6px;
  298. z-index: 2;
  299. color: #909399;
  300. &:hover {
  301. cursor: pointer;
  302. color: rgb(56, 193, 231);
  303. }
  304. }
  305. }
  306. }
  307. .btnupload {
  308. float: left;
  309. border: 1px solid rgb(220, 223, 230);
  310. // border-left: 0;
  311. box-sizing: border-box;
  312. width: 200px;
  313. height: 165px;
  314. line-height: 165px;
  315. text-align: center;
  316. }
  317. .Upload {
  318. width: 200px;
  319. height: 165px;
  320. line-height: 165px;
  321. text-align: center;
  322. position: absolute;
  323. line-height: 0px;
  324. top: 0;
  325. left: 0;
  326. z-index: 2;
  327. line-height: 165px;
  328. }
  329. .fileUp {
  330. vertical-align: top;
  331. }
  332. .avatar {
  333. width: 200px;
  334. height: 165px;
  335. line-height: 165px;
  336. text-align: center;
  337. }
  338. .avatar-uploader .el-upload:hover {
  339. border-color: #409eff;
  340. }
  341. .avatar-uploader-icon {
  342. font-size: 33px;
  343. color: #8c939d;
  344. width: 50px;
  345. height: 50px;
  346. line-height: 50px;
  347. text-align: center;
  348. }
  349. .avatar {
  350. width: 100%;
  351. height: 100%;
  352. display: block;
  353. }
  354. .txt-tips {
  355. display: inline-block;
  356. font-size: 13px;
  357. color: #606266;
  358. padding: 15px 0 0 15px;
  359. p {
  360. margin: 0;
  361. line-height: 30px;
  362. span {
  363. padding: 0 15px 0 0;
  364. }
  365. }
  366. }
  367. .avatar-uploader .el-upload {
  368. border: 1px dashed #d9d9d9;
  369. border-radius: 6px;
  370. cursor: pointer;
  371. position: relative;
  372. overflow: hidden;
  373. }
  374. }
  375. }
  376. </style>