addEdit copy.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :center="true"
  5. align="left"
  6. top="5vh"
  7. width="1040px"
  8. @close="closeModel"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. v-loading="loading"
  12. element-loading-text="拼命加载中"
  13. element-loading-spinner="el-icon-loading"
  14. element-loading-background="rgba(0, 0, 0, 0.8)"
  15. >
  16. id:{{ id }} isDetail:{{ isDetail }},
  17. <!-- sitem:{{ sitem }}, -->
  18. 入参:{{ ruleForm }}
  19. <el-card>
  20. <el-row :gutter="10">
  21. <el-col :span="24">
  22. <el-form
  23. :model="ruleForm"
  24. status-icon
  25. :rules="rulesThis"
  26. ref="ruleForm"
  27. label-width="110px"
  28. class="demo-ruleForm"
  29. >
  30. <el-form-item
  31. label="退货原因"
  32. prop="returnReason"
  33. v-if="id === 'add' || isDetail"
  34. >
  35. <el-select
  36. style="width: 100%"
  37. v-model="ruleForm.returnReason"
  38. placeholder="退换货原因"
  39. >
  40. <el-option
  41. v-for="item in reason_options"
  42. :key="item.value"
  43. :label="item.label"
  44. :value="item.value"
  45. >
  46. </el-option>
  47. </el-select>
  48. </el-form-item>
  49. <el-form-item label="退货备注" prop="return_remark">
  50. <!-- <el-input v-model="ruleForm.tel" :disabled="isDetail"></el-input> -->
  51. <el-input
  52. type="textarea"
  53. maxlength="250"
  54. show-word-limit
  55. placeholder="请填写备注"
  56. v-model="ruleForm.return_remark"
  57. />
  58. </el-form-item>
  59. <el-form-item label="仓库信息">
  60. <el-table
  61. :data="tableForm.product_go"
  62. border
  63. :size="'mini'"
  64. row-key="key"
  65. >
  66. <el-table-column label="商品总数量" width="100">
  67. <template slot-scope="scope">
  68. <!-- :prop="'product_go.' + scope.$index + '.wsend_num'" -->
  69. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  70. <p>{{ scope.row.num }}</p>
  71. </el-form-item>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="已发货数量" width="100">
  75. <template slot-scope="scope">
  76. <!-- :prop="'product_go.' + scope.$index + '.send_num'" -->
  77. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  78. <p>
  79. {{ scope.row.send_num }}
  80. </p>
  81. </el-form-item>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="未发货数量" width="100">
  85. <template slot-scope="scope">
  86. <!-- :prop="'product_go.' + scope.$index + '.wsend_num'" -->
  87. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  88. <p>{{ scope.row.wsend_num }}</p>
  89. </el-form-item>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="退货数量">
  93. <template slot-scope="scope">
  94. <!-- :prop="'product_go.' + scope.$index + '.return_num'" -->
  95. <el-form-item
  96. :style="!scope.row.edit ? 'margin:0' : ''"
  97. :rules="{
  98. required: true,
  99. message: '退货数量不能为空',
  100. trigger: 'blur',
  101. }"
  102. >
  103. <el-input
  104. :disabled="!scope.row.edit"
  105. v-model="ruleForm.return_num"
  106. ></el-input>
  107. </el-form-item>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="采购编码" width="180">
  111. <template slot-scope="scope">
  112. <!-- :prop="'product_go.' + scope.$index + '.wsend_num'" -->
  113. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  114. <p>{{ scope.row.orderCode }}</p>
  115. </el-form-item>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="仓库名称" width="150">
  119. <template slot-scope="scope">
  120. <!-- :prop="'product_go.' + scope.$index + '.wsm_name'" -->
  121. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  122. <p>{{ scope.row.wsm_name }}</p>
  123. </el-form-item>
  124. </template>
  125. </el-table-column>
  126. <el-table-column label="仓库供应商" width="220">
  127. <template slot-scope="scope">
  128. <!-- :prop="'product_go.' + scope.$index + '.wsend_num'" -->
  129. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  130. <p>{{ scope.row.wsm_supplier }}</p>
  131. </el-form-item>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="仓库编码" width="200">
  135. <template slot-scope="scope">
  136. <!-- :prop="'product_go.' + scope.$index + '.wsend_num'" -->
  137. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  138. <p>{{ scope.row.wsm_code }}</p>
  139. </el-form-item>
  140. </template>
  141. </el-table-column>
  142. <!-- <el-table-column label="仓库供应商">
  143. <template slot-scope="scope">
  144. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  145. <p>{{ scope.row.wsm_supplierNo }}</p>
  146. </el-form-item>
  147. </template>
  148. </el-table-column> -->
  149. <el-table-column fixed="right" label="操作" width="80">
  150. <template slot-scope="scope">
  151. <el-tooltip
  152. effect="dark"
  153. content="编辑"
  154. v-if="!scope.row.edit"
  155. placement="top"
  156. >
  157. <i
  158. class="el-icon-edit tb-icon"
  159. @click="editRow(scope.$index, 'return')"
  160. ></i>
  161. </el-tooltip>
  162. <el-tooltip
  163. effect="dark"
  164. content="保存"
  165. v-if="scope.row.edit"
  166. placement="top"
  167. >
  168. <i
  169. class="el-icon-circle-check tb-icon"
  170. @click="checkRow(scope.$index, 'return')"
  171. ></i>
  172. </el-tooltip>
  173. <el-tooltip effect="dark" content="重置" placement="top">
  174. <i
  175. v-if="scope.row.edit"
  176. class="el-icon-refresh-left tb-icon"
  177. @click="resetRow(scope.$index)"
  178. ></i>
  179. </el-tooltip>
  180. </template>
  181. </el-table-column>
  182. </el-table>
  183. <!-- <el-col
  184. :span="24"
  185. style="text-align: right; padding: 30px 0 10px 0"
  186. >
  187. <el-button type="primary" :size="'mini'" @click="submitForm"
  188. >保 存
  189. </el-button>
  190. </el-col> -->
  191. </el-form-item>
  192. <el-form-item label="收货信息">
  193. <el-table
  194. :data="tableForm.get_product_go"
  195. border
  196. :size="'mini'"
  197. row-key="key"
  198. >
  199. <el-table-column label="收货总数量">
  200. <template slot-scope="scope">
  201. <!-- :prop="'product_go.' + scope.$index + '.send_num'" -->
  202. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  203. <p>
  204. {{ scope.row.receipt_quantity }}
  205. </p>
  206. </el-form-item>
  207. </template>
  208. </el-table-column>
  209. <el-table-column label="已发货数量">
  210. <template slot-scope="scope">
  211. <!-- :prop="'product_go.' + scope.$index + '.send_num'" -->
  212. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  213. <p>
  214. {{ scope.row.send_num }}
  215. </p>
  216. </el-form-item>
  217. </template>
  218. </el-table-column>
  219. <el-table-column label="未发货数量">
  220. <template slot-scope="scope">
  221. <!-- :prop="'product_go.' + scope.$index + '.wsend_num'" -->
  222. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  223. <p>{{ scope.row.wsend_num }}</p>
  224. </el-form-item>
  225. </template>
  226. </el-table-column>
  227. <el-table-column label="退货数量">
  228. <template slot-scope="scope">
  229. <!-- :prop="'product_go.' + scope.$index + '.return_num'" -->
  230. <el-form-item
  231. :style="!scope.row.edit ? 'margin:0' : ''"
  232. :rules="{
  233. required: true,
  234. message: '退货数量不能为空',
  235. trigger: 'blur',
  236. }"
  237. >
  238. <el-input
  239. :disabled="!scope.row.edit"
  240. v-model="ruleForm.get_return_num"
  241. ></el-input>
  242. </el-form-item>
  243. </template>
  244. </el-table-column>
  245. <el-table-column label="采购编码" width="200">
  246. <template slot-scope="scope">
  247. <!-- :prop="'product_go.' + scope.$index + '.send_num'" -->
  248. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  249. <p>
  250. {{ scope.row.orderCode }}
  251. </p>
  252. </el-form-item>
  253. </template>
  254. </el-table-column>
  255. <!-- <el-table-column label="仓库供应商">
  256. <template slot-scope="scope">
  257. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  258. <p>{{ scope.row.wsm_supplierNo }}</p>
  259. </el-form-item>
  260. </template>
  261. </el-table-column> -->
  262. <el-table-column label="收货联系人 ">
  263. <template slot-scope="scope">
  264. <!-- :prop="'product_go.' + scope.$index + '.wsm_name'" -->
  265. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  266. <p>{{ scope.row.contactor }}</p>
  267. </el-form-item>
  268. </template>
  269. </el-table-column>
  270. <el-table-column label="联系方式" width="120">
  271. <template slot-scope="scope">
  272. <!-- :prop="'product_go.' + scope.$index + '.wsm_name'" -->
  273. <el-form-item :style="!scope.row.edit ? 'margin:0' : ''">
  274. <p>{{ scope.row.mobile }}</p>
  275. </el-form-item>
  276. </template>
  277. </el-table-column>
  278. <el-table-column fixed="right" label="操作" width="80">
  279. <template slot-scope="scope">
  280. <el-tooltip
  281. effect="dark"
  282. content="编辑"
  283. v-if="!scope.row.edit"
  284. placement="top"
  285. >
  286. <i
  287. class="el-icon-edit tb-icon"
  288. @click="editRow(scope.$index, 'get')"
  289. ></i>
  290. </el-tooltip>
  291. <el-tooltip
  292. effect="dark"
  293. content="保存"
  294. v-if="scope.row.edit"
  295. placement="top"
  296. >
  297. <i
  298. class="el-icon-circle-check tb-icon"
  299. @click="checkRow(scope.$index, 'get')"
  300. ></i>
  301. </el-tooltip>
  302. <el-tooltip effect="dark" content="重置" placement="top">
  303. <i
  304. v-if="scope.row.edit"
  305. class="el-icon-refresh-left tb-icon"
  306. @click="resetRow(scope.$index)"
  307. ></i>
  308. </el-tooltip>
  309. </template>
  310. </el-table-column>
  311. </el-table>
  312. <!-- <el-col
  313. :span="24"
  314. style="text-align: right; padding: 30px 0 10px 0"
  315. >
  316. <el-button type="primary" :size="'mini'" @click="submitForm"
  317. >保 存
  318. </el-button>
  319. </el-col> -->
  320. </el-form-item>
  321. </el-form>
  322. </el-col>
  323. <el-col :span="24" style="text-align: right">
  324. <el-button type="primary" @click="submitForm" v-if="!isDetail"
  325. >保 存
  326. </el-button>
  327. <el-button @click="showModelThis = false">{{
  328. isDetail ? "关 闭" : "取 消"
  329. }}</el-button>
  330. </el-col>
  331. </el-row>
  332. </el-card>
  333. </el-dialog>
  334. </template>
  335. <script>
  336. import asyncRequest from "@/apis/service/sellOut/sellReturnList";
  337. import resToken from "@/mixins/resToken";
  338. import {
  339. isnumber,
  340. isMobile,
  341. validEmail,
  342. isAlphanumeric,
  343. isChinese,
  344. isEmoticon,
  345. validAlphabets,
  346. } from "@/utils/validate";
  347. export default {
  348. name: "sellReturnList",
  349. props: ["showModel", "id", "isDetail", "sitem"],
  350. mixins: [resToken],
  351. data() {
  352. const validateusername = (rule, value, callback) => {
  353. if (value === "") {
  354. callback(new Error("账号不能为空!"));
  355. } else {
  356. if (value.length < 6 || value.length > 18) {
  357. callback(new Error("账号规则为6~18位数字与字母组合!"));
  358. } else {
  359. if (isnumber(value)) {
  360. callback(new Error("账号规则为6~18位数字与字母组合!"));
  361. } else if (validAlphabets(value)) {
  362. callback(new Error("账号规则为6~18位数字与字母组合!"));
  363. } else if (!isAlphanumeric(value)) {
  364. callback(new Error("账号规则为6~18位数字与字母组合!"));
  365. } else {
  366. callback();
  367. }
  368. }
  369. }
  370. };
  371. const validatename = (rule, value, callback) => {
  372. if (value === "") {
  373. callback(new Error("真实姓名不能为空!"));
  374. } else {
  375. if (value.length < 2 || value.length > 12) {
  376. callback(new Error("真实姓名规则为2~12位汉字!"));
  377. } else {
  378. if (!isChinese(value)) {
  379. callback(new Error("真实姓名规则为2~12位汉字!"));
  380. } else if (isEmoticon(value)) {
  381. callback(new Error("真实姓名规则为2~12位汉字!"));
  382. } else {
  383. callback();
  384. }
  385. }
  386. }
  387. };
  388. const validatemobile = (rule, value, callback) => {
  389. if (value === "") {
  390. callback(new Error("手机号不能为空!"));
  391. } else {
  392. if (!isMobile(value)) {
  393. callback(new Error("手机号格式不正确!"));
  394. } else {
  395. callback();
  396. }
  397. }
  398. };
  399. const validateEmail = (rule, value, callback) => {
  400. if (value === "") {
  401. callback();
  402. } else {
  403. if (!validEmail(value)) {
  404. callback(new Error("邮箱格式不正确!"));
  405. } else {
  406. callback();
  407. }
  408. }
  409. };
  410. return {
  411. noSendNumbers: "", //收货-未发货数量
  412. noSendNum: "", //销售-未发货数量
  413. reason_options: [], //退换货原因备选项
  414. loading: false,
  415. title: "添加销售退货单",
  416. showModelThis: this.showModel,
  417. ruleForm: {
  418. get_return_num: "",
  419. outCode: "", //出库单编号
  420. return_remark: "", //退货备注
  421. return_num: "", //退货数量
  422. returnReason: [], //退货原因
  423. // email: "",
  424. // role_id: "",
  425. // status: "1",
  426. // item: [],
  427. },
  428. rulesThis: this.rules,
  429. rules: {
  430. returnReason: [
  431. {
  432. required: true,
  433. message: "请选择退货原因",
  434. // type: "array",
  435. trigger: "change",
  436. },
  437. ],
  438. return_num: [
  439. {
  440. required: true,
  441. validator: validatemobile,
  442. trigger: "blur",
  443. },
  444. ],
  445. return_remark: [
  446. {
  447. required: true,
  448. message: "请输入退货备注",
  449. trigger: "blur",
  450. },
  451. ],
  452. },
  453. tableForm: {
  454. product_go: [],
  455. get_product_go: [],
  456. },
  457. };
  458. },
  459. watch: {
  460. showModel: function (val) {
  461. this.showModelThis = val;
  462. if (val) {
  463. this.initForm();
  464. }
  465. },
  466. showModelThis(val) {
  467. if (!val) {
  468. this.$emit("cancel");
  469. }
  470. },
  471. },
  472. methods: {
  473. closeModel() {
  474. console.log("closeModel!!");
  475. },
  476. // 获取退换货原因
  477. async getReason() {
  478. this.loading = true;
  479. let model = {
  480. page: 1,
  481. size: 100,
  482. type: "5",
  483. };
  484. const res = await asyncRequest.getReason(model);
  485. if (res && res.code === 0 && res.data) {
  486. const {list}=res.data
  487. list.forEach((element) => {
  488. let obj = {
  489. value: element.result_code,
  490. label: element.result,
  491. id: element.id,
  492. };
  493. this.reason_options.push(obj);
  494. });
  495. } else if (res && res.code >= 100 && res.code <= 104) {
  496. await this.logout();
  497. } else {
  498. this.tableData = [];
  499. this.pageInfo.total = 0;
  500. }
  501. this.loading = false;
  502. },
  503. async initForm() {
  504. this.loading = true;
  505. // await this.getRole();
  506. if (this.id === "add") {
  507. this.title = "添加销售退货单";
  508. this.rulesThis = this.rules;
  509. await this.resetForm();
  510. } else {
  511. if (this.isDetail) {
  512. this.title = "添加销售退货单详情";
  513. this.rulesThis = {};
  514. } else {
  515. this.title = "修改添加销售退货单";
  516. this.rulesThis = this.rules;
  517. }
  518. await this.resetForm(this.sitem);
  519. // await this.initData()
  520. }
  521. this.getReason(); //获取退还货原因
  522. this.loading = false;
  523. },
  524. async initData() {
  525. // const res = await asyncRequest.detail({ id: this.id });
  526. // if (res && res.code === 0 && res.data) {
  527. // this.ruleForm = res.data;
  528. // this.ruleForm.role_id = this.ruleForm.role;
  529. // } else if (res && res.code >= 100 && res.code <= 104) {
  530. // await this.logout();
  531. // } else {
  532. // this.$message.warning(res.message);
  533. // }
  534. },
  535. async resetForm(sitem) {
  536. // 重置
  537. await this.$nextTick(() => {
  538. if (this.$refs.ruleForm) {
  539. this.$refs.ruleForm.resetFields();
  540. this.$refs.ruleForm.clearValidate();
  541. this.ruleForm = {
  542. return_remark: "", //退货备注
  543. return_num: "", //退货数量
  544. returnReason: [], //退货原因
  545. };
  546. }
  547. });
  548. },
  549. async submitForm() {
  550. await this.$refs.ruleForm.validate(async (valid) => {
  551. if (valid) {
  552. this.loading = true;
  553. const model = JSON.parse(JSON.stringify(this.ruleForm));
  554. model.errorCode = model.returnReason.toString();
  555. model.num = model.return_num;
  556. model.remark = model.return_remark;
  557. model.outCode = this.outCode;
  558. if (model.return_num > this.noSendNum) {
  559. this.$message.warning("退货数量不能大于未发货数量");
  560. return;
  561. }
  562. let res = {};
  563. if (this.id === "add") {
  564. delete model["id"];
  565. res = await asyncRequest.add(model);
  566. } else {
  567. res = await asyncRequest.update(model);
  568. }
  569. this.loading = false;
  570. if (res && res.code === 0) {
  571. const title = this.id === "add" ? "添加成功" : "修改成功";
  572. this.$notify.success({
  573. title,
  574. message: "",
  575. });
  576. this.showModelThis = false;
  577. // 刷新
  578. this.$emit("refresh");
  579. } else if (res && res.code >= 100 && res.code <= 104) {
  580. await this.logout();
  581. } else {
  582. this.$message.warning(res.message);
  583. }
  584. } else {
  585. console.log("error submit!!");
  586. return false;
  587. }
  588. });
  589. },
  590. //异常原因筛选
  591. //保存某一行
  592. checkRow(rowIndex, name) {
  593. if (name == "return") {
  594. const model = JSON.parse(JSON.stringify(this.ruleForm));
  595. if (Number(model.return_num) > Number(this.noSendNum)) {
  596. this.$message.warning("退货数量不能大于未发货数量");
  597. return;
  598. }
  599. const { check_value, check_remark } =
  600. this.tableForm.product_go[rowIndex];
  601. if (check_value != "" && check_remark != "") {
  602. this.tableForm.product_go[rowIndex].edit = false;
  603. } else {
  604. this.$message.warning("审核情况或审核备注不能为空");
  605. }
  606. } else if (name == "get") {
  607. const model = JSON.parse(JSON.stringify(this.ruleForm));
  608. if (Number(model.get_return_num) > Number(this.noSendNum)) {
  609. this.$message.warning("退货数量不能大于未发货数量");
  610. return;
  611. }
  612. const { check_value, check_remark } =
  613. this.tableForm.get_product_go[rowIndex];
  614. if (check_value != "" && check_remark != "") {
  615. this.tableForm.get_product_go[rowIndex].edit = false;
  616. } else {
  617. this.$message.warning("审核情况或审核备注不能为空");
  618. }
  619. }
  620. },
  621. //编辑某一行
  622. editRow(rowIndex, name) {
  623. if (name == "return") {
  624. let index = this.tableForm.product_go.findIndex((v) => {
  625. v.edit;
  626. });
  627. if (index !== -1) {
  628. this.$message.warning("请完成其他行的编辑!");
  629. return;
  630. } else {
  631. this.tableForm.product_go[rowIndex].edit = true;
  632. }
  633. } else if (name == "get") {
  634. let index = this.tableForm.product_go.findIndex((v) => {
  635. v.edit;
  636. });
  637. if (index !== -1) {
  638. this.$message.warning("请完成其他行的编辑!");
  639. return;
  640. } else {
  641. this.tableForm.get_product_go[rowIndex].edit = true;
  642. }
  643. }
  644. },
  645. resetRow(rowIndex) {
  646. this.tableForm.product_go[rowIndex].check_remark = "";
  647. this.tableForm.product_go[rowIndex].check_value = "agree";
  648. },
  649. },
  650. };
  651. </script>
  652. <style lang="scss" scoped>
  653. .sellReturnList {
  654. }
  655. </style>