index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <script>
  2. import orderApi from "@/api/business/purchase/purchase-order";
  3. import { initColumns, initDicts, initRules, initParams } from "@/utils/init";
  4. import { Columns, TabColumns } from "./column";
  5. const NewColumns = initColumns(Columns);
  6. const NewTabColumns = TabColumns.map((element) => ({
  7. ...element,
  8. tableColumns: initColumns(element.tableColumns),
  9. }));
  10. const SelectColumns = NewColumns.filter(
  11. (column) => column.inputType === "Select"
  12. );
  13. NewTabColumns.forEach((column) => {
  14. SelectColumns.push(
  15. ...column.tableColumns.filter((cColumn) => cColumn.inputType === "Select")
  16. );
  17. });
  18. export default {
  19. name: "AddPurchaseOrderDrawer",
  20. dicts: initDicts(SelectColumns),
  21. components: {
  22. FileUploadCenter: () => import("../components/FileUploadCenter/index.vue"),
  23. popDialog: () => import("@/components/PopDialog/index.vue"),
  24. },
  25. data() {
  26. return {
  27. visible: false,
  28. columns: NewColumns,
  29. rules: initRules(NewColumns),
  30. params: {
  31. ...initParams(NewColumns),
  32. puOrderItemList: [],
  33. puOrderExecuteList: [],
  34. },
  35. tabColumns: NewTabColumns,
  36. tabName: "puOrderItemList",
  37. };
  38. },
  39. computed: {},
  40. watch: {
  41. "params.puOrderItemList": {
  42. handler(nVal, oVal) {
  43. this.visible &&
  44. this.handleSynchronousMaterial(
  45. "puOrderItemList",
  46. "puOrderExecuteList"
  47. );
  48. },
  49. deep: true,
  50. },
  51. "params.puOrderExecuteList": {
  52. handler(nVal, oVal) {
  53. this.visible &&
  54. this.handleSynchronousMaterial(
  55. "puOrderExecuteList",
  56. "puOrderItemList"
  57. );
  58. },
  59. deep: true,
  60. },
  61. params: {
  62. handler(nVal, oVal) {
  63. // 组织变化
  64. if (this.visible && nVal.puOrg != oVal.puOrg) {
  65. console.log(nVal.puOrg, "nVal.puOrg", oVal.puOrg, "oVal.puOrg");
  66. for (const key in this.params) {
  67. if (Array.isArray(this.params[key])) {
  68. this.params[key] = [];
  69. } else if (
  70. key != "puOrg" &&
  71. key != "puOrgName" &&
  72. key != "buyer" &&
  73. key != "buyerName" &&
  74. key != "puDept" &&
  75. key != "puDeptName" &&
  76. key != "status"
  77. ) {
  78. this.params[key] = "";
  79. } else {
  80. }
  81. }
  82. }
  83. },
  84. deep: true,
  85. },
  86. },
  87. methods: {
  88. beforeOpen() {
  89. const { deptName, deptId, name, nickName, orgName, orgId } = this.$store.state.user;
  90. this.params.puOrg = orgId;
  91. this.params.puOrgName = orgName;
  92. this.params.buyer = name;
  93. this.params.buyerName = nickName;
  94. this.params.puDept = deptId;
  95. this.params.puDeptName = deptName;
  96. this.params.billDate = new Date().Format('yyyy-MM-dd');
  97. this.addTableRow();
  98. },
  99. setVisible(prop) {
  100. this.visible = prop;
  101. if(!this.visible){
  102. this.$refs['orderAddForm'].clearValidate();
  103. }
  104. },
  105. // 复制赋值
  106. async setCopyParams(id) {
  107. console.log(id, "iid-----------------------");
  108. try {
  109. const { code, msg, data } = await orderApi.details(id);
  110. if (code === 200) {
  111. this.params = {
  112. ...data,
  113. id: "",
  114. code: "",
  115. status: "0",
  116. source: "3",
  117. };
  118. for (const key in this.params) {
  119. if (Array.isArray(this.params[key])) {
  120. this.params[key].forEach((v) => {
  121. v.id = "";
  122. });
  123. }
  124. }
  125. }
  126. } catch (err) {
  127. //
  128. } finally {
  129. // this.loading = false;
  130. }
  131. },
  132. // 增行
  133. addTableRow(prop) {
  134. for (const key in this.params) {
  135. // if (Array.isArray(this.params[key])) {
  136. if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
  137. const arr = this.tabColumns.find(
  138. (element) => element.key === key
  139. ).tableColumns;
  140. let rowData = initParams(arr, "key", "value");
  141. "rowno" in rowData &&
  142. (rowData["rowno"] = this.params[key].length + 1);
  143. // 物料
  144. if("rowNo" in rowData){
  145. rowData["rowNo"] = this.params[key].length + 1;
  146. // 扣税类别
  147. rowData["taxDeductClassify"] = '1';
  148. // 价格类型
  149. rowData["priceType"] = 'order';
  150. // 币种
  151. rowData["currency"] = '1002Z0100000000001K1';
  152. rowData["currencyName"] = '人民币';
  153. }
  154. // 是否完成询价,新增明细行需默认明细为false
  155. rowData["whetherCompleteInquiry"] = false;
  156. this.params[key].push(rowData);
  157. }
  158. }
  159. // const arr = this.tabColumns.find(
  160. // (element) => element.key === this.tabName
  161. // ).tableColumns;
  162. // prop.push(initParams(arr, "key", "value"));
  163. },
  164. // 删行
  165. delTableRow(prop, index) {
  166. for (const key in this.params) {
  167. if (Array.isArray(this.params[key])) {
  168. this.params[key].splice(index, 1);
  169. }
  170. }
  171. // prop.splice(index, 1);
  172. },
  173. // 同步子表物料
  174. handleSynchronousMaterial(key1, key2) {
  175. let _this = this;
  176. // this.params[key1]-- -> this.params[key2]
  177. this.params[key1] &&
  178. this.params[key1].forEach((item, index) => {
  179. for (const key in item) {
  180. if (key in _this.params[key2][index]) {
  181. if (
  182. key == "material" ||
  183. key == "materialName" ||
  184. key == "materialCode"
  185. ) {
  186. _this.params[key2][index].material = item.material;
  187. _this.params[key2][index].materialName = item.materialName;
  188. _this.params[key2][index].materialCode = item.materialCode;
  189. } else {
  190. _this.params[key2][index][key] = item[key];
  191. }
  192. }
  193. }
  194. });
  195. },
  196. // 取消
  197. handleCancel() {
  198. this.params = {
  199. ...initParams(this.columns),
  200. puOrderItemList: [],
  201. puOrderExecuteList: [],
  202. };
  203. this.setVisible(false);
  204. },
  205. // 判断保存条件
  206. judgeSaveCondition(cb){
  207. this.$refs['orderAddForm'].validate(async (valid) => {
  208. if (valid) {
  209. if(!this.params['puOrderItemList'].length || !this.params['puOrderExecuteList'].length){
  210. this.$message.error('请填写订单行!');
  211. return false;
  212. }
  213. // puOrderItemList
  214. let isPrice = this.params.puOrderItemList.filter(item => !item.whetherCompleteInquiry);
  215. if(isPrice.length){
  216. this.$message.error('询价失败!');
  217. return false
  218. }
  219. console.log(isPrice,'isPrice');
  220. cb();
  221. } else {
  222. console.log('error submit!!');
  223. return false;
  224. }
  225. });
  226. },
  227. // 保存
  228. handleSava() {
  229. console.log(this.params,'this.params---------');
  230. this.judgeSaveCondition(async()=>{
  231. try {
  232. this.loading = true;
  233. const { code, msg } = await orderApi.create(this.params);
  234. if (code === 200) {
  235. this.handleCancel();
  236. }
  237. } catch (err) {
  238. //
  239. } finally {
  240. this.loading = false;
  241. }
  242. })
  243. },
  244. // 保存并新增
  245. async handleSubmit() {
  246. this.judgeSaveCondition(async()=>{
  247. try {
  248. const createById = this.params.buyer;
  249. const createByName = this.params.buyerName;
  250. const updateById = this.$store.state.user.id;
  251. const updateByName = this.$store.state.user.name;
  252. const { code, msg } = await orderApi.create({
  253. createById,
  254. createByName,
  255. updateById,
  256. updateByName,
  257. ...this.params,
  258. });
  259. if (code === 200) {
  260. this.setVisible(false);
  261. }
  262. } catch (err) {
  263. this.$notify.error({ title: "error", message: err });
  264. } finally {
  265. // this.setVisible(false);
  266. }
  267. })
  268. },
  269. // 子表参照改变之后
  270. handleReferChange(val, source, type) {
  271. console.log(val, "val");
  272. console.log(source, "source");
  273. console.log(type, "type");
  274. // 触发物料参照询价
  275. if (type == "MATERIAL_PARAM" && source.qty && source.qty != "") {
  276. this.handleGetPrice();
  277. }
  278. // if(type == "MATERIAL_PARAM"){
  279. // source.isDrug = val.materialMedcine.isDrug == '0' ? 'Y' : 'N';
  280. // }
  281. },
  282. // 子表下拉框改变
  283. handleSelectChange(type,row){
  284. console.log(type,'type');
  285. if(type == 'priceType' && row.material && row.qty && row.qty != ""){
  286. this.handleGetPrice();
  287. }
  288. },
  289. // 子表inputNumber
  290. handleInputChange(row, type) {
  291. console.log(type, "type");
  292. // 物料数量变化----询价
  293. if (type == "qty" && row.material) {
  294. this.handleGetPrice();
  295. }
  296. },
  297. // 询价 getPrice
  298. async handleGetPrice() {
  299. try {
  300. // let { puOrg, priceType, customer, assignSupplier, material, } = data;
  301. let { code, data } = await orderApi.getPrice({ ...this.params });
  302. if (code == 200) {
  303. this.params = data;
  304. }
  305. } catch (error) {
  306. } finally {
  307. }
  308. },
  309. // 下拉框选择改变
  310. handleChangeSelect(val,typeName){
  311. if(val === 'billType'){
  312. this.params['billTypeName'] = this.dict.type[typeName].find(item => item.value == this.params[val]).label;
  313. }
  314. },
  315. },
  316. created() {
  317. console.log("ADD CREATED", this.params);
  318. },
  319. mounted() {},
  320. destroyed() {},
  321. };
  322. </script>
  323. <template>
  324. <el-drawer
  325. direction="btt"
  326. size="100%"
  327. :with-header="false"
  328. :visible.sync="visible"
  329. @open="beforeOpen"
  330. @close="$emit('close')"
  331. >
  332. <el-form
  333. size="mini"
  334. label-position="right"
  335. ref="orderAddForm"
  336. label-width="140px"
  337. :model="params"
  338. :rules="rules"
  339. >
  340. <el-card
  341. :body-style="{
  342. padding: '20px',
  343. display: 'flex',
  344. 'flex-wrap': 'wrap',
  345. }"
  346. style="margin: 10px"
  347. >
  348. <div
  349. slot="header"
  350. style="
  351. display: flex;
  352. justify-content: space-between;
  353. align-items: center;
  354. "
  355. >
  356. <h3>新增</h3>
  357. <div style="text-align: right">
  358. <el-button size="mini" @click="handleCancel">取消</el-button>
  359. <el-button
  360. size="mini"
  361. type="danger"
  362. @click="handleSava"
  363. >保存</el-button>
  364. <!-- <el-button size="mini" type="info" @click="handleSubmit">
  365. 保存并新增
  366. </el-button> -->
  367. </div>
  368. </div>
  369. <el-row style="display: flex; flex-wrap: wrap">
  370. <el-col
  371. v-for="(column, index) in columns"
  372. :key="index"
  373. :span="column.span || 6"
  374. >
  375. <el-form-item
  376. :prop="column.key"
  377. :label="column.title"
  378. v-if="column.isShow"
  379. >
  380. <el-input
  381. v-if="column.inputType === 'Input'"
  382. v-model="params[column.key]"
  383. :placeholder="column.placeholder"
  384. :clearable="column.clearable"
  385. :disabled="column.disabled"
  386. style="width: 100%"
  387. >
  388. </el-input>
  389. <dr-popover-select
  390. v-if="column.inputType === 'PopoverSelect'"
  391. v-model="params[column.key]"
  392. :value-key="column.valueKey"
  393. :source.sync="params"
  394. :title="column.title"
  395. :type="column.referName"
  396. :multiple="column.multiple"
  397. :placeholder="column.placeholder"
  398. :data-mapping="column.dataMapping"
  399. :query-params="column.queryParams"
  400. ></dr-popover-select>
  401. <el-input
  402. v-if="column.inputType === 'Textarea'"
  403. v-model="params[column.key]"
  404. type="textarea"
  405. :placeholder="column.placeholder"
  406. :clearable="column.clearable"
  407. :disabled="column.disabled"
  408. style="width: 100%"
  409. ></el-input>
  410. <el-input-number
  411. v-if="column.inputType === 'InputNumber'"
  412. v-model="params[column.key]"
  413. :controls-position="column.controlsPosition"
  414. :placeholder="column.placeholder"
  415. :clearable="column.clearable"
  416. :disabled="column.disabled"
  417. style="width: 100%"
  418. >
  419. </el-input-number>
  420. <el-select
  421. v-if="column.inputType === 'Select'"
  422. v-model="params[column.key]"
  423. :disabled="column.disabled"
  424. :clearable="column.clearable"
  425. :placeholder="column.placeholder"
  426. style="width: 100%"
  427. >
  428. <el-option
  429. v-for="item in dict.type[column.referName]"
  430. :key="item.value"
  431. :label="item.label"
  432. :value="item.value"
  433. ></el-option>
  434. </el-select>
  435. <el-select
  436. v-if="column.inputType === 'TagSelect'"
  437. v-model="params[column.key]"
  438. multiple
  439. clearable
  440. collapse-tags
  441. :placeholder="column.placeholder"
  442. :clearable="column.clearable"
  443. :disabled="column.disabled"
  444. style="width: 100%"
  445. >
  446. <template #prefix>
  447. <el-icon
  448. class="el-icon-view"
  449. style="cursor: pointer"
  450. @click.stop="$message.info(234)"
  451. >
  452. </el-icon>
  453. </template>
  454. <el-option
  455. v-for="item in options"
  456. :key="item.value"
  457. :label="item.label"
  458. :value="item.value"
  459. ></el-option>
  460. </el-select>
  461. <el-date-picker
  462. v-if="column.inputType === 'DatePicker'"
  463. v-model="params[column.key]"
  464. :type="column.type"
  465. :placeholder="column.placeholder"
  466. :clearable="column.clearable"
  467. :disabled="column.disabled"
  468. :picker-options="column.pickerOptions"
  469. style="width: 100%"
  470. ></el-date-picker>
  471. <el-checkbox
  472. v-if="column.inputType === 'Checkbox'"
  473. v-model="params[column.key]"
  474. :disabled="column.disabled"
  475. true-label="Y"
  476. false-label="N"
  477. ></el-checkbox>
  478. <file-upload-center
  479. v-if="column.inputType === 'Upload'"
  480. v-model="params[column.key]"
  481. :file-type="column.fileType"
  482. ></file-upload-center>
  483. </el-form-item>
  484. </el-col>
  485. </el-row>
  486. </el-card>
  487. <el-card
  488. :body-style="{
  489. padding: '20px',
  490. display: 'flex',
  491. 'flex-wrap': 'wrap',
  492. position: 'relative',
  493. }"
  494. style="margin: 10px"
  495. >
  496. <el-tabs v-model="tabName" style="width: 100%">
  497. <el-tab-pane
  498. v-for="(column, index) in tabColumns"
  499. :key="index"
  500. :label="column.title"
  501. :name="column.key"
  502. >
  503. <el-table :data="params[column.key]" style="width: 100%">
  504. <el-table-column
  505. v-for="(cColumn, cIndex) in column.tableColumns"
  506. :key="cIndex"
  507. :label="cColumn.title"
  508. :width="cColumn.width || 80"
  509. >
  510. <template slot-scope="scope">
  511. <el-form-item
  512. label-width="0"
  513. :prop="`${column.key}.${scope.$index}.${[cColumn.key]}`"
  514. :rules="{ required: cColumn.require || false, message: `${cColumn.title}不能为空`, trigger: 'change' }"
  515. >
  516. <el-tag v-if="cColumn.key === 'index'" >
  517. {{ scope.$index + 1 }}
  518. </el-tag>
  519. <el-input
  520. v-if="cColumn.inputType === 'Input'"
  521. v-model="scope.row[cColumn.key]"
  522. :placeholder="cColumn.placeholder"
  523. :clearable="cColumn.clearable"
  524. :disabled="cColumn.disabled"
  525. size="mini"
  526. style="width: 100%"
  527. ></el-input>
  528. <!-- -->
  529. <dr-popover-select
  530. v-if="cColumn.inputType === 'PopoverSelect'"
  531. v-model="scope.row[cColumn.key]"
  532. :source.sync="scope.row"
  533. :title="cColumn.title"
  534. :value-key="cColumn.valueKey"
  535. :type="cColumn.referName"
  536. :multiple="cColumn.multiple"
  537. :placeholder="cColumn.placeholder"
  538. :data-mapping="cColumn.dataMapping"
  539. :query-params="cColumn.queryParams"
  540. @change="handleReferChange"
  541. size="mini"
  542. >
  543. </dr-popover-select>
  544. <el-input-number
  545. v-if="cColumn.inputType === 'InputNumber'"
  546. v-model="scope.row[cColumn.key]"
  547. :controls-position="cColumn.controlsPosition"
  548. :placeholder="cColumn.placeholder"
  549. @change="handleInputChange(scope.row, cColumn.key)"
  550. :clearable="cColumn.clearable"
  551. :disabled="cColumn.disabled"
  552. size="mini"
  553. style="width: 100%"
  554. ></el-input-number>
  555. <el-select
  556. v-if="cColumn.inputType === 'Select'"
  557. v-model="scope.row[cColumn.key]"
  558. size="mini"
  559. :disabled="cColumn.disabled"
  560. :clearable="cColumn.clearable"
  561. :placeholder="cColumn.placeholder"
  562. style="width: 100%"
  563. @change="handleSelectChange(cColumn.key,scope.row)"
  564. >
  565. <el-option
  566. v-for="item in dict.type[cColumn.referName]"
  567. :key="item.value"
  568. :label="item.label"
  569. :value="item.value"
  570. ></el-option>
  571. </el-select>
  572. <el-checkbox
  573. v-if="cColumn.inputType === 'Checkbox'"
  574. v-model="scope.row[cColumn.key]"
  575. :disabled="cColumn.disabled"
  576. true-label="Y"
  577. false-label="N"
  578. ></el-checkbox>
  579. </el-form-item>
  580. </template>
  581. </el-table-column>
  582. <el-table-column fixed="right" label="操作" width="80">
  583. <template slot-scope="scope">
  584. <el-button
  585. @click.native.prevent="
  586. delTableRow(params[tabName], scope.$index)
  587. "
  588. type="text"
  589. size="small"
  590. >
  591. 删行
  592. </el-button>
  593. </template>
  594. </el-table-column>
  595. </el-table>
  596. </el-tab-pane>
  597. </el-tabs>
  598. <el-row style="position: absolute; top: 20px; right: 20px">
  599. <el-button size="mini" @click="addTableRow(params[tabName])"
  600. >增行</el-button
  601. >
  602. </el-row>
  603. </el-card>
  604. </el-form>
  605. </el-drawer>
  606. </template>