add.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div class="form">
  3. <van-nav-bar :title="$t('claim.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 #file>
  7. <div style="width:100%">
  8. <div v-for="file in formData.data.fileList" :key="file.id" style="color: #409eff;cursor: pointer;"
  9. @click="onPreviewFile(file.fileName,file.fileUrl)">
  10. {{file.fileName}}
  11. </div>
  12. </div>
  13. </template>
  14. </testForm>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { ref, reactive, getCurrentInstance, onMounted, computed } from "vue";
  19. import { showSuccessToast, showFailToast } from "vant";
  20. import { useRoute } from "vue-router";
  21. import testForm from "@/components/testForm/index.vue";
  22. const proxy = getCurrentInstance().proxy;
  23. const route = useRoute();
  24. const contractorData = ref([]);
  25. const formDom = ref(null);
  26. const formData = reactive({
  27. data: {},
  28. });
  29. const rules = {
  30. contractId: [
  31. {
  32. required: true,
  33. message: proxy.t("claim.contractCanNotBeEmpty"),
  34. },
  35. ],
  36. money: [
  37. {
  38. required: true,
  39. message: proxy.t("claim.relatedAmountCanNotBeEmpty"),
  40. },
  41. ],
  42. };
  43. const formOption = reactive({
  44. readonly: false, //用于控制整个表单是否只读
  45. disabled: false,
  46. labelAlign: "top",
  47. scroll: true,
  48. labelWidth: "62pk",
  49. submitBtnText: proxy.t("common.submit"),
  50. hiddenSubmitBtn: false,
  51. btnConfig: {
  52. isNeed: true,
  53. listTitle: proxy.t("claim.relatedContract"),
  54. prop: "claimContractList",
  55. plain: true,
  56. listConfig: [
  57. {
  58. type: "input",
  59. itemType: "text",
  60. label: "认领时间",
  61. prop: "createTime",
  62. },
  63. {
  64. type: "input",
  65. itemType: "text",
  66. label: "认领人",
  67. prop: "claimUserName",
  68. },
  69. {
  70. type: "picker",
  71. label: proxy.t("claim.contractCode"),
  72. prop: "contractId",
  73. itemType: "onePicker",
  74. showPicker: false,
  75. readonly: false,
  76. fieldNames: {
  77. text: "code",
  78. value: "id",
  79. },
  80. data: [],
  81. },
  82. {
  83. type: "input",
  84. itemType: "number",
  85. label: "认领金额",
  86. prop: "money",
  87. },
  88. ],
  89. clickFn: () => {
  90. if (
  91. formData.data.claimContractList &&
  92. formData.data.claimContractList.length > 0
  93. ) {
  94. formData.data.claimContractList.push({
  95. contractId: "",
  96. contractCode: "",
  97. money: "",
  98. });
  99. } else {
  100. formData.data.claimContractList = [
  101. {
  102. contractId: "",
  103. contractCode: "",
  104. money: "",
  105. },
  106. ];
  107. }
  108. },
  109. },
  110. });
  111. const formConfig = computed(() => [
  112. {
  113. type: "title",
  114. title: "基本信息",
  115. },
  116. {
  117. type: "input",
  118. label: "提交时间",
  119. prop: "applyTime",
  120. itemType: "text",
  121. readonly: true,
  122. },
  123. {
  124. type: "input",
  125. label: "提交人",
  126. prop: "createUserName",
  127. itemType: "text",
  128. readonly: true,
  129. },
  130. {
  131. type: "input",
  132. label: "所属公司",
  133. prop: "companyName",
  134. itemType: "text",
  135. readonly: true,
  136. },
  137. {
  138. type: "input",
  139. label: "所属部门",
  140. prop: "deptName",
  141. itemType: "text",
  142. readonly: true,
  143. },
  144. {
  145. type: "picker",
  146. label: "承包单位",
  147. prop: "contractorId",
  148. itemType: "onePicker",
  149. showPicker: false,
  150. fieldNames: {
  151. text: "label",
  152. value: "value",
  153. },
  154. data: contractorData.value,
  155. readonly: false,
  156. },
  157. {
  158. type: "input",
  159. label: "账期",
  160. prop: "accountPeriod",
  161. itemType: "text",
  162. readonly: true,
  163. },
  164. {
  165. type: "input",
  166. label: "账期金额",
  167. prop: "accountPeriodAmount",
  168. itemType: "text",
  169. readonly: true,
  170. },
  171. {
  172. type: "input",
  173. label: "预付金额",
  174. prop: "prepaidAmount",
  175. itemType: "text",
  176. readonly: true,
  177. },
  178. {
  179. type: "input",
  180. label: "最终金额",
  181. prop: "finalAmount",
  182. itemType: "text",
  183. readonly: true,
  184. },
  185. {
  186. type: "input",
  187. label: "说明",
  188. prop: "remark",
  189. itemType: "textarea",
  190. readonly: true,
  191. },
  192. {
  193. type: "slot",
  194. label: "账单附件",
  195. slotName: "file",
  196. },
  197. ]);
  198. const onClickLeft = () => history.back();
  199. const getDict = () => {
  200. proxy
  201. .post("/contractor/page", {
  202. pageNum: 1,
  203. pageSize: 9999,
  204. })
  205. .then((res) => {
  206. contractorData.value = res.data.rows.map((item) => {
  207. return {
  208. label: item.name,
  209. value: item.id,
  210. };
  211. });
  212. });
  213. };
  214. onMounted(() => {
  215. getDict();
  216. formOption.btnConfig.isNeed = false;
  217. formOption.readonly = true;
  218. formOption.hiddenSubmitBtn = true;
  219. proxy.post("/epibolyBill/detail", { id: route.query.id }).then(
  220. (res) => {
  221. formData.data = res.data;
  222. let businessId = route.query.id;
  223. proxy
  224. .post("/fileInfo/getList", { businessIdList: [businessId] })
  225. .then((res) => {
  226. let fileObj = res.data;
  227. if (fileObj[businessId] && fileObj[businessId].length > 0) {
  228. formData.data.fileList = fileObj[businessId]
  229. .filter((x) => x.businessType == "0")
  230. .map((item) => {
  231. return {
  232. ...item,
  233. name: item.fileName,
  234. url: item.fileUrl,
  235. };
  236. });
  237. } else {
  238. formData.data.fileList = [];
  239. }
  240. });
  241. },
  242. (err) => {
  243. return showFailToast(err.message);
  244. }
  245. );
  246. });
  247. const onSubmit = () => {
  248. if (route.query.isClaim != "1") {
  249. if (formData.data.claimContractList.length > 0) {
  250. let list = formData.data.claimContractList;
  251. for (let i = 0; i < list.length; i++) {
  252. const e = list[i];
  253. if (!(Number(e.money) > 0)) {
  254. return showFailToast(
  255. proxy.t("claim.relatedAmountMustBeGreaterThanZero")
  256. );
  257. }
  258. }
  259. const total = list.reduce((total, x) => (total += Number(x.money)), 0);
  260. if (total > Number(formData.data.waitAmount)) {
  261. return showFailToast(
  262. proxy.t("claim.relatedAmountTotalNotBeGreaterThanAccountAmount")
  263. );
  264. }
  265. formData.data.amount = total;
  266. proxy.post("/claim/add", formData.data).then(
  267. () => {
  268. showSuccessToast(proxy.t("common.operationSuccessful"));
  269. setTimeout(() => {
  270. onClickLeft();
  271. }, 500);
  272. },
  273. (err) => {
  274. return showFailToast(err.message);
  275. }
  276. );
  277. } else {
  278. return showFailToast(proxy.t("claim.addDetails"));
  279. }
  280. } else {
  281. proxy.post("/claim/delete", { id: route.query.id }).then(
  282. () => {
  283. showSuccessToast(proxy.t("common.operationSuccessful"));
  284. setTimeout(() => {
  285. onClickLeft();
  286. }, 500);
  287. },
  288. (err) => {
  289. return showFailToast(err.message);
  290. }
  291. );
  292. }
  293. };
  294. </script>
  295. <style lang="scss" scoped>
  296. </style>