index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <script>
  2. import { Columns, TabColumns } from "../add/column";
  3. import {
  4. edit,
  5. item,
  6. itemTableList,
  7. } from "@/api/business/purchase/contract";
  8. import { initColumns, initDicts, initRules, initParams } from "@/utils/init";
  9. const NewColumns = initColumns(Columns);
  10. const NewTabColumns = TabColumns.map((element) => ({
  11. ...element,
  12. tableColumns: initColumns(element.tableColumns),
  13. }));
  14. export default {
  15. name: "EditDrawer",
  16. dicts: initDicts(NewColumns),
  17. components: {
  18. },
  19. data() {
  20. return {
  21. size: "mini",
  22. visible: false,
  23. loading: false,
  24. columns: NewColumns,
  25. rules: initRules(NewColumns),
  26. params: {
  27. ...initParams(NewColumns),
  28. contractItemList: [],
  29. contractClauseList: [],
  30. contractExpenseList: [],
  31. contractAgreementList: [],
  32. contractApplyOrgList: [],
  33. },
  34. tabColumns: NewTabColumns,
  35. tabName: "contractItemList",
  36. };
  37. },
  38. computed: {},
  39. watch: {
  40. "params.contractType": function (newProp) {
  41. this.tabColumns = NewTabColumns.filter((element) =>
  42. newProp === "1" ? element.key !== "contractItemList" : 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. },
  51. methods: {
  52. setVisible(prop) {
  53. this.visible = prop;
  54. },
  55. // 查询详细
  56. async fetchItem(prop) {
  57. try {
  58. this.loading = true;
  59. const { code, msg, data } = await item(prop);
  60. if (code === 200) {
  61. this.params = data;
  62. this.$notify.success({ title: msg });
  63. } else {
  64. this.$notify.warning({ title: msg });
  65. }
  66. } catch (err) {
  67. this.$notify.error({ title: "error", message: err });
  68. } finally {
  69. this.loading = false;
  70. }
  71. },
  72. // 查询详情关联TABLE
  73. async fetchTable(prop, name) {
  74. try {
  75. this.loading = true;
  76. const { code, msg, rows } = await itemTableList({ id: prop }, name);
  77. if (code === 200) {
  78. this.params[name] = rows;
  79. this.$notify.success({ title: msg });
  80. } else {
  81. this.$notify.warning({ title: msg });
  82. }
  83. } catch (err) {
  84. this.$notify.error({ title: "error", message: err });
  85. } finally {
  86. this.loading = false;
  87. }
  88. },
  89. // 新增行
  90. addTableRow(prop) {
  91. const arr = this.tabColumns.find(
  92. (element) => element.key === this.tabName
  93. ).tableColumns;
  94. prop.push(initParams(arr, "key", "value"));
  95. },
  96. // 删除行
  97. delTableRow(prop, index) {
  98. prop.splice(index, 1);
  99. },
  100. // 取消
  101. handleCancel() {
  102. this.setVisible(false);
  103. this.params = initParams(this.columns, "key", "value");
  104. },
  105. // 保存
  106. handleSava() {
  107. this.setVisible(false);
  108. },
  109. // 保存并新增
  110. async handleSubmit() {
  111. try {
  112. const createById = this.params.buyer;
  113. const createByName = this.params.buyerName;
  114. const updateById = this.$store.state.user.id;
  115. const updateByName = this.$store.state.user.name;
  116. const { code, msg } = await edit({
  117. createById,
  118. createByName,
  119. updateById,
  120. updateByName,
  121. ...this.params,
  122. });
  123. if (code === 200) {
  124. this.$notify.success({ title: msg });
  125. this.setVisible(false);
  126. } else {
  127. this.$notify.warning({ title: msg });
  128. }
  129. } catch (err) {
  130. this.$notify.error({ title: "error", message: err });
  131. } finally {
  132. // this.setVisible(false);
  133. }
  134. },
  135. },
  136. created() {
  137. console.log("ADD CREATED");
  138. },
  139. mounted() { },
  140. destroyed() { },
  141. };
  142. </script>
  143. <template>
  144. <el-drawer direction="btt" size="100%" :with-header="false" :visible.sync="visible" @open="beforeOpen"
  145. @close="$emit('close')">
  146. <el-form v-loading="loading" :size="size" label-position="right" label-width="135px" :model="params" :rules="rules">
  147. <el-card :body-style="{
  148. padding: '20px',
  149. display: 'flex',
  150. 'flex-wrap': 'wrap',
  151. }" style="margin: 10px">
  152. <div slot="header" style="
  153. display: flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. ">
  157. <h3>编辑</h3>
  158. <div style="text-align: right">
  159. <el-button :size="size" @click="handleCancel">取 消</el-button>
  160. <el-button :size="size" type="danger" @click="handleSava">更 新</el-button>
  161. </div>
  162. </div>
  163. <el-row>
  164. <el-col v-for="(column, index) in columns" :key="index" :span="column.span || 6">
  165. <el-form-item :prop="column.key" :label="column.title">
  166. <el-input v-if="column.type === 'Input'" v-model="params[column.key]" :placeholder="column.placeholder"
  167. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%"></el-input>
  168. <dr-popover-select v-if="column.type === 'InputDialog'" v-model="params[column.key]" :source.sync="params"
  169. :type="column.config.componentName" :data-mapping="column.config.dataMapping" :title="column.title"
  170. :disabled="column.disabled" :readonly="column.readonly" :clearable="column.clearable"
  171. :placeholder="column.placeholder">
  172. </dr-popover-select>
  173. <el-input v-if="column.type === 'Textarea'" v-model="params[column.key]" type="textarea"
  174. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  175. style="width: 100%"></el-input>
  176. <el-input-number v-if="column.type === 'InputNumber'" v-model="params[column.key]"
  177. :controls-position="column.config.controlsPosition" :placeholder="column.placeholder"
  178. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%"></el-input-number>
  179. <el-select v-if="column.type === 'Select'" v-model="params[column.key]" :placeholder="column.placeholder"
  180. :clearable="column.clearable" :disabled="column.disabled" style="width: 100%">
  181. <el-option v-for="item in dict.type[column.config.optionsName]" :key="item.value" :label="item.label"
  182. :value="item.value">
  183. </el-option>
  184. </el-select>
  185. <el-select v-if="column.type === 'TagSelect'" v-model="params[column.key]" multiple clearable collapse-tags
  186. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  187. style="width: 100%">
  188. <template #prefix>
  189. <el-icon class="el-icon-view" style="cursor: pointer" @click.stop="$message.info(234)"></el-icon>
  190. </template>
  191. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  192. </el-option>
  193. </el-select>
  194. <el-date-picker v-if="column.type === 'DatePicker'" v-model="params[column.key]" :type="column.config.type"
  195. :placeholder="column.placeholder" :clearable="column.clearable" :disabled="column.disabled"
  196. :picker-options="column.pickerOptions" style="width: 100%">
  197. </el-date-picker>
  198. <el-upload v-if="column.type === 'Upload'" :file-list="params[column.key]" :disabled="column.disabled" drag
  199. action="https://sy.derom.com/document-center/fastdfs/upload" multiple>
  200. <i class="el-icon-upload"></i>
  201. <div class="el-upload__text">
  202. 将文件拖到此处,或<em>点击上传</em>
  203. </div>
  204. <!-- <div class="el-upload__tip" slot="tip">
  205. 只能上传jpg/png文件,且不超过500kb
  206. </div> -->
  207. </el-upload>
  208. </el-form-item>
  209. </el-col>
  210. </el-row>
  211. </el-card>
  212. <el-card :body-style="{
  213. padding: '20px',
  214. display: 'flex',
  215. 'flex-wrap': 'wrap',
  216. position: 'relative',
  217. }" style="margin: 10px">
  218. <el-tabs v-model="tabName" style="width: 100%">
  219. <el-tab-pane v-for="(column, index) in tabColumns" :key="index" :label="column.title" :name="column.key">
  220. <el-table :data="params[column.key]" style="width: 100%">
  221. <el-table-column label="序号">
  222. <template slot-scope="scope">
  223. {{ scope.$index + 1 }}
  224. </template>
  225. </el-table-column>
  226. <el-table-column v-for="(cColumn, cIndex) in column.tableColumns" :key="cIndex" :prop="cColumn.key"
  227. :label="cColumn.title" :width="cColumn.width">
  228. <template slot-scope="scope">
  229. <span v-if="!cColumn.type">
  230. {{ scope.row[cColumn.key] }}</span>
  231. <el-input v-if="cColumn.type === 'Input'" v-model="scope.row[cColumn.key]"
  232. :placeholder="cColumn.placeholder" :clearable="cColumn.clearable" :disabled="cColumn.disabled"
  233. :size="size" style="width: 100%"></el-input>
  234. <dr-popover-select v-if="cColumn.type === 'InputDialog'" v-model="scope.row[cColumn.key]"
  235. :placeholder="cColumn.placeholder" :clearable="cColumn.clearable" :disabled="cColumn.disabled"
  236. :readonly="cColumn.readonly" :title="cColumn.title" :type="cColumn.config.componentName"
  237. :data-mapping="cColumn.config.dataMapping" :source.sync="scope.row" :size="size">
  238. </dr-popover-select>
  239. <el-input-number v-if="cColumn.type === 'InputNumber'" v-model="scope.row[cColumn.key]"
  240. :controls-position="cColumn.config.controlsPosition" :placeholder="cColumn.placeholder"
  241. :clearable="cColumn.clearable" :disabled="cColumn.disabled" :size="size"
  242. style="width: 100%"></el-input-number>
  243. </template>
  244. </el-table-column>
  245. <el-table-column fixed="right" label="操作" width="120">
  246. <template slot-scope="scope">
  247. <el-button @click.native.prevent="
  248. delTableRow(params[tabName], scope.$index)
  249. " type="text" size="small">
  250. 删行
  251. </el-button>
  252. </template>
  253. </el-table-column>
  254. </el-table>
  255. </el-tab-pane>
  256. </el-tabs>
  257. <el-row style="position: absolute; top: 20px; right: 20px">
  258. <el-button :size="size" @click="addTableRow(params[tabName])">增行</el-button>
  259. </el-row>
  260. </el-card>
  261. </el-form>
  262. </el-drawer>
  263. </template>