index.vue 10 KB

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