addEditForm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <template>
  2. <el-form
  3. ref="ruleForm"
  4. :loading="loading"
  5. :model="ruleForm"
  6. status-icon
  7. :rules="rulesThis"
  8. label-width="80px"
  9. style="width: 100%"
  10. class="demo-ruleForm"
  11. >
  12. <el-row>
  13. <el-col :span="12">
  14. <el-form-item label="异常数量" prop="error_num">
  15. <el-input
  16. :disabled="id !== 'add'"
  17. v-model="ruleForm.error_num"
  18. placeholder="异常数量"
  19. >
  20. <template slot="append"
  21. >总发货数量:{{ ruleForm.send_num }}</template
  22. >
  23. </el-input>
  24. </el-form-item>
  25. <el-form-item label="期望意愿" prop="except_code">
  26. <el-select
  27. style="width: 100%"
  28. :disabled="id !== 'add'"
  29. v-model="ruleForm.except_code"
  30. placeholder="期望意愿"
  31. >
  32. <el-option
  33. v-for="item in expect_options"
  34. :key="item.value"
  35. :label="item.label"
  36. :value="item.value"
  37. >
  38. </el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item label="异常原因" prop="error_code">
  42. <el-select
  43. style="width: 100%"
  44. :disabled="id !== 'add'"
  45. v-model="ruleForm.error_code"
  46. placeholder="异常原因"
  47. >
  48. <el-option
  49. v-for="item in reason_options"
  50. :key="item.id"
  51. :label="item.result"
  52. :value="item.result_code"
  53. :disabled="item.status == 0"
  54. >
  55. </el-option>
  56. </el-select>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="12">
  60. <el-form-item label="异常备注1" prop="error_remark">
  61. <el-input
  62. type="textarea"
  63. :rows="7"
  64. placeholder="请输入异常原因备注"
  65. v-model="ruleForm.error_remark"
  66. :disabled="id !== 'add'"
  67. maxlength="250"
  68. show-word-limit
  69. />
  70. </el-form-item>
  71. </el-col>
  72. <el-col :span="24">
  73. <el-form-item label="异常图片" prop="error_img">
  74. <div class="el-form-item-error-img clear">
  75. <ul>
  76. <li
  77. class="images_li"
  78. :style="getMargin_li()"
  79. v-for="(item, index) in ruleForm.error_img"
  80. :key="item"
  81. v-viewer
  82. style="margin: 0"
  83. >
  84. <img :src="item" alt="" style="width: 129px; height: 94px" />
  85. <i
  86. class="el-icon-close"
  87. @click="imgClose(index)"
  88. v-if="ruleForm.error_img.length < 5 && id === 'add'"
  89. ></i>
  90. </li>
  91. </ul>
  92. <div
  93. class="btnupload"
  94. :style="getMargin()"
  95. v-if="ruleForm.error_img.length < 5 && id === 'add'"
  96. style="position: relative"
  97. @click="open"
  98. >
  99. <i class="el-icon-plus avatar-uploader-icon"></i>
  100. <file-upload
  101. class="Upload"
  102. :accept="'.jpg,.png,,.jpeg'"
  103. :multiple="true"
  104. :uploadcondition="beforeAvatarUpload"
  105. @UploadErrorEvent="UploadErrorEvent"
  106. @UploadSuccessEvent="UploadSuccessEvent"
  107. />
  108. </div>
  109. </div>
  110. </el-form-item>
  111. </el-col>
  112. <el-col :span="24" style="text-align: right">
  113. <el-button type="primary" @click="submitForm" v-if="id === 'add'"
  114. >保 存</el-button
  115. >
  116. <el-button @click="closeAddEdit" v-if="id === 'add'">{{
  117. isDetail ? "关 闭" : "取 消"
  118. }}</el-button></el-col
  119. >
  120. </el-row>
  121. </el-form>
  122. </template>
  123. <script>
  124. import { isnumber } from "@/utils/validate.js";
  125. import asyncRequest from "@/apis/service/sellOut/sellAfterApply";
  126. import resToken from "@/mixins/resToken";
  127. export default {
  128. name: "sellAfterApplyDetail",
  129. props: ["id", "sitem", "showModelThis", "newTime", "orderCode", "outCode"],
  130. mixins: [resToken],
  131. data() {
  132. const validatenumbers = (rule, value, callback) => {
  133. if (value === "") {
  134. callback(new Error("异常数量不能为空!"));
  135. } else {
  136. if (!isnumber(value)) {
  137. callback(new Error("异常数量必须为数字"));
  138. } else {
  139. callback();
  140. }
  141. }
  142. };
  143. return {
  144. isShow: true,
  145. loading: false,
  146. disabled: true,
  147. status: "", //存储详情接口返的状态
  148. showModelThis: this.showModel,
  149. resign_name: "", //离职人
  150. hand_name: "", //交接人
  151. ruleForm: {
  152. send_num: "",
  153. order_type: "1", //售后类型 1销售2咨询,
  154. outCode: "", //出库单编号
  155. error_num: "", //异常数量
  156. error_img: [], //异常图片
  157. error_remark: "", //异常备注
  158. error_code: "", //异常原因code
  159. except_code: [], //期望意愿
  160. },
  161. rulesThis: this.rules,
  162. // 验证规则
  163. rules: {
  164. error_num: [
  165. {
  166. required: true,
  167. trigger: "blur",
  168. validator: validatenumbers,
  169. },
  170. ],
  171. error_code: [
  172. {
  173. required: true,
  174. message: "请选择异常原因",
  175. trigger: "change",
  176. },
  177. ],
  178. except_code: [
  179. {
  180. required: true,
  181. message: "请选择期望意愿",
  182. trigger: "change",
  183. },
  184. ],
  185. error_img: [
  186. {
  187. type: "array",
  188. required: true,
  189. message: "异常图片不能为空!",
  190. trigger: "change",
  191. },
  192. ],
  193. error_remark: [
  194. {
  195. required: true,
  196. message: "请输入异常原因备注",
  197. trigger: "blur",
  198. },
  199. ],
  200. },
  201. reason_options: [],
  202. reason_value: "", //异常原因
  203. expect_options: [
  204. {
  205. value: "1",
  206. label: "退货",
  207. },
  208. {
  209. value: "2",
  210. label: "换货",
  211. },
  212. {
  213. value: "3",
  214. label: "改变售价",
  215. },
  216. ],
  217. code: "",
  218. };
  219. },
  220. computed: {
  221. powers() {
  222. let tran =
  223. this.$store.getters.btnList.find(
  224. (item) => item.menu_route == "sellAfterApplyDetail"
  225. ) || {};
  226. if (tran && tran.action && tran.action.length > 0) {
  227. return tran.action;
  228. } else {
  229. return [];
  230. }
  231. },
  232. },
  233. mounted() {
  234. this.getReason(); //获取异常原因
  235. this.initForm();
  236. },
  237. watch: {
  238. id: function (val) {
  239. if (val) {
  240. this.initForm();
  241. }
  242. },
  243. newTime: function (val) {
  244. if (val) {
  245. this.initForm();
  246. }
  247. },
  248. },
  249. methods: {
  250. // 关闭弹窗,直接隐藏表单
  251. async closeAddEdit() {
  252. this.$emit("closeModel", false); //抛出一个事件,关闭弹窗
  253. },
  254. closeAdd() {
  255. this.showModelThis = false;
  256. },
  257. async initForm() {
  258. this.loading = true;
  259. this.status = "";
  260. this.rulesThis = this.rules;
  261. this.disabled = false;
  262. await this.resetForm();
  263. this.loading = false;
  264. },
  265. async resetForm() {
  266. // 重置
  267. await this.$nextTick(() => {
  268. if (this.$refs.ruleForm) {
  269. this.$refs.ruleForm.resetFields();
  270. this.$refs.ruleForm.clearValidate();
  271. let {
  272. error_num,
  273. error_img,
  274. error_remark,
  275. except_code,
  276. error_code,
  277. outCode,
  278. send_num,
  279. total_num,
  280. } = this.sitem;
  281. this.ruleForm = {
  282. outCode: outCode || "", //出库单编号
  283. error_num: error_num || "", //异常数量
  284. error_code: error_code || "", //异常原因
  285. except_code: except_code || "", //期望意愿
  286. error_img: error_img ? error_img.split(",") : [],
  287. error_remark: error_remark || "", //异常备注
  288. send_num: send_num || total_num || "",
  289. };
  290. }
  291. });
  292. },
  293. async submitForm() {
  294. await this.$refs.ruleForm.validate(async (valid) => {
  295. if (valid) {
  296. const { anomalous_numbers } = this.ruleForm;
  297. if (this.sitem.send_num < anomalous_numbers) {
  298. this.$message.warning("异常数量不能大于发货数量");
  299. return false;
  300. }
  301. let model = JSON.parse(JSON.stringify(this.ruleForm));
  302. model.error_img = model.error_img.toString();
  303. model.outCode = this.sitem.outCode;
  304. model.orderCode = this.sitem.orderCode;
  305. model.num = model.error_num;
  306. model.remark = model.error_remark;
  307. model.img = model.error_img;
  308. model.errorCode = model.error_code;
  309. delete model["error_num"];
  310. delete model["error_remark"];
  311. delete model["error_img"];
  312. delete model["error_code"];
  313. const res = await asyncRequest.add(model);
  314. if (res && res.code === 0) {
  315. const title = this.id === "add" ? "添加成功!" : "修改成功!";
  316. this.$notify.success({
  317. title,
  318. message: "",
  319. });
  320. this.$emit("refresh", false);
  321. } else if (res && res.code >= 100 && res.code <= 104) {
  322. await this.logout();
  323. } else {
  324. this.$message.warning(res.message);
  325. }
  326. } else {
  327. console.log("error submit!!");
  328. return false;
  329. }
  330. });
  331. },
  332. async statusConfirm(status, message) {
  333. await this.$confirm(`确定要${message}?`, {
  334. confirmButtonText: "确定",
  335. cancelButtonText: "取消",
  336. type: "warning",
  337. })
  338. .then(async () => {
  339. if (status === "-1") {
  340. await this.deleteById(message);
  341. } else {
  342. await this.setStatus(status, message);
  343. }
  344. })
  345. .catch(() => {
  346. console.log("取消");
  347. });
  348. },
  349. async deleteById(message) {
  350. const res = await asyncRequest.delete({ id: this.id });
  351. if (res && res.code === 0) {
  352. this.$notify.success({
  353. title: message + "成功!",
  354. message: "",
  355. });
  356. this.routeGoto("handover", {});
  357. } else if (res && res.code >= 100 && res.code <= 104) {
  358. await this.logout();
  359. } else {
  360. this.$message.warning(res.message);
  361. }
  362. },
  363. async setStatus(status, message) {
  364. let model = {
  365. id: this.id,
  366. remark: "",
  367. status: status,
  368. };
  369. const res = await asyncRequest.status(model);
  370. this.loading = false;
  371. if (res && res.code === 0) {
  372. this.$notify.success({
  373. title: message + "成功!",
  374. message: "",
  375. });
  376. this.initForm();
  377. } else if (res && res.code >= 100 && res.code <= 104) {
  378. await this.logout();
  379. } else {
  380. this.$message.warning(res.message);
  381. }
  382. },
  383. open() {
  384. this.show = true;
  385. },
  386. // 获取异常原因
  387. async getReason() {
  388. let model = {
  389. type: "2",
  390. page: 1,
  391. size: 100,
  392. };
  393. const res = await asyncRequest.reasonList(model);
  394. this.loading = false;
  395. if (res && res.code === 0) {
  396. this.reason_options = res.data.list;
  397. } else if (res && res.code >= 100 && res.code <= 104) {
  398. await this.logout();
  399. } else {
  400. this.$message.warning(res.message);
  401. }
  402. },
  403. // 异常原因
  404. handleAnomalousReason(e) {
  405. if (e) {
  406. this.ruleForm.error_code = e;
  407. } else {
  408. this.ruleForm.error_code = "";
  409. }
  410. this.$refs.ruleForm.validateField("error_code");
  411. },
  412. //图片上传失败
  413. UploadErrorEvent(res) {
  414. if (res !== "break") {
  415. this.$message.error("图片上传失败!");
  416. this.$refs.ruleForm.validateField("error_img");
  417. }
  418. },
  419. //图片上传成功
  420. async UploadSuccessEvent(data) {
  421. const { url } = data;
  422. if (url === "noToken") {
  423. await this.logout();
  424. } else {
  425. this.ruleForm.error_img.push(url);
  426. this.$message.success("图片上传成功!");
  427. this.$refs.ruleForm.validateField("error_img");
  428. }
  429. },
  430. //判断图片规格
  431. beforeAvatarUpload(file) {
  432. let isJPG = false,
  433. isLt2M = false;
  434. if (file) {
  435. if (
  436. file.type === "image/jpg" ||
  437. file.type === "image/png" ||
  438. file.type === "image/jpeg"
  439. ) {
  440. isJPG = true;
  441. }
  442. isLt2M = file.size / 1024 / 1024 < 1;
  443. if (!isJPG) {
  444. this.$message.error("图片格式不正确!");
  445. }
  446. if (!isLt2M) {
  447. this.$message.error("图片大小不能超过 1MB!");
  448. }
  449. }
  450. return isJPG && isLt2M;
  451. },
  452. imgClose(index) {
  453. this.ruleForm.error_img.splice(index, 1);
  454. this.$refs.ruleForm.validateField("error_img");
  455. },
  456. getMargin() {
  457. if (this.ruleForm.error_img.length == 0) {
  458. return "margin:0;";
  459. } else if (this.ruleForm.error_img.length < 3) {
  460. return "margin:0px 0 0 10px";
  461. } else {
  462. return "margin:10px 0 0 10px";
  463. }
  464. },
  465. getMargin_li() {
  466. if (this.ruleForm.error_img.length <= 3) {
  467. return "margin:0 0 0 10px";
  468. } else {
  469. return "margin:10px 0 0 10px";
  470. }
  471. },
  472. },
  473. };
  474. </script>
  475. <style lang="scss" scoped>
  476. .el-form-item-error-img {
  477. width: 100%;
  478. position: relative;
  479. padding: 0;
  480. margin: 0;
  481. vertical-align: top;
  482. // float: left;
  483. ul {
  484. vertical-align: top;
  485. width: 100%;
  486. float: left;
  487. padding: 0;
  488. margin: 0;
  489. margin: -40px 0 0 -10px;
  490. li {
  491. float: left;
  492. border: 1px solid rgb(220, 223, 230);
  493. // border-left: 0;
  494. display: block;
  495. box-sizing: border-box;
  496. width: 129px;
  497. height: 94px;
  498. line-height: 94px;
  499. position: relative;
  500. img {
  501. display: inline-block;
  502. width: 100%;
  503. height: 100%;
  504. }
  505. .el-icon-close {
  506. position: absolute;
  507. top: 0;
  508. right: 0;
  509. z-index: 2;
  510. width: 25px;
  511. height: 25px;
  512. text-align: center;
  513. line-height: 25px;
  514. font-size: 19px;
  515. &:hover {
  516. color: #63cbe7;
  517. }
  518. }
  519. }
  520. }
  521. }
  522. .images_li {
  523. // width: 129px;
  524. // height: 94px;
  525. float: left;
  526. img {
  527. &:hover {
  528. cursor: pointer;
  529. }
  530. }
  531. }
  532. .btnupload {
  533. float: left;
  534. border: 1px solid rgb(220, 223, 230);
  535. // border-left: 0;
  536. box-sizing: border-box;
  537. width: 129px;
  538. height: 94px;
  539. line-height: 94px;
  540. text-align: center;
  541. }
  542. .Upload {
  543. width: 129px;
  544. height: 94px;
  545. line-height: 94px;
  546. text-align: center;
  547. position: absolute;
  548. line-height: 0px;
  549. top: 0;
  550. left: 0;
  551. z-index: 2;
  552. line-height: 94px;
  553. }
  554. .avatar-uploader-icon {
  555. font-size: 33px;
  556. color: #8c939d;
  557. width: 50px;
  558. height: 50px;
  559. line-height: 50px;
  560. text-align: center;
  561. }
  562. </style>