index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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.sysFileRecordList, "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, source, type) {
  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. created() {
  256. console.log("ADD CREATED", this.params)
  257. },
  258. mounted() { },
  259. destroyed() { },
  260. };
  261. </script>
  262. <template>
  263. <el-drawer
  264. direction="btt"
  265. size="100%"
  266. :with-header="false"
  267. :visible.sync="visible"
  268. @open="beforeOpen"
  269. @close="$emit('close')"
  270. >
  271. <el-form
  272. size="mini"
  273. label-position="right"
  274. ref="orderAddForm"
  275. label-width="140px"
  276. :model="params"
  277. :rules="rules"
  278. >
  279. <el-card :body-style="{
  280. padding: '20px',
  281. display: 'flex',
  282. 'flex-wrap': 'wrap',
  283. }" style="margin: 10px">
  284. <div slot="header" style="
  285. display: flex;
  286. justify-content: space-between;
  287. align-items: center;
  288. ">
  289. <h3>新增</h3>
  290. <div style="text-align: right">
  291. <el-button size="mini" @click="handleCancel">取消</el-button>
  292. <el-button size="mini" type="danger" @click="handleSava">保存</el-button>
  293. <!-- <el-button size="mini" type="info" @click="handleSubmit">
  294. 保存并新增
  295. </el-button> -->
  296. </div>
  297. </div>
  298. <el-row style="display:flex; flex-wrap: wrap;">
  299. <el-col v-for="(column, index) in columns" :key="index" :span="column.span || 6">
  300. <el-form-item :prop="column.key" :label="column.title" v-if="column.isShow">
  301. <el-input v-if="column.inputType === 'Input'"
  302. v-model="params[column.key]"
  303. :placeholder="column.placeholder"
  304. :clearable="column.clearable"
  305. :disabled="column.disabled"
  306. style="width: 100%"
  307. >
  308. </el-input>
  309. <dr-popover-select v-if="column.inputType === 'PopoverSelect'"
  310. v-model="params[column.key]"
  311. :value-key="column.valueKey"
  312. :source.sync="params"
  313. :title="column.title"
  314. :type="column.referName"
  315. :multiple="column.multiple"
  316. :placeholder="column.placeholder"
  317. :data-mapping="column.dataMapping"
  318. :query-params="column.queryParams(params)"
  319. ></dr-popover-select>
  320. <el-input v-if="column.inputType === 'Textarea'"
  321. v-model="params[column.key]"
  322. type="textarea"
  323. :placeholder="column.placeholder"
  324. :clearable="column.clearable"
  325. :disabled="column.disabled"
  326. style="width: 100%"
  327. ></el-input>
  328. <el-input-number v-if="column.inputType === 'InputNumber'"
  329. v-model="params[column.key]"
  330. :controls-position="column.controlsPosition"
  331. :placeholder="column.placeholder"
  332. :clearable="column.clearable"
  333. :disabled="column.disabled"
  334. style="width: 100%"
  335. > </el-input-number>
  336. <el-select v-if="column.inputType === 'Select'"
  337. v-model="params[column.key]"
  338. :disabled="column.disabled"
  339. :clearable="column.clearable"
  340. :placeholder="column.placeholder"
  341. style="width: 100%"
  342. >
  343. <el-option
  344. v-for="item in dict.type[column.referName]"
  345. :key="item.value"
  346. :label="item.label"
  347. :value="item.value"
  348. ></el-option>
  349. </el-select>
  350. <el-select v-if="column.inputType === 'TagSelect'"
  351. v-model="params[column.key]"
  352. multiple
  353. clearable
  354. collapse-tags
  355. :placeholder="column.placeholder"
  356. :clearable="column.clearable"
  357. :disabled="column.disabled"
  358. style="width: 100%"
  359. >
  360. <template #prefix>
  361. <el-icon
  362. class="el-icon-view"
  363. style="cursor: pointer"
  364. @click.stop="$message.info(234)">
  365. </el-icon>
  366. </template>
  367. <el-option
  368. v-for="item in options"
  369. :key="item.value"
  370. :label="item.label"
  371. :value="item.value"
  372. ></el-option>
  373. </el-select>
  374. <el-date-picker v-if="column.inputType === 'DatePicker'"
  375. v-model="params[column.key]"
  376. :type="column.type"
  377. :placeholder="column.placeholder"
  378. :clearable="column.clearable"
  379. :disabled="column.disabled"
  380. :picker-options="column.pickerOptions"
  381. style="width: 100%"
  382. ></el-date-picker>
  383. <el-checkbox v-if="column.inputType === 'Checkbox'"
  384. v-model="params[column.key]"
  385. true-label="Y"
  386. false-label="N"
  387. ></el-checkbox>
  388. <file-upload-center v-if="column.inputType === 'Upload'"
  389. v-model="params[column.key]"
  390. :file-type="column.fileType"
  391. ></file-upload-center>
  392. </el-form-item>
  393. </el-col>
  394. </el-row>
  395. </el-card>
  396. <el-card :body-style="{
  397. padding: '20px',
  398. display: 'flex',
  399. 'flex-wrap': 'wrap',
  400. position: 'relative',
  401. }" style="margin: 10px">
  402. <el-tabs v-model="tabName" style="width: 100%">
  403. <el-tab-pane
  404. v-for="(column, index) in tabColumns"
  405. :key="index"
  406. :label="column.title"
  407. :name="column.key"
  408. >
  409. <el-table :data="params[column.key]" style="width: 100%">
  410. <el-table-column
  411. v-for="(cColumn, cIndex) in column.tableColumns"
  412. :key="cIndex"
  413. :prop="cColumn.key"
  414. :label="cColumn.title"
  415. :width="cColumn.width || 80"
  416. >
  417. <template slot-scope="scope">
  418. <el-tag v-if="cColumn.key === 'index'">
  419. {{ scope.$index + 1 }}
  420. </el-tag>
  421. <el-input v-if="cColumn.inputType === 'Input'"
  422. v-model="scope.row[cColumn.key]"
  423. :placeholder="cColumn.placeholder"
  424. :clearable="cColumn.clearable"
  425. :disabled="cColumn.disabled"
  426. size="mini"
  427. style="width: 100%"
  428. ></el-input>
  429. <!-- -->
  430. <dr-popover-select v-if="cColumn.inputType === 'PopoverSelect'"
  431. v-model="scope.row[cColumn.key]"
  432. :source.sync="scope.row"
  433. :title="cColumn.title"
  434. :value-key="cColumn.valueKey"
  435. :type="cColumn.referName"
  436. :multiple="cColumn.multiple"
  437. :placeholder="cColumn.placeholder"
  438. :data-mapping="cColumn.dataMapping"
  439. :query-params="cColumn.queryParams(scope.row)"
  440. @change="handleReferChange"
  441. size="mini"
  442. > </dr-popover-select>
  443. <el-input-number v-if="cColumn.inputType === 'InputNumber'"
  444. v-model="scope.row[cColumn.key]"
  445. :controls-position="cColumn.controlsPosition"
  446. :placeholder="cColumn.placeholder"
  447. @change="handleInputChange(scope.row, cColumn.key)"
  448. :clearable="cColumn.clearable"
  449. :disabled="cColumn.disabled"
  450. size="mini"
  451. style="width: 100%"
  452. ></el-input-number>
  453. <el-select v-if="cColumn.inputType === 'Select'"
  454. v-model="scope.row[cColumn.key]"
  455. size="mini"
  456. :disabled="cColumn.disabled"
  457. :clearable="cColumn.clearable"
  458. :placeholder="cColumn.placeholder"
  459. style="width: 100%"
  460. >
  461. <el-option
  462. v-for="item in dict.type[cColumn.referName]"
  463. :key="item.value"
  464. :label="item.label"
  465. :value="item.value"
  466. ></el-option>
  467. </el-select>
  468. <el-checkbox v-if="cColumn.inputType === 'Checkbox'"
  469. v-model="scope.row[cColumn.key]"
  470. true-label="Y"
  471. false-label="N"
  472. ></el-checkbox>
  473. </template>
  474. </el-table-column>
  475. <el-table-column fixed="right" label="操作" width="80">
  476. <template slot-scope="scope">
  477. <el-button @click.native.prevent="
  478. delTableRow(params[tabName], scope.$index)
  479. " type="text" size="small">
  480. 删行
  481. </el-button>
  482. </template>
  483. </el-table-column>
  484. </el-table>
  485. </el-tab-pane>
  486. </el-tabs>
  487. <el-row style="position: absolute; top: 20px; right: 20px">
  488. <el-button size="mini" @click="addTableRow(params[tabName])">增行</el-button>
  489. </el-row>
  490. </el-card>
  491. </el-form>
  492. </el-drawer>
  493. </template>