index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <script>
  2. import { Columns, TabColumns } from "../column";
  3. import { ADD, CODE } from "@/api/business/purchase/contract";
  4. import { initDicts, initRules, initParams } from "@/utils/init";
  5. export default {
  6. name: "AddDialog",
  7. dicts: Array.from(
  8. new Set([
  9. ...initDicts(Columns),
  10. ...initDicts(TabColumns.map((item) => item.tableColumns))
  11. .flat()
  12. .filter((cItem) => cItem.inputType === "Select"),
  13. ])
  14. ),
  15. components: {},
  16. data() {
  17. return {
  18. size: "mini",
  19. visible: false,
  20. loading: false,
  21. columns: Columns,
  22. rules: initRules(Columns),
  23. params: {
  24. ...initParams(Columns),
  25. contractItemList: [],
  26. contractClauseList: [],
  27. contractExpenseList: [],
  28. contractAgreementList: [],
  29. contractApplyOrgList: [],
  30. },
  31. tabColumns: TabColumns,
  32. tabName: "contractItemList",
  33. };
  34. },
  35. computed: {},
  36. watch: {
  37. "params.contractType": function (newProp) {
  38. this.tabColumns = TabColumns.filter((element) =>
  39. newProp === "1" ? element.key !== "contractItemList" : element
  40. );
  41. this.tabName = this.tabColumns[0].key;
  42. },
  43. },
  44. methods: {
  45. //
  46. open() {
  47. const {
  48. deptId: puDept,
  49. deptName: puDeptName,
  50. id: buyer,
  51. name: buyerName,
  52. orgId: puOrg,
  53. orgName: puOrgName,
  54. } = this.$store.state.user;
  55. this.params.puOrg = puOrg;
  56. this.params.puOrgName = puOrgName;
  57. this.params.buyer = buyer;
  58. this.params.buyerName = buyerName;
  59. this.params.puDept = puDept;
  60. this.params.puDeptName = puDeptName;
  61. this.fetchCode();
  62. this.visible = true;
  63. },
  64. //
  65. hide() {
  66. this.visible = false;
  67. this.params = initParams(this.columns);
  68. this.tabName = this.tabColumns[0].key;
  69. },
  70. //
  71. async fetchCode() {
  72. try {
  73. this.loading = true;
  74. const code = await CODE();
  75. this.params.code = code;
  76. } catch (err) {
  77. //
  78. } finally {
  79. this.loading = false;
  80. }
  81. },
  82. //
  83. rowAdd(prop) {
  84. const tab = this.tabColumns.find((element) => element.key === prop);
  85. this.params[prop].push(initParams(tab.tableColumns));
  86. },
  87. //
  88. rowDelete(prop, index) {
  89. prop.splice(index, 1);
  90. },
  91. //
  92. sava() {
  93. this.visible = false;
  94. },
  95. //
  96. submit(prop) {
  97. this.$refs[prop].validate(async (valid) => {
  98. if (valid) {
  99. try {
  100. const createById = this.params.buyer;
  101. const createByName = this.params.buyerName;
  102. const updateById = this.$store.state.user.id;
  103. const updateByName = this.$store.state.user.name;
  104. const { code, msg } = await ADD({
  105. createById,
  106. createByName,
  107. updateById,
  108. updateByName,
  109. ...this.params,
  110. });
  111. if (code === 200) {
  112. this.hide();
  113. this.$emit("submit-success");
  114. this.$notify.success({ title: msg });
  115. } else {
  116. this.$notify.warning({ title: msg });
  117. }
  118. } catch (err) {
  119. //
  120. } finally {
  121. //
  122. }
  123. } else {
  124. return false;
  125. }
  126. });
  127. },
  128. },
  129. created() {},
  130. mounted() {},
  131. destroyed() {},
  132. };
  133. </script>
  134. <template>
  135. <el-dialog :visible.sync="visible" title="新增" fullscreen @close="hide">
  136. <el-form
  137. ref="ruleForm"
  138. v-loading="loading"
  139. :size="size"
  140. :rules="rules"
  141. :model="params"
  142. label-width="auto"
  143. label-position="right"
  144. >
  145. <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
  146. <el-col
  147. v-for="(column, index) in columns"
  148. :key="index"
  149. :span="column.span || 6"
  150. >
  151. <el-form-item :prop="column.key" :label="column.title">
  152. <el-input
  153. v-if="column.inputType === 'Input'"
  154. v-model="params[column.key]"
  155. :disabled="column.disabled"
  156. :clearable="column.clearable"
  157. :placeholder="column.placeholder"
  158. style="width: 100%"
  159. ></el-input>
  160. <dr-popover-select
  161. v-if="column.inputType === 'PopoverSelect'"
  162. v-model="params[column.key]"
  163. :source.sync="params"
  164. :title="column.title"
  165. :type="column.referName"
  166. :disabled="column.disabled"
  167. :readonly="column.readonly"
  168. :clearable="column.clearable"
  169. :placeholder="column.placeholder"
  170. :data-mapping="column.dataMapping"
  171. >
  172. </dr-popover-select>
  173. <el-input
  174. v-if="column.inputType === 'Textarea'"
  175. v-model="params[column.key]"
  176. type="textarea"
  177. :disabled="column.disabled"
  178. :clearable="column.clearable"
  179. :placeholder="column.placeholder"
  180. style="width: 100%"
  181. ></el-input>
  182. <el-input-number
  183. v-if="column.inputType === 'InputNumber'"
  184. v-model="params[column.key]"
  185. :disabled="column.disabled"
  186. :clearable="column.clearable"
  187. :placeholder="column.placeholder"
  188. :controls-position="column.controlsPosition"
  189. style="width: 100%"
  190. ></el-input-number>
  191. <el-select
  192. v-if="column.inputType === 'Select'"
  193. v-model="params[column.key]"
  194. :disabled="column.disabled"
  195. :clearable="column.clearable"
  196. :placeholder="column.placeholder"
  197. style="width: 100%"
  198. >
  199. <el-option
  200. v-for="item in dict.type[column.referName]"
  201. :key="item.value"
  202. :label="item.label"
  203. :value="item.value"
  204. >
  205. </el-option>
  206. </el-select>
  207. <el-date-picker
  208. v-if="column.inputType === 'DatePicker'"
  209. v-model="params[column.key]"
  210. :type="column.type"
  211. :disabled="column.disabled"
  212. :clearable="column.clearable"
  213. :placeholder="column.placeholder"
  214. :picker-options="column.pickerOptions"
  215. style="width: 100%"
  216. >
  217. </el-date-picker>
  218. <file-upload
  219. v-if="column.inputType === 'Upload'"
  220. v-model="params[column.key]"
  221. :file-type="column.fileType"
  222. ></file-upload>
  223. </el-form-item>
  224. </el-col>
  225. </el-row>
  226. <el-form-item label-width="0">
  227. <el-tabs v-model="tabName" tab-position="left" style="width: 100%">
  228. <el-tab-pane
  229. v-for="(column, index) in tabColumns"
  230. :key="index"
  231. :label="column.title"
  232. :name="column.key"
  233. >
  234. <el-table :data="params[column.key]" style="width: 100%">
  235. <el-table-column label="序号">
  236. <template slot-scope="scope">
  237. {{ scope.$index + 1 }}
  238. </template>
  239. </el-table-column>
  240. <el-table-column
  241. v-for="(cColumn, cIndex) in column.tableColumns"
  242. :key="cIndex"
  243. :prop="cColumn.key"
  244. :label="cColumn.title"
  245. :width="cColumn.width"
  246. >
  247. <template slot-scope="scope">
  248. <el-input
  249. v-if="cColumn.inputType === 'Input'"
  250. v-model="scope.row[cColumn.key]"
  251. :size="size"
  252. :disabled="cColumn.disabled"
  253. :clearable="cColumn.clearable"
  254. :placeholder="cColumn.placeholder"
  255. style="width: 100%"
  256. ></el-input>
  257. <dr-computed-input
  258. v-if="cColumn.inputType === 'ComputedInput'"
  259. v-model="scope.row[cColumn.key]"
  260. :source="scope.row"
  261. :computed="cColumn.computed"
  262. :placeholder="cColumn.placeholder"
  263. style="width: 100%"
  264. ></dr-computed-input>
  265. <dr-popover-select
  266. v-else-if="cColumn.inputType === 'PopoverSelect'"
  267. v-model="scope.row[cColumn.key]"
  268. :size="size"
  269. :title="cColumn.title"
  270. :source.sync="scope.row"
  271. :type="cColumn.referName"
  272. :disabled="cColumn.disabled"
  273. :readonly="cColumn.readonly"
  274. :clearable="cColumn.clearable"
  275. :placeholder="cColumn.placeholder"
  276. :data-mapping="cColumn.dataMapping"
  277. >
  278. </dr-popover-select>
  279. <el-input-number
  280. v-else-if="cColumn.inputType === 'InputNumber'"
  281. v-model="scope.row[cColumn.key]"
  282. :size="size"
  283. :disabled="cColumn.disabled"
  284. :clearable="cColumn.clearable"
  285. :placeholder="cColumn.placeholder"
  286. :controls-position="cColumn.controlsPosition"
  287. style="width: 100%"
  288. ></el-input-number>
  289. <el-select
  290. v-else-if="cColumn.inputType === 'Select'"
  291. v-model="scope.row[cColumn.key]"
  292. :disabled="cColumn.disabled"
  293. :clearable="cColumn.clearable"
  294. :placeholder="cColumn.placeholder"
  295. style="width: 100%"
  296. >
  297. <el-option
  298. v-for="item in dict.type[cColumn.referName]"
  299. :key="item.value"
  300. :label="item.label"
  301. :value="item.value"
  302. >
  303. </el-option>
  304. </el-select>
  305. <span v-else> {{ scope.row[cColumn.key] }}</span>
  306. </template>
  307. </el-table-column>
  308. <el-table-column fixed="right" label="操作" width="75">
  309. <template slot="header" slot-scope="scope">
  310. <el-button
  311. circle
  312. icon="el-icon-plus"
  313. :size="size"
  314. @click="rowAdd(tabName)"
  315. >
  316. </el-button>
  317. </template>
  318. <template slot-scope="scope">
  319. <el-button
  320. circle
  321. icon="el-icon-minus"
  322. :size="size"
  323. @click.native.prevent="
  324. rowDelete(params[tabName], scope.$index)
  325. "
  326. >
  327. </el-button>
  328. </template>
  329. </el-table-column>
  330. </el-table>
  331. </el-tab-pane>
  332. </el-tabs>
  333. </el-form-item>
  334. <el-form-item label-width="0" style="text-align: right">
  335. <el-button :size="size" @click="hide">取 消</el-button>
  336. <el-button :size="size" @click="sava">保 存</el-button>
  337. <el-button :size="size" @click="submit('ruleForm')"> 新 增 </el-button>
  338. </el-form-item>
  339. </el-form>
  340. </el-dialog>
  341. </template>