index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <script>
  2. // import { Columns, TabColumns } from "../add/column";
  3. import { editColumns, editTabColumns, forbidden, SelectColumns } from "./initColumn";
  4. import orderApi from "@/api/business/purchase/purchase-order";
  5. import { initColumns, initDicts, initRules, initParams } from "@/utils/init";
  6. // const NewColumns = initColumns(Columns);
  7. // const NewTabColumns = TabColumns.map((element) => ({
  8. // ...element,
  9. // tableColumns: initColumns(element.tableColumns),
  10. // }));
  11. //
  12. // const SelectColumns = NewColumns.filter(column => column.inputType === 'Select')
  13. // NewTabColumns.forEach(column => {
  14. // SelectColumns.push(...column.tableColumns.filter(cColumn => cColumn.inputType === 'Select'))
  15. // });
  16. export default {
  17. name: "EditPurchaseOrderDrawer",
  18. dicts: initDicts(SelectColumns),
  19. components: {
  20. FileUploadCenter: () => import('../components/FileUploadCenter/index.vue'),
  21. },
  22. data() {
  23. return {
  24. size: "mini",
  25. visible: false,
  26. loading: false,
  27. columns: editColumns,
  28. rules: initRules(editColumns),
  29. params: {
  30. ...initParams(editColumns),
  31. puOrderItemList: [],
  32. puOrderExecuteList: [],
  33. },
  34. tabColumns: editTabColumns,
  35. tabName: "puOrderItemList",
  36. };
  37. },
  38. computed: {},
  39. watch: {
  40. "params.contractType": function (newProp) {
  41. this.tabColumns = editTabColumns.filter((element) =>
  42. newProp === "1" ? element.key !== "puOrderItemList" : element
  43. );
  44. this.tabName = this.tabColumns[0].key;
  45. },
  46. tabName: function (newProp) {
  47. const { id } = this.params;
  48. // this.fetchTable(id, newProp);
  49. },
  50. 'params.puOrderItemList': {
  51. handler(nVal, oVal) {
  52. this.params.source == 3 && this.handleSynchronousMaterial('puOrderItemList', 'puOrderExecuteList');
  53. },
  54. deep: true,
  55. immediate: true
  56. },
  57. 'params.puOrderExecuteList': {
  58. handler(nVal, oVal) {
  59. this.params.source == 3 && this.handleSynchronousMaterial('puOrderExecuteList', 'puOrderItemList');
  60. },
  61. deep: true,
  62. immediate: true
  63. },
  64. },
  65. methods: {
  66. setVisible(prop) {
  67. this.visible = prop;
  68. },
  69. // 同步子表物料
  70. handleSynchronousMaterial(key1, key2) {
  71. // this.params[key1]-- -> this.params[key2]
  72. this.params[key1] && this.params[key1].forEach((item, index) => {
  73. this.params[key2][index].material = item.material;
  74. this.params[key2][index].materialName = item.materialName;
  75. this.params[key2][index].materialCode = item.materialCode;
  76. })
  77. },
  78. // 判断属性是否禁用
  79. handleIsForbidden(status) {
  80. console.log(status);
  81. let { editColumns, editTabColumns } = forbidden(status != '2');
  82. this.columns = editColumns;
  83. this.tabColumns = editTabColumns;
  84. },
  85. // 查询详细
  86. async fetchItem(prop) {
  87. try {
  88. this.loading = true;
  89. const { code, msg, data } = await orderApi.details(prop);
  90. if (code === 200) {
  91. this.params = { ...this.params, ...data };
  92. console.log(this.params, 'this.params----------123');
  93. this.handleIsForbidden(this.params.status);
  94. }
  95. } catch (err) {
  96. //
  97. } finally {
  98. this.loading = false;
  99. }
  100. },
  101. // 新增行
  102. addTableRow(prop) {
  103. for (const key in this.params) {
  104. if (Array.isArray(this.params[key])) {
  105. const arr = this.tabColumns.find(
  106. (element) => element.key === key
  107. ).tableColumns;
  108. let rowData = initParams(arr, "key", "value");
  109. 'rowno' in rowData && (rowData['rowno'] = this.params[key].length + 1);
  110. 'rowNo' in rowData && (rowData['rowNo'] = this.params[key].length + 1);
  111. this.params[key].push(rowData);
  112. }
  113. }
  114. // const arr = this.tabColumns.find(
  115. // (element) => element.key === this.tabName
  116. // ).tableColumns;
  117. // prop.push(initParams(arr, "key", "value"));
  118. },
  119. // 删除行
  120. delTableRow(prop, index) {
  121. // prop.splice(index, 1);
  122. for (const key in this.params) {
  123. if (Array.isArray(this.params[key])) {
  124. this.params[key].splice(index, 1);
  125. }
  126. }
  127. },
  128. // 取消
  129. handleCancel() {
  130. this.setVisible(false);
  131. this.params = initParams(this.columns, "key", "value");
  132. },
  133. // 保存
  134. async handleSava() {
  135. // this.$refs['orderEditForm'].validate(async (valid) => {
  136. // if (valid) {
  137. try {
  138. this.loading = true;
  139. const { code, msg } = await (this.handleIsRevise(this.params.status) ?
  140. orderApi.revision(this.params)
  141. : orderApi.edit(this.params)
  142. )
  143. if (code === 200) {
  144. this.setVisible(false);
  145. }
  146. } catch (err) {
  147. //
  148. } finally {
  149. this.loading = false;
  150. }
  151. // } else {
  152. // console.log('error submit!!');
  153. // return false;
  154. // }
  155. // });
  156. },
  157. beforeOpen() {
  158. },
  159. // 子表参照改变之后
  160. handleReferChange(val, source, type) {
  161. console.log(val, 'val');
  162. console.log(source, 'source');
  163. console.log(type, 'type');
  164. // 触发物料参照
  165. if (type == 'MATERIAL_PARAM' && source.qty && source.qty != '') {
  166. this.handleGetPrice();
  167. }
  168. },
  169. // 子表inputNumber
  170. handleInputChange(row, type) {
  171. console.log(type, 'type');
  172. // 物料数量变化----询价
  173. if (type == 'qty' && row.material) {
  174. this.handleGetPrice();
  175. }
  176. },
  177. // 询价 getPrice
  178. async handleGetPrice() {
  179. try {
  180. // let { puOrg, priceType, customer, assignSupplier, material, } = data;
  181. let { code, data } = await orderApi.getPrice({ ...this.params })
  182. if (code == 200) {
  183. this.params = data;
  184. }
  185. } catch (error) {
  186. } finally {
  187. }
  188. },
  189. // 判断修订还是编辑
  190. handleIsRevise(status) {
  191. return status == '2';
  192. },
  193. },
  194. created() {
  195. console.log("EDIT CREATED");
  196. console.log(this.params, 'this.params');
  197. },
  198. mounted() { },
  199. destroyed() { },
  200. };
  201. </script>
  202. <template>
  203. <el-drawer direction="btt" size="100%" :with-header="false" :visible.sync="visible" @open="beforeOpen"
  204. @close="$emit('close')">
  205. <el-form v-loading="loading" :size="size" ref="orderEditForm" label-position="right" label-width="140px"
  206. :model="params" :rules="rules">
  207. <el-card :body-style="{
  208. padding: '20px',
  209. display: 'flex',
  210. 'flex-wrap': 'wrap',
  211. }" style="margin: 10px">
  212. <div slot="header" style="
  213. display: flex;
  214. justify-content: space-between;
  215. align-items: center;
  216. ">
  217. <h3>{{ handleIsRevise(params.status) ? '修订' : '编辑' }}</h3>
  218. <div style="text-align: right">
  219. <el-button :size="size" @click="handleCancel">取 消</el-button>
  220. <el-button :size="size" type="danger" @click="handleSava">更 新</el-button>
  221. </div>
  222. </div>
  223. <el-row style="display:flex; flex-wrap: wrap;">
  224. <el-col v-for="(column, index) in columns" :key="index" :span="column.span || 6">
  225. <el-form-item :prop="column.key" :label="column.title">
  226. <el-input v-if="column.inputType === 'Input'" v-model="params[column.key]" :placeholder="column.placeholder"
  227. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%">
  228. </el-input>
  229. <dr-popover-select v-if="column.inputType === 'PopoverSelect'" v-model="params[column.key]" size="mini"
  230. :value-key="column.valueKey" :source.sync="params" :title="column.title" :type="column.referName"
  231. :multiple="column.multiple" :placeholder="column.placeholder" :data-mapping="column.dataMapping"
  232. :disabled="column.disabled" :query-params="column.queryParams(params)">
  233. </dr-popover-select>
  234. <el-input v-if="column.inputType === 'Textarea'" v-model="params[column.key]" type="textarea"
  235. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  236. style="width: 100%">
  237. </el-input>
  238. <el-input-number v-if="column.inputType === 'InputNumber'" v-model="params[column.key]"
  239. :max="handleIsRevise(params.status) ? params[column.key] : 'Infinity'"
  240. :controls-position="column.controlsPosition" :placeholder="column.placeholder"
  241. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%">
  242. </el-input-number>
  243. <el-select v-if="column.inputType === 'Select'" v-model="params[column.key]" :disabled="column.disabled"
  244. :clearable="column.clearable" :placeholder="column.placeholder" style="width: 100%">
  245. <el-option v-for="item in dict.type[column.referName]" :key="item.value" :label="item.label"
  246. :value="item.value">
  247. </el-option>
  248. </el-select>
  249. <el-select v-if="column.inputType === 'TagSelect'" v-model="params[column.key]" multiple clearable
  250. collapse-tags :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  251. style="width: 100%">
  252. <template #prefix>
  253. <el-icon class="el-icon-view" style="cursor: pointer" @click.stop="$message.info(234)"></el-icon>
  254. </template>
  255. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  256. </el-option>
  257. </el-select>
  258. <el-date-picker v-if="column.inputType === 'DatePicker'" v-model="params[column.key]" :type="column.type"
  259. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  260. :picker-options="column.pickerOptions" style="width: 100%">
  261. </el-date-picker>
  262. <el-checkbox v-if="column.inputType === 'Checkbox'" v-model="params[column.key]" :disabled="column.disabled"
  263. true-label="Y" false-label="N">
  264. </el-checkbox>
  265. <file-upload-center v-if="column.inputType === 'Upload'" v-model="params[column.key]"
  266. :file-type="column.fileType">
  267. </file-upload-center>
  268. </el-form-item>
  269. </el-col>
  270. </el-row>
  271. </el-card>
  272. <el-card :body-style="{
  273. padding: '20px',
  274. display: 'flex',
  275. 'flex-wrap': 'wrap',
  276. position: 'relative',
  277. }" style="margin: 10px">
  278. <el-tabs v-model="tabName" style="width: 100%">
  279. <el-tab-pane v-for="(column, index) in tabColumns" :key="index" :label="column.title" :name="column.key">
  280. <el-table :data="params[column.key]" style="width: 100%">
  281. <el-table-column label="序号">
  282. <template slot-scope="scope">
  283. {{ scope.$index + 1 }}
  284. </template>
  285. </el-table-column>
  286. <el-table-column v-for="(cColumn, cIndex) in column.tableColumns" :key="cIndex" :prop="cColumn.key"
  287. :label="cColumn.title" :width="cColumn.width">
  288. <template slot-scope="scope">
  289. <span v-if="!cColumn.inputType">
  290. {{ scope.row[cColumn.key] }}
  291. </span>
  292. <el-input v-if="cColumn.inputType === 'Input'" v-model="scope.row[cColumn.key]"
  293. :placeholder="cColumn.placeholder" :clearable="cColumn.clearable" :disabled="cColumn.disabled"
  294. :size="size" style="width: 100%">
  295. </el-input>
  296. <dr-popover-select v-if="cColumn.inputType === 'PopoverSelect'" v-model="scope.row[cColumn.key]"
  297. :source.sync="scope.row" :title="cColumn.title" :value-key="cColumn.valueKey"
  298. :disabled="cColumn.disabled" :type="cColumn.referName" :multiple="cColumn.multiple"
  299. :placeholder="cColumn.placeholder" :data-mapping="cColumn.dataMapping"
  300. :query-params="cColumn.queryParams(scope.row)" size="mini" @change="handleReferChange">
  301. </dr-popover-select>
  302. <el-select v-if="cColumn.inputType === 'Select'" v-model="scope.row[cColumn.key]" size="mini"
  303. :disabled="cColumn.disabled" :clearable="cColumn.clearable" :placeholder="cColumn.placeholder"
  304. style="width: 100%">
  305. <el-option v-for="item in dict.type[cColumn.referName]" :key="item.value" :label="item.label"
  306. :value="item.value">
  307. </el-option>
  308. </el-select>
  309. <el-checkbox v-if="cColumn.inputType === 'Checkbox'" v-model="scope.row[cColumn.key]"
  310. :disabled="cColumn.disabled" true-label="Y" false-label="N">
  311. </el-checkbox>
  312. <el-input-number v-if="cColumn.inputType === 'InputNumber'" v-model="scope.row[cColumn.key]"
  313. :controls-position="cColumn.controlsPosition"
  314. :max="handleIsRevise(params.status) ? scope.row[cColumn.key] : 'Infinity'"
  315. @change="handleInputChange(scope.row, cColumn.key)" :placeholder="cColumn.placeholder"
  316. :clearable="cColumn.clearable" :disabled="cColumn.disabled" :size="size" style="width: 100%">
  317. </el-input-number>
  318. </template>
  319. </el-table-column>
  320. <!-- 修订:不可删除、增行
  321. 编辑:自制:可删可增 -->
  322. <el-table-column fixed="right" label="操作" width="120">
  323. <template slot-scope="scope">
  324. <el-button v-if="params.source == '3' && !handleIsRevise(params.status)" @click.native.prevent="
  325. delTableRow(params[tabName], scope.$index)
  326. " type="text" size="small">
  327. 删行
  328. </el-button>
  329. </template>
  330. </el-table-column>
  331. </el-table>
  332. </el-tab-pane>
  333. </el-tabs>
  334. <el-row style="position: absolute; top: 20px; right: 20px">
  335. <el-button v-if="params.source == '3' && !handleIsRevise(params.status)" :size="size"
  336. @click="addTableRow(params[tabName])">增行</el-button>
  337. </el-row>
  338. </el-card>
  339. </el-form>
  340. </el-drawer>
  341. </template>