index.vue 14 KB

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