addEditForm.vue 16 KB

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