index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <script>
  2. import { Columns, TabColumns } from "../column";
  3. import { edit, item, itemTableList } from "@/api/business/purchase/contract";
  4. import { initColumns, initDicts, initRules, initParams } from "@/utils/init";
  5. const NewColumns = initColumns(Columns);
  6. const NewTabColumns = TabColumns.map((element) => ({
  7. ...element,
  8. tableColumns: initColumns(element.tableColumns),
  9. }));
  10. export default {
  11. name: "EditDrawer",
  12. dicts: initDicts(NewColumns),
  13. components: {},
  14. data() {
  15. return {
  16. size: "mini",
  17. visible: false,
  18. loading: false,
  19. columns: NewColumns,
  20. rules: initRules(NewColumns),
  21. params: {
  22. ...initParams(NewColumns),
  23. contractItemList: [],
  24. contractClauseList: [],
  25. contractExpenseList: [],
  26. contractAgreementList: [],
  27. contractApplyOrgList: [],
  28. },
  29. tabColumns: NewTabColumns,
  30. tabName: "contractItemList",
  31. };
  32. },
  33. computed: {},
  34. watch: {
  35. "params.contractType": function (newProp) {
  36. this.tabColumns = NewTabColumns.filter((element) =>
  37. newProp === "1" ? element.key !== "contractItemList" : element
  38. );
  39. this.tabName = this.tabColumns[0].key;
  40. },
  41. tabName: function (newProp) {
  42. const { id } = this.params;
  43. this.fetchTable(id, newProp);
  44. },
  45. },
  46. methods: {
  47. setVisible(prop) {
  48. this.visible = prop;
  49. },
  50. // 查询详细
  51. async fetchItem(prop) {
  52. try {
  53. this.loading = true;
  54. const { code, msg, data } = await item(prop);
  55. if (code === 200) {
  56. this.params = data;
  57. this.$notify.success({ title: msg });
  58. } else {
  59. this.$notify.warning({ title: msg });
  60. }
  61. } catch (err) {
  62. //
  63. } finally {
  64. this.loading = false;
  65. }
  66. },
  67. // 查询详情关联TABLE
  68. async fetchTable(prop, name) {
  69. try {
  70. this.loading = true;
  71. const { code, msg, rows } = await itemTableList({ id: prop }, name);
  72. if (code === 200) {
  73. this.params[name] = rows;
  74. this.$notify.success({ title: msg });
  75. } else {
  76. this.$notify.warning({ title: msg });
  77. }
  78. } catch (err) {
  79. //
  80. } finally {
  81. this.loading = false;
  82. }
  83. },
  84. // 新增行
  85. addTableRow(prop) {
  86. const arr = this.tabColumns.find(
  87. (element) => element.key === this.tabName
  88. ).tableColumns;
  89. prop.push(initParams(arr, "key", "value"));
  90. },
  91. // 删除行
  92. delTableRow(prop, index) {
  93. prop.splice(index, 1);
  94. },
  95. // 取消
  96. handleCancel() {
  97. this.setVisible(false);
  98. this.params = initParams(this.columns, "key", "value");
  99. },
  100. // 保存
  101. handleSava() {
  102. this.setVisible(false);
  103. },
  104. // 保存并新增
  105. async handleSubmit() {
  106. try {
  107. const createById = this.params.buyer;
  108. const createByName = this.params.buyerName;
  109. const updateById = this.$store.state.user.id;
  110. const updateByName = this.$store.state.user.name;
  111. const { code, msg } = await edit({
  112. createById,
  113. createByName,
  114. updateById,
  115. updateByName,
  116. ...this.params,
  117. });
  118. if (code === 200) {
  119. this.$notify.success({ title: msg });
  120. this.setVisible(false);
  121. } else {
  122. this.$notify.warning({ title: msg });
  123. }
  124. } catch (err) {
  125. //
  126. } finally {
  127. // this.setVisible(false);
  128. }
  129. },
  130. },
  131. created() {
  132. console.log("ADD CREATED");
  133. },
  134. mounted() {},
  135. destroyed() {},
  136. };
  137. </script>
  138. <template>
  139. <el-drawer
  140. direction="btt"
  141. size="100%"
  142. :with-header="false"
  143. :visible.sync="visible"
  144. @open="beforeOpen"
  145. @close="$emit('close')"
  146. >
  147. <el-form
  148. v-loading="loading"
  149. :size="size"
  150. label-position="right"
  151. label-width="135px"
  152. :model="params"
  153. :rules="rules"
  154. >
  155. <el-card
  156. :body-style="{
  157. padding: '20px',
  158. display: 'flex',
  159. 'flex-wrap': 'wrap',
  160. }"
  161. style="margin: 10px"
  162. >
  163. <div
  164. slot="header"
  165. style="
  166. display: flex;
  167. justify-content: space-between;
  168. align-items: center;
  169. "
  170. >
  171. <h3>编辑</h3>
  172. <div style="text-align: right">
  173. <el-button :size="size" @click="handleCancel">取 消</el-button>
  174. <el-button :size="size" type="danger" @click="handleSava"
  175. >更 新</el-button
  176. >
  177. </div>
  178. </div>
  179. <el-row>
  180. <el-col
  181. v-for="(column, index) in columns"
  182. :key="index"
  183. :span="column.span || 6"
  184. >
  185. <el-form-item :prop="column.key" :label="column.title">
  186. <el-input
  187. v-if="column.type === 'Input'"
  188. v-model="params[column.key]"
  189. :placeholder="column.placeholder"
  190. :clearable="column.clearable"
  191. :disabled="column.disabled"
  192. style="width: 100%"
  193. ></el-input>
  194. <dr-popover-select
  195. v-if="column.type === 'InputDialog'"
  196. v-model="params[column.key]"
  197. :source.sync="params"
  198. :type="column.config.componentName"
  199. :data-mapping="column.config.dataMapping"
  200. :title="column.title"
  201. :disabled="column.disabled"
  202. :readonly="column.readonly"
  203. :clearable="column.clearable"
  204. :placeholder="column.placeholder"
  205. >
  206. </dr-popover-select>
  207. <el-input
  208. v-if="column.type === 'Textarea'"
  209. v-model="params[column.key]"
  210. type="textarea"
  211. :placeholder="column.placeholder"
  212. :clearable="column.clearable"
  213. :disabled="column.disabled"
  214. style="width: 100%"
  215. ></el-input>
  216. <el-input-number
  217. v-if="column.type === 'InputNumber'"
  218. v-model="params[column.key]"
  219. :controls-position="column.config.controlsPosition"
  220. :placeholder="column.placeholder"
  221. :clearable="column.clearable"
  222. :disabled="column.disabled"
  223. style="width: 100%"
  224. ></el-input-number>
  225. <el-select
  226. v-if="column.type === 'Select'"
  227. v-model="params[column.key]"
  228. :placeholder="column.placeholder"
  229. :clearable="column.clearable"
  230. :disabled="column.disabled"
  231. style="width: 100%"
  232. >
  233. <el-option
  234. v-for="item in dict.type[column.config.optionsName]"
  235. :key="item.value"
  236. :label="item.label"
  237. :value="item.value"
  238. >
  239. </el-option>
  240. </el-select>
  241. <el-select
  242. v-if="column.type === 'TagSelect'"
  243. v-model="params[column.key]"
  244. multiple
  245. clearable
  246. collapse-tags
  247. :placeholder="column.placeholder"
  248. :clearable="column.clearable"
  249. :disabled="column.disabled"
  250. style="width: 100%"
  251. >
  252. <template #prefix>
  253. <el-icon
  254. class="el-icon-view"
  255. style="cursor: pointer"
  256. @click.stop="$message.info(234)"
  257. ></el-icon>
  258. </template>
  259. <el-option
  260. v-for="item in options"
  261. :key="item.value"
  262. :label="item.label"
  263. :value="item.value"
  264. >
  265. </el-option>
  266. </el-select>
  267. <el-date-picker
  268. v-if="column.type === 'DatePicker'"
  269. v-model="params[column.key]"
  270. :type="column.config.type"
  271. :placeholder="column.placeholder"
  272. :clearable="column.clearable"
  273. :disabled="column.disabled"
  274. :picker-options="column.pickerOptions"
  275. style="width: 100%"
  276. >
  277. </el-date-picker>
  278. <el-upload
  279. v-if="column.type === 'Upload'"
  280. :file-list="params[column.key]"
  281. :disabled="column.disabled"
  282. drag
  283. action="https://sy.derom.com/document-center/fastdfs/upload"
  284. multiple
  285. >
  286. <i class="el-icon-upload"></i>
  287. <div class="el-upload__text">
  288. 将文件拖到此处,或<em>点击上传</em>
  289. </div>
  290. <!-- <div class="el-upload__tip" slot="tip">
  291. 只能上传jpg/png文件,且不超过500kb
  292. </div> -->
  293. </el-upload>
  294. </el-form-item>
  295. </el-col>
  296. </el-row>
  297. </el-card>
  298. <el-card
  299. :body-style="{
  300. padding: '20px',
  301. display: 'flex',
  302. 'flex-wrap': 'wrap',
  303. position: 'relative',
  304. }"
  305. style="margin: 10px"
  306. >
  307. <el-tabs v-model="tabName" style="width: 100%">
  308. <el-tab-pane
  309. v-for="(column, index) in tabColumns"
  310. :key="index"
  311. :label="column.title"
  312. :name="column.key"
  313. >
  314. <el-table :data="params[column.key]" style="width: 100%">
  315. <el-table-column label="序号">
  316. <template slot-scope="scope">
  317. {{ scope.$index + 1 }}
  318. </template>
  319. </el-table-column>
  320. <el-table-column
  321. v-for="(cColumn, cIndex) in column.tableColumns"
  322. :key="cIndex"
  323. :prop="cColumn.key"
  324. :label="cColumn.title"
  325. :width="cColumn.width"
  326. >
  327. <template slot-scope="scope">
  328. <span v-if="!cColumn.type">
  329. {{ scope.row[cColumn.key] }}</span
  330. >
  331. <el-input
  332. v-if="cColumn.type === 'Input'"
  333. v-model="scope.row[cColumn.key]"
  334. :placeholder="cColumn.placeholder"
  335. :clearable="cColumn.clearable"
  336. :disabled="cColumn.disabled"
  337. :size="size"
  338. style="width: 100%"
  339. ></el-input>
  340. <dr-popover-select
  341. v-if="cColumn.type === 'InputDialog'"
  342. v-model="scope.row[cColumn.key]"
  343. :placeholder="cColumn.placeholder"
  344. :clearable="cColumn.clearable"
  345. :disabled="cColumn.disabled"
  346. :readonly="cColumn.readonly"
  347. :title="cColumn.title"
  348. :type="cColumn.config.componentName"
  349. :data-mapping="cColumn.config.dataMapping"
  350. :source.sync="scope.row"
  351. :size="size"
  352. >
  353. </dr-popover-select>
  354. <el-input-number
  355. v-if="cColumn.type === 'InputNumber'"
  356. v-model="scope.row[cColumn.key]"
  357. :controls-position="cColumn.config.controlsPosition"
  358. :placeholder="cColumn.placeholder"
  359. :clearable="cColumn.clearable"
  360. :disabled="cColumn.disabled"
  361. :size="size"
  362. style="width: 100%"
  363. ></el-input-number>
  364. </template>
  365. </el-table-column>
  366. <el-table-column fixed="right" label="操作" width="120">
  367. <template slot-scope="scope">
  368. <el-button
  369. @click.native.prevent="
  370. delTableRow(params[tabName], scope.$index)
  371. "
  372. type="text"
  373. size="small"
  374. >
  375. 删行
  376. </el-button>
  377. </template>
  378. </el-table-column>
  379. </el-table>
  380. </el-tab-pane>
  381. </el-tabs>
  382. <el-row style="position: absolute; top: 20px; right: 20px">
  383. <el-button :size="size" @click="addTableRow(params[tabName])"
  384. >增行</el-button
  385. >
  386. </el-row>
  387. </el-card>
  388. </el-form>
  389. </el-drawer>
  390. </template>