addSupply.vue 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogVisible" width="40%" :before-close="closePop" >
  3. <!-- :before-close="handleClose" 如需要可添加进上方 -->
  4. <div>
  5. <el-form
  6. :inline="true"
  7. :model="supplier"
  8. class="demo-form-inline"
  9. label-width="100px"
  10. :rules="rules"
  11. ref="supplier"
  12. >
  13. <el-row>
  14. <el-col :span="6">
  15. <el-form-item label="供应商编码" prop="supplierCode">
  16. <el-input v-model="supplier.supplierCode"></el-input>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :span="6">
  20. <el-form-item label="供应商名称" prop="supplierName">
  21. <el-input v-model="supplier.supplierName"></el-input>
  22. </el-form-item>
  23. </el-col>
  24. </el-row>
  25. <el-row>
  26. <el-col :span="6">
  27. <el-form-item label="供应商类别" prop="supplierType">
  28. <!-- <el-input v-model="supplier.type"></el-input> -->
  29. <!-- <el-autocomplete
  30. v-model="supplier.supplierType"
  31. :fetch-suggestions="querySearchAsync"
  32. @select="handleSelect"
  33. ></el-autocomplete> -->
  34. <el-select
  35. v-model="supplier.supplierType"
  36. @select="handleSelect"
  37. >
  38. <el-option
  39. v-for="item in supplierType"
  40. :key="item.value"
  41. :label="item.name"
  42. :value="item.value"
  43. >
  44. </el-option>
  45. </el-select>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="6">
  49. <el-form-item label="增值税税率" prop="vatRate">
  50. <el-input
  51. v-model="supplier.vatRate"
  52. @keyup.native="supplier.vatRate = oninput(supplier.vatRate)"
  53. ></el-input>%
  54. </el-form-item>
  55. </el-col>
  56. </el-row>
  57. <el-row>
  58. <el-col :span="6">
  59. <el-form-item label="纳税人识别号" prop="number">
  60. <el-input v-model="supplier.number"></el-input>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="6">
  64. <el-form-item label="开户银行" prop="bank">
  65. <el-input v-model="supplier.bank"></el-input>
  66. </el-form-item>
  67. </el-col>
  68. </el-row>
  69. <el-row>
  70. <el-col :span="6">
  71. <el-form-item label="银行账号" prop="bankAccount">
  72. <el-input v-model="supplier.bankAccount"></el-input>
  73. </el-form-item>
  74. </el-col>
  75. </el-row>
  76. </el-form>
  77. <el-form :model="recordInfo" ref="recordInfo" class="tableclass">
  78. <el-table
  79. :row-style="{ color: '#303133' }"
  80. :header-cell-style="{
  81. backgroundColor: 'rgb(245, 247, 250)',
  82. color: '#606266',
  83. }"
  84. :data="recordInfo.contacts"
  85. :class="signAndWeighBoxPatients"
  86. border
  87. style="width: 100%"
  88. max-height="450"
  89. >
  90. <!-- 联系人填写 -->
  91. <el-table-column label="联系人" align="center" width="130">
  92. <template slot="header" slot-scope="scope">
  93. <span>联系人<span style="color: red">*</span></span>
  94. </template>
  95. <!-- tableRules.name -->
  96. <template slot-scope="scope">
  97. <el-form-item
  98. :prop="'contacts.' + scope.$index + '.name'"
  99. :rules="
  100. scope.row.name != ''
  101. ? [
  102. {
  103. required: 'true',
  104. message: '请输入主要联系人',
  105. trigger: ['blur'],
  106. },
  107. ]
  108. : null
  109. "
  110. >
  111. <el-input
  112. v-model="scope.row.name"
  113. style="width: 100px; margin-top: 3px"
  114. ></el-input>
  115. </el-form-item>
  116. </template>
  117. </el-table-column>
  118. <!-- 手机填写 -->
  119. <el-table-column label="手机" align="center" width="150">
  120. <template slot-scope="scope">
  121. <el-input
  122. v-model="scope.row.phone"
  123. style="width: 120px"
  124. ></el-input>
  125. <div style="visibility: hidden">/</div>
  126. </template>
  127. </el-table-column>
  128. <!-- id填写======================================================= -->
  129. <el-table-column label="id" v-if="false">
  130. <template slot-scope="scope">
  131. <el-input v-model="scope.row.id" style="width: 100px"></el-input>
  132. <div style="visibility: hidden">/</div>
  133. </template>
  134. </el-table-column>
  135. <!-- 联系地址填写 -->
  136. <el-table-column label="联系地址" align="center" width="150">
  137. <template slot-scope="scope">
  138. <el-input
  139. v-model="scope.row.address"
  140. style="width: 120px"
  141. ></el-input>
  142. <div style="visibility: hidden">/</div>
  143. </template>
  144. </el-table-column>
  145. <!-- 首要联系人填写 -->
  146. <el-table-column align="center" width="130px">
  147. <template slot="header" slot-scope="scope">
  148. <span>首要联系人<span style="color: red">*</span></span>
  149. </template>
  150. <template slot-scope="scope">
  151. <el-form-item :prop="'contacts.' + scope.$index + '.name'">
  152. <!-- :prop="'contacts.' + scope.$index + '.name'" 如需添加可在上方标签加入 -->
  153. <el-select
  154. v-model="scope.row.is_first"
  155. style="width: 110px"
  156. @change="changeName($event, scope)"
  157. >
  158. <el-option
  159. v-for="(item, index) in tabList"
  160. :key="index"
  161. :label="item.label"
  162. :value="item.value"
  163. >
  164. </el-option>
  165. </el-select>
  166. </el-form-item>
  167. </template>
  168. </el-table-column>
  169. <el-table-column
  170. label="操作"
  171. align="center"
  172. width="150px"
  173. fixed="right"
  174. >
  175. <template slot-scope="scope">
  176. <el-tooltip
  177. class="item"
  178. effect="dark"
  179. content="新增"
  180. placement="top"
  181. >
  182. <el-button
  183. size="mini"
  184. type="primary"
  185. icon="el-icon-circle-plus-outline"
  186. @click="handleAdd(scope.$index, scope.row)"
  187. >
  188. </el-button>
  189. </el-tooltip>
  190. <el-tooltip
  191. class="item"
  192. effect="dark"
  193. content="删除"
  194. placement="top"
  195. >
  196. <el-button
  197. size="mini"
  198. type="danger"
  199. icon="el-icon-delete"
  200. @click="handleDelete(scope.$index, scope.row)"
  201. >
  202. </el-button>
  203. </el-tooltip>
  204. </template>
  205. </el-table-column>
  206. </el-table>
  207. </el-form>
  208. </div>
  209. <span slot="footer" class="dialog-footer">
  210. <el-button @click="closePop">取 消</el-button>
  211. <el-button type="primary" @click="submitForm('supplier', 'recordInfo')"
  212. >确 定</el-button
  213. >
  214. </span>
  215. </el-dialog>
  216. </template>
  217. <script>
  218. import {
  219. getSupplierId,
  220. getsupplytype,
  221. getsupplyandcontactone,
  222. delcontactone,
  223. savesupply,
  224. updatesupply,
  225. getexporthistory,
  226. } from "@/api/supply";
  227. import Template from "../../data/template.vue";
  228. export default {
  229. data() {
  230. return {
  231. show_type: 1,
  232. supplier_ids: "",
  233. title: "",
  234. Template,
  235. supplierType: [],
  236. signAndWeighBoxPatients: "sign-and-weigh-box-patients",
  237. list: ["001", "002"],
  238. // 表单验证规则
  239. rules: {
  240. supplierCode: [
  241. {
  242. required: true,
  243. message: "请填写供应商编号",
  244. trigger: "blur",
  245. },
  246. ],
  247. supplierName: [
  248. {
  249. required: true,
  250. message: "请填写供应商名称",
  251. trigger: "blur",
  252. },
  253. ],
  254. },
  255. tabList: [
  256. {
  257. value: 1,
  258. label: "是",
  259. },
  260. {
  261. value: 0,
  262. label: "否",
  263. },
  264. ],
  265. tableRules: {
  266. name: [{ required: true, message: "联系人不能为空", trigger: "blur" }],
  267. },
  268. recordInfo: {
  269. contacts: [{}],
  270. },
  271. tableData: [
  272. {
  273. id: "",
  274. contacts: "",
  275. phone: "",
  276. address: "",
  277. FirstConcats: "",
  278. operate: "",
  279. },
  280. ],
  281. dialogVisible: false,
  282. supplier: {
  283. supplierName: "",
  284. supplierCode: "gsy001",
  285. supplierType: "请选择类别",
  286. vatRate: 0,
  287. number: "",
  288. bank: "",
  289. bankAccount: "",
  290. },
  291. supply_code: [],
  292. select_supply: [],
  293. type: "",
  294. timeout: null,
  295. id: "",
  296. name: "",
  297. };
  298. },
  299. created() {},
  300. methods: {
  301. show(data, type) {
  302. if (type == 1) {
  303. this.initSupplierData();
  304. this.show_type = 1;
  305. this.title = "新增供应商";
  306. this.getsupplytype();
  307. this.dialogVisible = true;
  308. } else if (type == 2) {
  309. this.getsupplytype();
  310. // console.log(data,'oop')
  311. this.show_type = 2;
  312. this.supplier_ids = data.ID;
  313. this.title = "编辑供应商";
  314. this.supplier.supplierCode = data.SupplierCode;
  315. this.supplier.supplierName = data.SupplierName;
  316. this.supplier.supplierType = data.SupplierType;
  317. this.supplier.vatRate = data.VatRate;
  318. this.supplier.number = data.Number;
  319. this.supplier.bank = data.Bank;
  320. this.supplier.bankAccount = data.BankAccount;
  321. this.getcontacts(data.ID);
  322. this.dialogVisible = true;
  323. }
  324. },
  325. oninput(num) {
  326. var str = num;
  327. var len1 = str.substr(0, 1);
  328. var len2 = str.substr(1, 1);
  329. //如果第一位是0,第二位不是点,就用数字把点替换掉
  330. if (str.length > 1 && len1 == 0 && len2 != ".") {
  331. str = str.substr(1, 1);
  332. }
  333. //第一位不能是.
  334. if (len1 == ".") {
  335. str = "";
  336. }
  337. //限制只能输入一个小数点
  338. if (str.indexOf(".") != -1) {
  339. var str_ = str.substr(str.indexOf(".") + 1);
  340. if (str_.indexOf(".") != -1) {
  341. str = str.substr(0, str.indexOf(".") + str_.indexOf(".") + 1);
  342. }
  343. }
  344. //正则替换
  345. str = str.replace(/[^\d^\.]+/g, ""); // 保留数字和小数点
  346. str = str.replace(/\.\d\d\d\d$/, ""); // 小数点后只能输两位
  347. return str;
  348. },
  349. closePop() {
  350. this.dialogVisible = false;
  351. this.supply_code = [];
  352. this.supplier.supplierCode = "";
  353. this.supplier.supplierName = "";
  354. this.supplier.supplierType = "";
  355. this.supplier.vatRate = "";
  356. this.supplier.number = "";
  357. this.supplier.bank = "";
  358. this.supplier.bankAccount = "";
  359. this.recordInfo.contacts = [{}];
  360. },
  361. // 获取供应商编码接口
  362. initSupplierData() {
  363. getSupplierId().then((res) => {
  364. if (res.data.state == 1) {
  365. this.supplier.supplierCode =
  366. res.data.data.supplycode[0].supplier_code;
  367. }
  368. });
  369. },
  370. getsupplytype() {
  371. // 获取供应商类别接口
  372. getsupplytype()
  373. .then((res) => {
  374. if (res.status == 200) {
  375. this.supplierType = res.data.data.list;
  376. }
  377. })
  378. .catch((err) => {
  379. console.log(err);
  380. });
  381. },
  382. handleSelect(item) {
  383. this.supplier.name = item.value;
  384. this.supplier.value = item.name;
  385. },
  386. // 验证表单内容
  387. submitForm(supplier, formName) {
  388. if (this.show_type == 1) {
  389. this.$refs[supplier].validate((valid) => {
  390. if (valid) {
  391. this.$refs[formName].validate((valid) => {
  392. if (valid) {
  393. this.recordInfo.contacts.forEach((el) => {
  394. if (!el.phone) {
  395. el.phone = "";
  396. }
  397. if (!el.address) {
  398. el.address = "";
  399. }
  400. if (!el.id) {
  401. el.id = 0;
  402. }
  403. });
  404. let params = {
  405. suppliercode: this.supplier.supplierCode || "",
  406. suppliername: this.supplier.supplierName || "",
  407. suppliertype: this.supplier.supplierType || 0,
  408. vatrate: this.supplier.vatRate || 0,
  409. number: this.supplier.number || "",
  410. bank: this.supplier.bank || "",
  411. bankaccount: this.supplier.bankAccount || "",
  412. contacts: [...this.recordInfo.contacts],
  413. };
  414. savesupply(params).then((res) => {
  415. if (res.data.state == 1) {
  416. this.$message.success("新增成功");
  417. this.closePop();
  418. this.$emit("init");
  419. } else {
  420. this.$message.error("新增失败:"+res.data.msg);
  421. setTimeout(() => {
  422. this.closePop();
  423. }, 2000);
  424. }
  425. });
  426. } else {
  427. return false;
  428. }
  429. });
  430. } else {
  431. return false;
  432. }
  433. });
  434. } else if (this.show_type == 2) {
  435. this.$refs[supplier].validate((valid) => {
  436. if (valid) {
  437. this.$refs[formName].validate((valid) => {
  438. if (valid) {
  439. this.recordInfo.contacts.forEach((el) => {
  440. if (!el.phone) {
  441. el.phone = "";
  442. }
  443. if (!el.address) {
  444. el.address = "";
  445. }
  446. if (!el.id) {
  447. el.id = 0;
  448. }
  449. });
  450. let params = {
  451. suppliercode: this.supplier.supplierCode || "",
  452. suppliername: this.supplier.supplierName || "",
  453. id: this.supplier_ids || 0,
  454. suppliertype: this.supplier.supplierType || "",
  455. vatrate: this.supplier.vatRate || 0,
  456. number: this.supplier.number || "",
  457. bank: this.supplier.bank || "",
  458. bankaccount: this.supplier.bankAccount || "",
  459. contacts: [...this.recordInfo.contacts],
  460. };
  461. updatesupply(params).then((res) => {
  462. if (res.data.state == 1) {
  463. this.$message.success("修改成功");
  464. this.closePop();
  465. this.$emit("init");
  466. } else {
  467. this.$message.error("修改失败:"+res.data.msg);
  468. setTimeout(() => {
  469. this.closePop();
  470. }, 2000);
  471. }
  472. });
  473. } else {
  474. return false;
  475. }
  476. });
  477. } else {
  478. return false;
  479. }
  480. });
  481. }
  482. this.contactsinfo();
  483. },
  484. // 获取供应商与联系人 首次打开新增页面判断是否有首要联系人
  485. getcontacts(val) {
  486. let data = {
  487. value: 1,
  488. label: "是",
  489. };
  490. getsupplyandcontactone({ id: val }).then((res) => {
  491. if (res.data.code == 0) {
  492. this.recordInfo.contacts = res.data.data.contact;
  493. if (this.recordInfo.contacts.length == 0) {
  494. this.recordInfo.contacts = [{}];
  495. this.recordInfo.contacts[0].is_first = data.value;
  496. }
  497. // else if (this.recordInfo.contacts.length == 1) {
  498. // let val = res.data.data.contact[0];
  499. // this.recordInfo.contacts[0].is_first = data.value;
  500. // this.recordInfo.contacts[0] = {
  501. // id: parseFloat(val.id),
  502. // name: val.name,
  503. // address: val.address,
  504. // phone: val.phone,
  505. // };
  506. // }
  507. }
  508. });
  509. },
  510. // 首要联系人选择变更动态展示
  511. changeName(data, scope) {
  512. let data1 = {
  513. value: 0,
  514. label: "否",
  515. };
  516. let data2 = {
  517. value: 1,
  518. label: "是",
  519. };
  520. let arr = [];
  521. if (this.recordInfo.contacts.length <= 1) {
  522. this.recordInfo.contacts[0].is_first = data2.value;
  523. } else {
  524. this.recordInfo.contacts.forEach((el, index) => {
  525. if (scope.$index == index) {
  526. el.is_first = data;
  527. } else {
  528. el.is_first = data1.value;
  529. }
  530. arr.push(el.is_first);
  531. });
  532. if (arr.includes(1)) {
  533. return;
  534. } else {
  535. this.recordInfo.contacts[0].is_first = data2.value;
  536. }
  537. }
  538. },
  539. // 添加表单行
  540. handleAdd() {
  541. let data = {};
  542. this.recordInfo.contacts.push(data);
  543. },
  544. // 删除表单行
  545. handleDelete(index, data) {
  546. let params = {
  547. id: data.id,
  548. };
  549. if (this.show_type == 1) {
  550. if (this.recordInfo.contacts.length <= 1) {
  551. return;
  552. } else {
  553. this.recordInfo.contacts.splice(index, 1);
  554. }
  555. } else if (this.show_type == 2) {
  556. delcontactone(params).then((res) => {
  557. if (res.data.state == 1) {
  558. this.$message.success("删除成功");
  559. this.getcontacts(this.supplier_ids);
  560. } else {
  561. this.$message.error(res.data.data.list);
  562. }
  563. });
  564. }
  565. },
  566. //表格判断是否填入信息
  567. contactsinfo() {
  568. let info = this.tableData;
  569. return new Promise((resolve, reject) => {
  570. // if (info) {
  571. // resolve(info);
  572. // } else {
  573. // reject("error");
  574. info.forEach((i) => {
  575. if (
  576. i.contacts != "" &&
  577. i.phone != "" &&
  578. i.id != "" &&
  579. i.address != "" &&
  580. i.FirstConcats != ""
  581. ) {
  582. resolve(info);
  583. } else {
  584. reject("error");
  585. }
  586. });
  587. // }
  588. })
  589. .then((res) => {
  590. // console.log(res, "ooo");
  591. })
  592. .catch((err) => {
  593. // console.log(err, "ddd");
  594. });
  595. },
  596. },
  597. };
  598. </script>
  599. <style lang="scss" scoped>
  600. .demo-form-inline {
  601. .el-col-6 {
  602. width: 50%;
  603. }
  604. .el-input {
  605. width: 75%;
  606. }
  607. }
  608. .el-dialog__body {
  609. .el-form-item__content {
  610. .el-autocomplete {
  611. width: 75% !important;
  612. }
  613. .el-select.el-select--medium {
  614. width: 85% !important;
  615. }
  616. }
  617. }
  618. .tablebtn {
  619. padding: 10px 12px;
  620. }
  621. /deep/.el-form.tableclass {
  622. .el-table__header-wrapper {
  623. .el-table__header {
  624. width: 625px !important;
  625. }
  626. }
  627. .el-table__body-wrapper.is-scrolling-none {
  628. .el-table__body {
  629. width: 625px !important;
  630. }
  631. }
  632. }
  633. /deep/ .el-form-item__error {
  634. // display: none !important;
  635. }
  636. /deep/ .el-table__body-wrapper::-webkit-scrollbar {
  637. width: 10px;
  638. height: 10px;
  639. }
  640. /deep/ .el-table__fixed-right{
  641. bottom: 0 !important;
  642. }
  643. </style>