index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div>
  3. <el-card class="box-card">
  4. <byTable
  5. :source="sourceList.data"
  6. :pagination="sourceList.pagination"
  7. :config="config"
  8. :loading="loading"
  9. :searchConfig="searchConfig"
  10. highlight-current-row
  11. :action-list="[
  12. {
  13. text: '添加供应商',
  14. action: () => clickModal(),
  15. },
  16. ]"
  17. @get-list="getList"
  18. @clickReset="clickReset">
  19. <template #contactPerson="{ item }">
  20. <div>
  21. {{ item.contactPerson1 }} {{ item.contactNumber1 }}, {{ item.contactPerson2 }} {{ item.contactNumber2 }}, {{ item.contactPerson3 }}
  22. {{ item.contactNumber3 }}
  23. </div>
  24. </template>
  25. </byTable>
  26. </el-card>
  27. <el-dialog :title="modalType == 'add' ? '添加供应商' : '编辑供应商'" v-if="openDialog" v-model="openDialog" width="900">
  28. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  29. <template #contactPerson1>
  30. <div style="width: 100%">
  31. <el-row :gutter="10">
  32. <el-col :span="8">
  33. <el-input v-model="formData.data.contactPerson1" placeholder="请输入姓名" />
  34. </el-col>
  35. <el-col :span="8">
  36. <el-input v-model="formData.data.contactNumber1" placeholder="请输入电话" />
  37. </el-col>
  38. <el-col :span="8">
  39. <el-input v-model="formData.data.contactMailbox1" placeholder="请输入邮箱" />
  40. </el-col>
  41. </el-row>
  42. </div>
  43. </template>
  44. <template #contactPerson2>
  45. <div style="width: 100%">
  46. <el-row :gutter="10">
  47. <el-col :span="8">
  48. <el-input v-model="formData.data.contactPerson2" placeholder="请输入姓名" />
  49. </el-col>
  50. <el-col :span="8">
  51. <el-input v-model="formData.data.contactNumber2" placeholder="请输入电话" />
  52. </el-col>
  53. <el-col :span="8">
  54. <el-input v-model="formData.data.contactMailbox2" placeholder="请输入邮箱" />
  55. </el-col>
  56. </el-row>
  57. </div>
  58. </template>
  59. <template #contactPerson3>
  60. <div style="width: 100%">
  61. <el-row :gutter="10">
  62. <el-col :span="8">
  63. <el-input v-model="formData.data.contactPerson3" placeholder="请输入姓名" />
  64. </el-col>
  65. <el-col :span="8">
  66. <el-input v-model="formData.data.contactNumber3" placeholder="请输入电话" />
  67. </el-col>
  68. <el-col :span="8">
  69. <el-input v-model="formData.data.contactMailbox3" placeholder="请输入邮箱" />
  70. </el-col>
  71. </el-row>
  72. </div>
  73. </template>
  74. </byForm>
  75. <template #footer>
  76. <el-button @click="openDialog = false" size="large">取 消</el-button>
  77. <el-button type="primary" @click="submitForm()" size="large" v-preReClick>确 定</el-button>
  78. </template>
  79. </el-dialog>
  80. </div>
  81. </template>
  82. <script setup>
  83. import byTable from "@/components/byTable/index";
  84. import byForm from "@/components/byForm/index";
  85. import { ElMessage, ElMessageBox } from "element-plus";
  86. const { proxy } = getCurrentInstance();
  87. const sourceList = ref({
  88. data: [],
  89. pagination: {
  90. total: 0,
  91. pageNum: 1,
  92. pageSize: 10,
  93. name: "",
  94. },
  95. });
  96. const loading = ref(false);
  97. const searchConfig = computed(() => {
  98. return [
  99. {
  100. type: "input",
  101. prop: "name",
  102. label: "供应商名称",
  103. },
  104. ];
  105. });
  106. const config = computed(() => {
  107. return [
  108. {
  109. attrs: {
  110. label: "供应商名称",
  111. prop: "name",
  112. },
  113. },
  114. {
  115. attrs: {
  116. label: "账期",
  117. prop: "paymentPeriod",
  118. width: 120,
  119. },
  120. },
  121. {
  122. attrs: {
  123. label: "电话",
  124. prop: "companyTelephone",
  125. width: 160,
  126. },
  127. },
  128. {
  129. attrs: {
  130. label: "联系方式",
  131. slot: "contactPerson",
  132. width: 200,
  133. },
  134. },
  135. {
  136. attrs: {
  137. label: "省份",
  138. prop: "province",
  139. width: 140,
  140. },
  141. },
  142. {
  143. attrs: {
  144. label: "城市",
  145. prop: "city",
  146. width: 140,
  147. },
  148. },
  149. {
  150. attrs: {
  151. label: "地址",
  152. prop: "detailedAddress",
  153. width: 240,
  154. },
  155. },
  156. {
  157. attrs: {
  158. label: "操作",
  159. width: 120,
  160. align: "center",
  161. fixed: "right",
  162. },
  163. renderHTML(row) {
  164. return [
  165. {
  166. attrs: {
  167. label: "编辑",
  168. type: "primary",
  169. text: true,
  170. },
  171. el: "button",
  172. click() {
  173. clickUpdate(row);
  174. },
  175. },
  176. {
  177. attrs: {
  178. label: "删除",
  179. type: "danger",
  180. text: true,
  181. },
  182. el: "button",
  183. click() {
  184. clickDelete(row);
  185. },
  186. },
  187. ];
  188. },
  189. },
  190. ];
  191. });
  192. const getList = async (req, status) => {
  193. if (status) {
  194. sourceList.value.pagination = {
  195. pageNum: sourceList.value.pagination.pageNum,
  196. pageSize: sourceList.value.pagination.pageSize,
  197. };
  198. } else {
  199. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  200. }
  201. loading.value = true;
  202. proxy.post("/supplier/page", sourceList.value.pagination).then((res) => {
  203. sourceList.value.data = res.rows;
  204. sourceList.value.pagination.total = res.total;
  205. setTimeout(() => {
  206. loading.value = false;
  207. }, 200);
  208. });
  209. };
  210. getList();
  211. const clickReset = () => {
  212. getList("", true);
  213. };
  214. const modalType = ref("add");
  215. const openDialog = ref(false);
  216. const submit = ref(null);
  217. const formOption = reactive({
  218. inline: true,
  219. labelWidth: "100px",
  220. itemWidth: 100,
  221. rules: [],
  222. labelPosition: "right",
  223. });
  224. const formData = reactive({
  225. data: {},
  226. });
  227. const formConfig = computed(() => {
  228. return [
  229. {
  230. type: "title",
  231. title: "基本信息",
  232. label: "",
  233. },
  234. {
  235. type: "input",
  236. prop: "name",
  237. label: "供应商名称",
  238. itemType: "text",
  239. },
  240. {
  241. type: "input",
  242. prop: "companyTelephone",
  243. label: "公司电话",
  244. itemType: "text",
  245. itemWidth: 50,
  246. },
  247. {
  248. type: "input",
  249. prop: "paymentPeriod",
  250. label: "账期",
  251. itemType: "text",
  252. itemWidth: 50,
  253. },
  254. {
  255. type: "input",
  256. prop: "province",
  257. label: "省份",
  258. itemType: "text",
  259. itemWidth: 50,
  260. },
  261. {
  262. type: "input",
  263. prop: "city",
  264. label: "城市",
  265. itemType: "text",
  266. itemWidth: 50,
  267. },
  268. {
  269. type: "input",
  270. prop: "detailedAddress",
  271. label: "地址",
  272. itemType: "text",
  273. },
  274. {
  275. type: "input",
  276. prop: "dutyNumber",
  277. label: "税号",
  278. itemType: "text",
  279. },
  280. {
  281. type: "title",
  282. title: "联系人信息",
  283. label: "",
  284. },
  285. {
  286. type: "slot",
  287. slotName: "contactPerson1",
  288. label: "联系人1",
  289. },
  290. {
  291. type: "slot",
  292. slotName: "contactPerson2",
  293. label: "联系人2",
  294. },
  295. {
  296. type: "slot",
  297. slotName: "contactPerson3",
  298. label: "联系人3",
  299. },
  300. {
  301. type: "title",
  302. title: "银行账户信息",
  303. label: "",
  304. },
  305. {
  306. type: "input",
  307. prop: "bank",
  308. label: "银行",
  309. itemType: "text",
  310. itemWidth: 50,
  311. },
  312. {
  313. type: "input",
  314. prop: "bankAccountName",
  315. label: "账户名",
  316. itemType: "text",
  317. itemWidth: 50,
  318. },
  319. {
  320. type: "input",
  321. prop: "bankAccountNumber",
  322. label: "账号",
  323. itemType: "text",
  324. itemWidth: 50,
  325. },
  326. ];
  327. });
  328. const rules = ref({
  329. name: [{ required: true, message: "请输入供应商名称", trigger: "blur" }],
  330. });
  331. const clickModal = () => {
  332. modalType.value = "add";
  333. formData.data = {};
  334. openDialog.value = true;
  335. };
  336. const submitForm = () => {
  337. submit.value.handleSubmit(() => {
  338. proxy.post("/supplier/" + modalType.value, formData.data).then(() => {
  339. ElMessage({
  340. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  341. type: "success",
  342. });
  343. openDialog.value = false;
  344. getList();
  345. });
  346. });
  347. };
  348. const clickUpdate = (row) => {
  349. modalType.value = "edit";
  350. proxy.post("/supplier/detail", { id: row.id }).then((res) => {
  351. formData.data = res;
  352. openDialog.value = true;
  353. });
  354. };
  355. const clickDelete = (row) => {
  356. ElMessageBox.confirm("你是否确认此操作", "提示", {
  357. confirmButtonText: "确定",
  358. cancelButtonText: "取消",
  359. type: "warning",
  360. })
  361. .then(() => {
  362. proxy.post("/supplier/delete", { id: row.id }).then(() => {
  363. ElMessage({ message: "删除成功", type: "success" });
  364. getList();
  365. });
  366. })
  367. .catch(() => {});
  368. };
  369. </script>
  370. <style lang="scss" scoped>
  371. ::v-deep(.el-input-number .el-input__inner) {
  372. text-align: left;
  373. }
  374. </style>