index.vue 17 KB

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