index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. console.log(SelectColumns, 'SelectColumns');
  17. export default {
  18. name: "AddPurchaseOrderDrawer",
  19. dicts: initDicts(SelectColumns),
  20. components: {},
  21. data() {
  22. return {
  23. visible: false,
  24. columns: NewColumns,
  25. rules: initRules(NewColumns),
  26. params: {
  27. ...initParams(NewColumns),
  28. puOrderItemList: [],
  29. puOrderExecuteList: [],
  30. },
  31. tabColumns: NewTabColumns,
  32. tabName: "puOrderItemList",
  33. };
  34. },
  35. computed: {},
  36. watch: {
  37. "params.puOrderItemList": {
  38. handler(nVal, oVal) {
  39. console.log(nVal, 'nVal', oVal, 'oVal');
  40. this.handleSynchronousMaterial("puOrderItemList", "puOrderExecuteList");
  41. },
  42. deep: true,
  43. },
  44. "params.puOrderExecuteList": {
  45. handler(nVal, oVal) {
  46. this.handleSynchronousMaterial("puOrderExecuteList", "puOrderItemList");
  47. },
  48. deep: true,
  49. },
  50. "params": {
  51. handler(nVal, oVal) {
  52. // 组织变化
  53. if (nVal.puOrg != oVal.puOrg) {
  54. console.log(nVal.puOrg, 'nVal.puOrg', oVal.puOrg, 'oVal.puOrg');
  55. for (const key in this.params) {
  56. if (Array.isArray(this.params[key])) {
  57. this.params[key] = [];
  58. }
  59. else if (key != 'puOrg' && key != 'puOrgName'
  60. && key != 'buyer' && key != 'buyerName'
  61. && key != 'puDept' && key != 'puDeptName'
  62. && key != 'status') {
  63. this.params[key] = '';
  64. }
  65. else { }
  66. }
  67. }
  68. },
  69. deep: true,
  70. }
  71. },
  72. methods: {
  73. beforeOpen() {
  74. const { deptName, deptId, name, nickName, orgName, orgId } = this.$store.state.user;
  75. this.params.puOrg = orgId;
  76. this.params.puOrgName = orgName;
  77. this.params.buyer = name;
  78. this.params.buyerName = nickName;
  79. this.params.puDept = deptId;
  80. this.params.puDeptName = deptName;
  81. this.params.status = '0';
  82. },
  83. setVisible(prop) {
  84. this.visible = prop;
  85. },
  86. // 增行
  87. addTableRow(prop) {
  88. for (const key in this.params) {
  89. if (Array.isArray(this.params[key])) {
  90. const arr = this.tabColumns.find(
  91. (element) => element.key === key
  92. ).tableColumns;
  93. let rowData = initParams(arr, "key", "value");
  94. "rowno" in rowData &&
  95. (rowData["rowno"] = this.params[key].length + 1);
  96. "rowNo" in rowData &&
  97. (rowData["rowNo"] = this.params[key].length + 1);
  98. // 是否完成询价,新增明细行需默认明细为false
  99. rowData['whetherCompleteInquiry'] = false;
  100. this.params[key].push(rowData);
  101. }
  102. }
  103. // const arr = this.tabColumns.find(
  104. // (element) => element.key === this.tabName
  105. // ).tableColumns;
  106. // prop.push(initParams(arr, "key", "value"));
  107. },
  108. // 删行
  109. delTableRow(prop, index) {
  110. for (const key in this.params) {
  111. if (Array.isArray(this.params[key])) {
  112. this.params[key].splice(index, 1);
  113. }
  114. }
  115. // prop.splice(index, 1);
  116. },
  117. // 同步子表物料
  118. handleSynchronousMaterial(key1, key2) {
  119. let _this = this;
  120. // this.params[key1]-- -> this.params[key2]
  121. this.params[key1] && this.params[key1].forEach((item, index) => {
  122. for (const key in item) {
  123. if (key in _this.params[key2][index]) {
  124. if (key == 'material' || key == 'materialName' || key == 'materialCode') {
  125. _this.params[key2][index].material = item.material;
  126. _this.params[key2][index].materialName = item.materialName;
  127. _this.params[key2][index].materialCode = item.materialCode;
  128. } else {
  129. _this.params[key2][index][key] = item[key];
  130. }
  131. }
  132. }
  133. });
  134. },
  135. // 取消
  136. handleCancel() {
  137. this.setVisible(false);
  138. this.params = initParams(this.columns, "key", "value");
  139. },
  140. // 保存
  141. async handleSava() {
  142. // orderAddForm
  143. console.log(this.params, "params");
  144. // this.$refs['orderAddForm'].validate(async (valid) => {
  145. // if (valid) {
  146. try {
  147. const { code, msg } = await orderApi.create(this.params);
  148. if (code === 200) {
  149. this.$notify.success({ title: msg });
  150. this.setVisible(false);
  151. } else {
  152. this.$notify.warning({ title: msg });
  153. }
  154. } catch (err) {
  155. //
  156. } finally {
  157. // this.setVisible(false);
  158. }
  159. // } else {
  160. // console.log('error submit!!');
  161. // return false;
  162. // }
  163. // });
  164. },
  165. // 保存并新增
  166. async handleSubmit() {
  167. // this.$refs["orderAddForm"].validate(async (valid) => {
  168. // if (valid) {
  169. try {
  170. const createById = this.params.buyer;
  171. const createByName = this.params.buyerName;
  172. const updateById = this.$store.state.user.id;
  173. const updateByName = this.$store.state.user.name;
  174. const { code, msg } = await orderApi.create({
  175. createById,
  176. createByName,
  177. updateById,
  178. updateByName,
  179. ...this.params,
  180. });
  181. if (code === 200) {
  182. this.$notify.success({ title: msg });
  183. this.setVisible(false);
  184. } else {
  185. this.$notify.warning({ title: msg });
  186. }
  187. } catch (err) {
  188. this.$notify.error({ title: "error", message: err });
  189. } finally {
  190. // this.setVisible(false);
  191. }
  192. // } else {
  193. // console.log("error submit!!");
  194. // return false;
  195. // }
  196. // });
  197. },
  198. // 子表参照改变之后
  199. handleReferChange(val, source, type) {
  200. console.log(val, 'val');
  201. console.log(source, 'source');
  202. console.log(type, 'type');
  203. // 触发物料参照
  204. if (type == 'MATERIAL_PARAM' && source.qty && source.qty != '') {
  205. this.handleGetPrice();
  206. }
  207. },
  208. // 子表input
  209. handleInputChange(row, type) {
  210. console.log(type, 'type');
  211. // 物料数量变化----询价
  212. if (type == 'qty' && row.material) {
  213. this.handleGetPrice();
  214. }
  215. },
  216. // 询价 getPrice
  217. async handleGetPrice() {
  218. try {
  219. // let { puOrg, priceType, customer, assignSupplier, material, } = data;
  220. let { code, data } = await orderApi.getPrice({ ...this.params })
  221. if (code == 200) {
  222. this.params = data;
  223. }
  224. } catch (error) {
  225. } finally {
  226. }
  227. },
  228. },
  229. created() {
  230. console.log("ADD CREATED", this.params)
  231. },
  232. mounted() { },
  233. destroyed() { },
  234. };
  235. </script>
  236. <template>
  237. <el-drawer direction="btt" size="100%" :with-header="false" :visible.sync="visible" @open="beforeOpen"
  238. @close="$emit('close')">
  239. <el-form size="mini" label-position="right" ref="orderAddForm" label-width="135px" :model="params" :rules="rules">
  240. <el-card :body-style="{
  241. padding: '20px',
  242. display: 'flex',
  243. 'flex-wrap': 'wrap',
  244. }" style="margin: 10px">
  245. <div slot="header" style="
  246. display: flex;
  247. justify-content: space-between;
  248. align-items: center;
  249. ">
  250. <h3>新增</h3>
  251. <div style="text-align: right">
  252. <el-button size="mini" @click="handleCancel">取消</el-button>
  253. <el-button size="mini" type="danger" @click="handleSava">保存</el-button>
  254. <el-button size="mini" type="info" @click="handleSubmit">
  255. 保存并新增
  256. </el-button>
  257. </div>
  258. </div>
  259. <el-row>
  260. <el-col v-for="(column, index) in columns" :key="index" :span="column.span || 6">
  261. <el-form-item :prop="column.key" :label="column.title">
  262. <el-input v-if="column.inputType === 'Input'" v-model="params[column.key]" :placeholder="column.placeholder"
  263. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%">
  264. </el-input>
  265. <dr-popover-select v-if="column.inputType === 'PopoverSelect'" v-model="params[column.key]"
  266. :value-key="column.valueKey" :source.sync="params" :title="column.title" :type="column.referName"
  267. :multiple="column.multiple" :placeholder="column.placeholder" :data-mapping="column.dataMapping"
  268. :query-params="column.queryParams(params)">
  269. </dr-popover-select>
  270. <el-input v-if="column.inputType === 'Textarea'" v-model="params[column.key]" type="textarea"
  271. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  272. style="width: 100%">
  273. </el-input>
  274. <el-input-number v-if="column.inputType === 'InputNumber'" v-model="params[column.key]"
  275. :controls-position="column.config.controlsPosition" :placeholder="column.placeholder"
  276. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%">
  277. </el-input-number>
  278. <el-select v-if="column.inputType === 'Select'" v-model="params[column.key]" :disabled="column.disabled"
  279. :clearable="column.clearable" :placeholder="column.placeholder" style="width: 100%">
  280. <el-option v-for="item in dict.type[column.referName]" :key="item.value" :label="item.label"
  281. :value="item.value">
  282. </el-option>
  283. </el-select>
  284. <el-select v-if="column.inputType === 'TagSelect'" v-model="params[column.key]" multiple clearable
  285. collapse-tags :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  286. style="width: 100%">
  287. <template #prefix>
  288. <el-icon class="el-icon-view" style="cursor: pointer" @click.stop="$message.info(234)"></el-icon>
  289. </template>
  290. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  291. </el-option>
  292. </el-select>
  293. <el-date-picker v-if="column.inputType === 'DatePicker'" v-model="params[column.key]" :type="column.type"
  294. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  295. :picker-options="column.pickerOptions" style="width: 100%">
  296. </el-date-picker>
  297. <el-checkbox v-if="column.inputType === 'Checkbox'" v-model="params[column.key]" true-label="Y"
  298. false-label="N">
  299. </el-checkbox>
  300. <el-upload v-if="column.inputType === 'Upload'" :file-list="params[column.key]" :disabled="column.disabled"
  301. drag action="https://jsonplaceholder.typicode.com/posts/" multiple>
  302. <i class="el-icon-upload"></i>
  303. <div class="el-upload__text">
  304. 将文件拖到此处,或<em>点击上传</em>
  305. </div>
  306. <div class="el-upload__tip" slot="tip">
  307. 只能上传jpg/png文件,且不超过500kb
  308. </div>
  309. </el-upload>
  310. </el-form-item>
  311. </el-col>
  312. </el-row>
  313. </el-card>
  314. <el-card :body-style="{
  315. padding: '20px',
  316. display: 'flex',
  317. 'flex-wrap': 'wrap',
  318. position: 'relative',
  319. }" style="margin: 10px">
  320. <el-tabs v-model="tabName" style="width: 100%">
  321. <el-tab-pane v-for="(column, index) in tabColumns" :key="index" :label="column.title" :name="column.key">
  322. <el-table :data="params[column.key]" style="width: 100%">
  323. <el-table-column v-for="(cColumn, cIndex) in column.tableColumns" :key="cIndex" :prop="cColumn.key"
  324. :label="cColumn.title" :width="cColumn.width || 80">
  325. <template slot-scope="scope">
  326. <el-tag v-if="cColumn.key === 'index'">
  327. {{ scope.$index + 1 }}
  328. </el-tag>
  329. <el-input v-if="cColumn.inputType === 'Input'" v-model="scope.row[cColumn.key]"
  330. :placeholder="cColumn.placeholder" :clearable="cColumn.clearable" :disabled="cColumn.disabled"
  331. size="mini" style="width: 100%" @change="handleInputChange(scope.row, cColumn.key)">
  332. </el-input>
  333. <!-- -->
  334. <dr-popover-select v-if="cColumn.inputType === 'PopoverSelect'" v-model="scope.row[cColumn.key]"
  335. :source.sync="scope.row" :title="cColumn.title" :value-key="cColumn.valueKey"
  336. :type="cColumn.referName" :multiple="cColumn.multiple" :placeholder="cColumn.placeholder"
  337. :data-mapping="cColumn.dataMapping" :query-params="cColumn.queryParams(scope.row)"
  338. @change="handleReferChange" size="mini">
  339. </dr-popover-select>
  340. <el-input-number v-if="cColumn.inputType === 'InputNumber'" v-model="scope.row[cColumn.key]"
  341. :controls-position="cColumn.config.controlsPosition" :placeholder="cColumn.placeholder"
  342. :clearable="cColumn.clearable" :disabled="cColumn.disabled" size="mini" style="width: 100%">
  343. </el-input-number>
  344. <el-select v-if="cColumn.inputType === 'Select'" v-model="scope.row[cColumn.key]" size="mini"
  345. :disabled="cColumn.disabled" :clearable="cColumn.clearable" :placeholder="cColumn.placeholder"
  346. style="width: 100%">
  347. <el-option v-for="item in dict.type[cColumn.referName]" :key="item.value" :label="item.label"
  348. :value="item.value">
  349. </el-option>
  350. </el-select>
  351. <el-checkbox v-if="cColumn.inputType === 'Checkbox'" v-model="scope.row[cColumn.key]" true-label="Y"
  352. false-label="N">
  353. </el-checkbox>
  354. </template>
  355. </el-table-column>
  356. <el-table-column fixed="right" label="操作" width="80">
  357. <template slot-scope="scope">
  358. <el-button @click.native.prevent="
  359. delTableRow(params[tabName], scope.$index)
  360. " type="text" size="small">
  361. 删行
  362. </el-button>
  363. </template>
  364. </el-table-column>
  365. </el-table>
  366. </el-tab-pane>
  367. </el-tabs>
  368. <el-row style="position: absolute; top: 20px; right: 20px">
  369. <el-button size="mini" @click="addTableRow(params[tabName])">增行</el-button>
  370. </el-row>
  371. </el-card>
  372. </el-form>
  373. </el-drawer>
  374. </template>