edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <div class="form">
  3. <van-nav-bar :title="$t('afterSales.name')" :left-text="$t('common.back')" left-arrow @click-left="onClickLeft">
  4. </van-nav-bar>
  5. <testForm v-model="formData.data" :formOption="formOption" :formConfig="formConfig" :rules="rules" @onSubmit="onSubmit" ref="formDom">
  6. <template #top>
  7. <div style="width: 100%">
  8. <ShowFormData :data="formData.data" :config="topConfig">
  9. </ShowFormData>
  10. </div>
  11. </template>
  12. <template #file>
  13. <div style="width: 100%;">
  14. <div v-if="
  15. formData.data.fileList && formData.data.fileList.length > 0
  16. ">
  17. <span v-for="item in formData.data.fileList" :key="item.id" @click="onPreviewFile(item)"
  18. style="margin-right: 10px; cursor: pointer; color: #409eff">
  19. {{ item.name }}
  20. </span>
  21. </div>
  22. <div v-else>无</div>
  23. </div>
  24. </template>
  25. <template #fileOne>
  26. <div style="width: 100%">
  27. <van-uploader v-model="formData.data.fileListOne" multiple :show-upload="false" />
  28. </div>
  29. </template>
  30. <template #list>
  31. <div style="width: 100%">
  32. <van-collapse v-model="activeNames">
  33. <van-collapse-item v-for="(item, index) in formData.data.bomDetailList" :key="item.id" :name="item.id"
  34. :value="'[ ' + item.quantity + ' ]'">
  35. <template #title>
  36. <div>
  37. <van-icon name="warning-o" v-if="
  38. submitData[item.productId].quantity &&
  39. submitData[item.productId].remark &&
  40. submitData[item.productId].fileList.length > 0
  41. " color="#ee0a24" style="margin-right: 5px" />
  42. {{ item.productName }}
  43. </div>
  44. </template>
  45. <div>
  46. <van-field v-model="submitData[item.productId].quantity" label="售后数量" type="digit" placeholder="请输入" label-align="top" />
  47. <van-field v-model="submitData[item.productId].remark" label="售后说明" type="textarea" placeholder="请输入" label-align="top" />
  48. <van-field name="uploader" label="现场照片">
  49. <template #input>
  50. <van-uploader v-model="submitData[item.productId].fileList" :after-read="afterRead" multiple :max-size="5 * 1024 * 1024"
  51. @oversize="onOversize" />
  52. </template>
  53. </van-field>
  54. </div>
  55. </van-collapse-item>
  56. </van-collapse>
  57. <!-- <div
  58. v-for="(item, index) in formData.data.bomDetailList"
  59. :key="index"
  60. >
  61. <ShowFormData
  62. :data="item"
  63. :config="listConfig"
  64. :showMore="
  65. item.afterSalesRecordDetail || route.query.status == 0
  66. ? true
  67. : false
  68. "
  69. @onClickItem="handleClickItem(item)"
  70. >
  71. </ShowFormData>
  72. </div> -->
  73. </div>
  74. </template>
  75. </testForm>
  76. </div>
  77. </template>
  78. <script setup>
  79. import { ref, reactive, getCurrentInstance, onMounted, watch } from "vue";
  80. import { showSuccessToast, showFailToast } from "vant";
  81. import { useRoute } from "vue-router";
  82. import testForm from "@/components/testForm/index.vue";
  83. import ShowFormData from "@/components/ShowFormData.vue";
  84. const proxy = getCurrentInstance().proxy;
  85. const route = useRoute();
  86. const formDom = ref(null);
  87. const activeNames = ref([]);
  88. const formData = reactive({
  89. data: {
  90. fileListOne: [],
  91. fileList: [],
  92. },
  93. });
  94. const rules = {
  95. afterSalesRemark: [
  96. {
  97. required: true,
  98. message: "请输入其他问题",
  99. },
  100. ],
  101. amount: [
  102. {
  103. required: true,
  104. message: "请输入售后金额",
  105. },
  106. ],
  107. };
  108. const formOption = reactive({
  109. readonly: false, //用于控制整个表单是否只读
  110. disabled: false,
  111. labelAlign: "top",
  112. scroll: true,
  113. labelWidth: "62pk",
  114. hiddenSubmitBtn: false,
  115. });
  116. const formConfig = reactive([
  117. {
  118. type: "slot",
  119. slotName: "top",
  120. },
  121. {
  122. type: "slot",
  123. label: "售后附件",
  124. slotName: "fileOne",
  125. },
  126. // {
  127. // type: "upload",
  128. // label: "售后附件",
  129. // readonly: true,
  130. // showUpload: false,
  131. // prop: "fileListOne",
  132. // },
  133. {
  134. type: "title",
  135. title: "配件问题",
  136. },
  137. {
  138. type: "slot",
  139. slotName: "list",
  140. },
  141. {
  142. type: "title",
  143. title: "其他问题",
  144. },
  145. {
  146. type: "input",
  147. itemType: "textarea",
  148. label: "",
  149. prop: "afterSalesRemark",
  150. },
  151. {
  152. type: "title",
  153. title: "售后金额",
  154. },
  155. {
  156. type: "input",
  157. itemType: "number",
  158. label: "",
  159. prop: "amount",
  160. clearable: true,
  161. },
  162. {
  163. type: "title",
  164. title: proxy.t("afterSales.programFile"),
  165. },
  166. // {
  167. // type: "upload",
  168. // label: " ",
  169. // readonly: true,
  170. // showUpload: false,
  171. // prop: "fileList",
  172. // },
  173. {
  174. type: "slot",
  175. slotName: "file",
  176. },
  177. ]);
  178. const topConfig = ref([
  179. {
  180. label: proxy.t("afterSales.afterSalesCode"),
  181. prop: "code",
  182. },
  183. {
  184. label: proxy.t("afterSales.productSN"),
  185. prop: "productSn",
  186. },
  187. {
  188. label: proxy.t("afterSales.productName"),
  189. prop: "productName",
  190. },
  191. {
  192. label: "规格型号",
  193. prop: "productSpec",
  194. },
  195. {
  196. label: "售后类型",
  197. prop: "typeName",
  198. },
  199. {
  200. label: "售后说明",
  201. prop: "remark",
  202. },
  203. {
  204. label: "客户联系人",
  205. prop: "contactName",
  206. },
  207. {
  208. label: "客户联系方式",
  209. prop: "contactInfo",
  210. },
  211. {
  212. label: "售后人员",
  213. prop: "afterSalesPersonIdName",
  214. },
  215. ]);
  216. const listConfig = ref([
  217. {
  218. label: proxy.t("afterSales.accessoriesName"),
  219. prop: "productName",
  220. },
  221. {
  222. label: proxy.t("afterSales.quantity"),
  223. prop: "quantity",
  224. },
  225. ]);
  226. const onClickLeft = () => history.back();
  227. const submitData = ref({});
  228. const afterSalesType = ref([]);
  229. const userList = ref([]);
  230. const getDetails = async (id) => {
  231. const data1 = await proxy.getDictOne(["after_sales_type"]);
  232. afterSalesType.value = data1["after_sales_type"].data.map((x) => ({
  233. label: x.dictValue,
  234. value: x.dictKey,
  235. }));
  236. const data2 = await proxy.get("/system/user/list?pageNum=1&pageSize=9999");
  237. userList.value = data2.rows.map((item) => {
  238. return {
  239. label: item.userName,
  240. value: item.userId,
  241. };
  242. });
  243. const status = route.query.status;
  244. proxy.post("/afterSalesRecord/detail", { id }).then(async (res) => {
  245. if (status == 0) {
  246. for (let i = 0; i < res.data.bomDetailList.length; i++) {
  247. const e = res.data.bomDetailList[i];
  248. submitData.value[e.productId] = {
  249. accessoriesId: e.productId,
  250. productName: e.productName,
  251. quantity: null,
  252. remark: "",
  253. fileList: [],
  254. };
  255. }
  256. formData.data = res.data;
  257. } else {
  258. let arr = res.data.bomDetailList.map((x) => x.afterSalesRecordDetail.id);
  259. for (let i = 0; i < res.data.bomDetailList.length; i++) {
  260. const e = res.data.bomDetailList[i];
  261. submitData.value[e.productId] = {
  262. accessoriesId: e.productId,
  263. productName: e.productName,
  264. quantity: e.afterSalesRecordDetail.quantity,
  265. remark: e.afterSalesRecordDetail.remark,
  266. fileList: [],
  267. };
  268. }
  269. formData.data = res.data;
  270. const fileObj = await proxy.post("/fileInfo/getList", {
  271. businessIdList: arr,
  272. });
  273. for (let i = 0; i < res.data.bomDetailList.length; i++) {
  274. const e = res.data.bomDetailList[i];
  275. for (const key in fileObj.data) {
  276. if (e.afterSalesRecordDetail.id == key) {
  277. submitData.value[e.productId].fileList = fileObj.data[key].map(
  278. (item) => ({
  279. raw: item,
  280. name: item.fileName,
  281. url: item.fileUrl,
  282. })
  283. );
  284. }
  285. }
  286. }
  287. }
  288. proxy
  289. .post("/fileInfo/getList", {
  290. businessIdList: [id],
  291. })
  292. .then((fileObj) => {
  293. if (fileObj.data && fileObj.data[id]) {
  294. formData.data.fileListOne = fileObj.data[id].map((x) => ({
  295. raw: x,
  296. name: x.fileName,
  297. url: x.fileUrl,
  298. }));
  299. console.log(formData.data.fileListOne, "asda");
  300. }
  301. });
  302. if (res.data.bomInfoId) {
  303. proxy
  304. .post("/fileInfo/getList", { businessIdList: [res.data.bomInfoId] })
  305. .then((file) => {
  306. formData.data.fileList = file.data[res.data.bomInfoId].map((x) => ({
  307. ...x,
  308. name: x.fileName,
  309. url: x.fileUrl,
  310. }));
  311. });
  312. }
  313. let typeName = afterSalesType.value.find((x) => x.value == res.data.type);
  314. if (typeName) {
  315. formData.data.typeName = typeName.label;
  316. }
  317. let userName = userList.value.find(
  318. (x) => x.value == res.data.afterSalesPersonId
  319. );
  320. if (userName) {
  321. formData.data.afterSalesPersonIdName = userName.label;
  322. }
  323. });
  324. };
  325. onMounted(() => {
  326. if (route.query.id) {
  327. getDetails(route.query.id);
  328. if (route.query.status == 1) {
  329. formOption.hiddenSubmitBtn = true; //隐藏提交按钮
  330. formOption.readonly = true;
  331. }
  332. }
  333. });
  334. const onSubmit = () => {
  335. let arr = Object.values(submitData.value);
  336. for (let i = 0; i < arr.length; i++) {
  337. const e = arr[i];
  338. if (e.quantity || e.remark.trim() || e.fileList.length > 0) {
  339. if (!e.quantity) {
  340. return showFailToast(`请填写${e.productName}配件的售后数量`);
  341. }
  342. if (!e.remark.trim()) {
  343. return showFailToast(`请填写${e.productName}配件的售后说明`);
  344. }
  345. if (e.fileList.length == 0) {
  346. return showFailToast(`请上传${e.productName}配件的现场照片`);
  347. }
  348. }
  349. }
  350. if (!(Number(formData.data.amount) > 0)) {
  351. return showFailToast(`售后金额需大于0`);
  352. }
  353. proxy
  354. .post("/afterSalesRecord/afterSales", {
  355. id: formData.data.id,
  356. afterSalesRemark: formData.data.afterSalesRemark,
  357. amount: formData.data.amount,
  358. afterSalesRecordDetailList: arr,
  359. })
  360. .then(
  361. () => {
  362. showSuccessToast(proxy.t("afterSales.operationSuccessful"));
  363. setTimeout(() => {
  364. onClickLeft();
  365. }, 500);
  366. },
  367. (err) => {
  368. return showFailToast(err.message);
  369. }
  370. );
  371. };
  372. const handleClickItem = (item) => {
  373. if (item.afterSalesRecordDetail || route.query.status == 0) {
  374. proxy.$router.push({
  375. path: "jxskAfterSalesEditItem",
  376. query: {
  377. data: JSON.stringify({
  378. bomDetailList: [item],
  379. code: formData.data.code,
  380. productName: formData.data.productName,
  381. productSn: formData.data.productSn,
  382. remark: item.afterSalesRecordDetail
  383. ? item.afterSalesRecordDetail.remark
  384. : "",
  385. fileList: [],
  386. status: route.query.status,
  387. }),
  388. },
  389. });
  390. }
  391. };
  392. const afterRead = (file) => {
  393. if (file && file.length > 0) {
  394. for (let i = 0; i < file.length; i++) {
  395. file[i].status = "uploading";
  396. file[i].message = "上传中...";
  397. proxy.post("/fileInfo/getSing", { fileName: file[i].file.name }).then(
  398. (res) => {
  399. let forms = new FormData();
  400. forms.append("file", file[i].file);
  401. proxy
  402. .post("https://winfaster.obs.cn-south-1.myhuaweicloud.com", {
  403. ...res.data.uploadBody,
  404. file: forms.get("file"),
  405. })
  406. .then(
  407. () => {
  408. file[i].id = res.data.id;
  409. file[i].url = res.data.fileUrl;
  410. file[i].fileName = res.data.fileName;
  411. delete file[i].status;
  412. delete file[i].message;
  413. },
  414. () => {
  415. file[i].status = "failed";
  416. file[i].message = "上传失败";
  417. }
  418. );
  419. },
  420. () => {
  421. file[i].status = "failed";
  422. file[i].message = "上传失败";
  423. }
  424. );
  425. }
  426. } else {
  427. file.status = "uploading";
  428. file.message = "上传中...";
  429. proxy.post("/fileInfo/getSing", { fileName: file.file.name }).then(
  430. (res) => {
  431. let forms = new FormData();
  432. forms.append("file", file.file);
  433. proxy
  434. .post("https://winfaster.obs.cn-south-1.myhuaweicloud.com", {
  435. ...res.data.uploadBody,
  436. file: forms.get("file"),
  437. })
  438. .then(
  439. () => {
  440. file.id = res.data.id;
  441. file.url = res.data.fileUrl;
  442. file.fileName = res.data.fileName;
  443. delete file.status;
  444. delete file.message;
  445. },
  446. () => {
  447. file.status = "failed";
  448. file.message = "上传失败";
  449. }
  450. );
  451. },
  452. () => {
  453. file.status = "failed";
  454. file.message = "上传失败";
  455. }
  456. );
  457. }
  458. };
  459. // 文件上传
  460. const onOversize = () => {
  461. showToast("文件大小不能超过 5MB");
  462. };
  463. watch(
  464. () => formData.data.fileList,
  465. (val) => {
  466. console.log(val, "a");
  467. }
  468. );
  469. const onPreviewFile = (item) => {
  470. uni.postMessage({
  471. data: {
  472. type: "file",
  473. url: item.url,
  474. name: item.name,
  475. },
  476. });
  477. };
  478. </script>
  479. <style lang="scss" scoped>
  480. .form {
  481. margin-bottom: 60px;
  482. }
  483. ::v-deep {
  484. .van-field--label-top .van-icon-arrow {
  485. right: -2px;
  486. top: -12px;
  487. }
  488. .van-cell__value {
  489. padding-right: 10px;
  490. }
  491. }
  492. </style>