index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <script>
  2. import Column from "../add/column";
  3. import useData from "../hooks/data";
  4. import useDicts from "../hooks/dicts";
  5. import useWatch from "../hooks/watch";
  6. import { initParams } from "@/utils/init";
  7. import { REFER } from "@/components/popover-select/api";
  8. import { EDIT, ITEM, TABLE } from "@/api/business/purchase/contract";
  9. const { watchContractType } = useWatch();
  10. export default {
  11. name: "EditDrawer",
  12. dicts: useDicts(Column),
  13. data() {
  14. return {
  15. title: "更 新",
  16. ...useData(Column),
  17. };
  18. },
  19. computed: {
  20. root: function () {
  21. return this.$parent.$parent;
  22. },
  23. hasPowerAlteration: function () {
  24. return this.$parent.$parent.hasPowerAlteration;
  25. },
  26. },
  27. watch: {
  28. "params.contractType": watchContractType(),
  29. },
  30. methods: {
  31. async fetchRefer(prop, type, source) {
  32. const { rateCode } = prop;
  33. if (type === "MATERIAL_PARAM") {
  34. try {
  35. // try
  36. this.loading = true;
  37. const { code, rows } = await REFER({
  38. search: rateCode,
  39. type: "TAX_RATE_PARAM",
  40. });
  41. if (code === 200) {
  42. const [{ ntaxrate }] = rows;
  43. source.tax = ntaxrate === "0E-8" ? "0.00000000" : ntaxrate;
  44. }
  45. } catch (err) {
  46. // catch
  47. console.error(err);
  48. } finally {
  49. // finally
  50. this.loading = false;
  51. }
  52. }
  53. },
  54. async fetchItem(prop) {
  55. try {
  56. // try
  57. this.loading = true;
  58. const { code, data } = await ITEM(prop);
  59. if (code === 200) {
  60. this.params = data;
  61. return true;
  62. } else {
  63. return false;
  64. }
  65. } catch (err) {
  66. // catch
  67. console.error(err);
  68. } finally {
  69. // finally
  70. this.loading = false;
  71. }
  72. },
  73. //
  74. async open(prop) {
  75. this.visible = await this.fetchItem(prop);
  76. },
  77. //
  78. async hide() {
  79. this.visible = false;
  80. this.tabName = this.tabColumns[0].key;
  81. },
  82. //
  83. async useRowAdd(prop) {
  84. const { tableColumns } = this.tabColumns.find(
  85. (item) => item.key === prop
  86. );
  87. this.params[prop].push(initParams(tableColumns));
  88. },
  89. //
  90. async useRowRemove(prop, scope) {
  91. const { ROMVE } = TABLE;
  92. const {
  93. row: { id, contractId },
  94. } = scope;
  95. try {
  96. // try
  97. this.loading = true;
  98. const { code } = ROMVE(id, prop);
  99. if (code === 200) {
  100. this.fetchItem(contractId);
  101. }
  102. } catch (err) {
  103. // catch
  104. console.error(err);
  105. } finally {
  106. // finally
  107. this.loading = false;
  108. }
  109. },
  110. //
  111. async useRowSubmit(prop, scope) {
  112. const {
  113. row: { contractId },
  114. } = scope;
  115. const { id } = this.params;
  116. const { ADD, EDIT } = TABLE;
  117. try {
  118. // try
  119. this.loading = true;
  120. if (contractId) {
  121. await EDIT(row, prop);
  122. } else {
  123. await ADD({ ...row, contractId: id }, prop);
  124. }
  125. } catch (err) {
  126. // catch
  127. console.error(err);
  128. } finally {
  129. // finally
  130. this.fetchItem(id);
  131. this.loading = false;
  132. }
  133. },
  134. //
  135. async useSubmit(prop) {
  136. this.$refs[prop].validate(async (valid) => {
  137. if (valid) {
  138. try {
  139. // try
  140. this.loading = true;
  141. const params = { ...this.params };
  142. const { msg, code } = await EDIT(params);
  143. if (code === 200) {
  144. this.hide();
  145. this.$emit("success");
  146. this.$notify.success(msg);
  147. }
  148. } catch (err) {
  149. // catch
  150. console.error(err);
  151. } finally {
  152. // finally
  153. this.loading = false;
  154. }
  155. } else {
  156. return false;
  157. }
  158. });
  159. },
  160. //
  161. async useAlteration(prop) {
  162. await this.root
  163. .useAlteration(prop)
  164. .then(() => {
  165. this.hide();
  166. })
  167. .catch(() => {});
  168. },
  169. },
  170. created() {},
  171. mounted() {},
  172. destroyed() {},
  173. };
  174. </script>
  175. <template>
  176. <el-drawer
  177. :size="width"
  178. :title="title"
  179. :show-close="false"
  180. :visible.sync="visible"
  181. >
  182. <template slot="title">
  183. <span>{{ title }}</span>
  184. <span>
  185. <el-tooltip
  186. v-if="root.hasPowerAlteration([params])"
  187. effect="dark"
  188. content="变 更"
  189. placement="bottom-end"
  190. >
  191. <el-button
  192. :size="size"
  193. circle
  194. icon="el-icon-check"
  195. @click="useAlteration([params])"
  196. >
  197. </el-button>
  198. </el-tooltip>
  199. <el-tooltip v-else effect="dark" content="更 新" placement="bottom-end">
  200. <el-button
  201. :size="size"
  202. circle
  203. icon="el-icon-check"
  204. @click="useSubmit('ruleForm')"
  205. >
  206. </el-button>
  207. </el-tooltip>
  208. <el-button
  209. :size="size"
  210. circle
  211. type="danger"
  212. icon="el-icon-close"
  213. @click="hide"
  214. ></el-button>
  215. </span>
  216. </template>
  217. <el-form
  218. ref="ruleForm"
  219. v-loading="loading"
  220. :size="size"
  221. :rules="rules"
  222. :model="params"
  223. label-width="auto"
  224. label-position="right"
  225. style="padding: 10px"
  226. >
  227. <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
  228. <el-col
  229. v-for="(column, index) in formColumns"
  230. :key="index"
  231. :span="column.span || 6"
  232. >
  233. <el-form-item :prop="column.key" :label="column.title">
  234. <el-input
  235. v-if="column.inputType === 'Input'"
  236. v-model="params[column.key]"
  237. :disabled="column.disabled"
  238. :clearable="column.clearable"
  239. :placeholder="column.placeholder"
  240. style="width: 100%"
  241. ></el-input>
  242. <dr-popover-select
  243. v-if="column.inputType === 'PopoverSelect'"
  244. v-model="params[column.key]"
  245. :source.sync="params"
  246. :title="column.title"
  247. :type="column.referName"
  248. :disabled="column.disabled"
  249. :readonly="column.readonly"
  250. :clearable="column.clearable"
  251. :placeholder="column.placeholder"
  252. :data-mapping="column.dataMapping"
  253. >
  254. </dr-popover-select>
  255. <el-input
  256. v-if="column.inputType === 'Textarea'"
  257. v-model="params[column.key]"
  258. type="textarea"
  259. :disabled="column.disabled"
  260. :clearable="column.clearable"
  261. :placeholder="column.placeholder"
  262. style="width: 100%"
  263. ></el-input>
  264. <el-input-number
  265. v-if="column.inputType === 'InputNumber'"
  266. v-model="params[column.key]"
  267. :disabled="column.disabled"
  268. :clearable="column.clearable"
  269. :placeholder="column.placeholder"
  270. :controls-position="column.controlsPosition"
  271. style="width: 100%"
  272. ></el-input-number>
  273. <el-select
  274. v-if="column.inputType === 'Select'"
  275. v-model="params[column.key]"
  276. :disabled="column.disabled"
  277. :clearable="column.clearable"
  278. :placeholder="column.placeholder"
  279. style="width: 100%"
  280. >
  281. <el-option
  282. v-for="item in dict.type[column.referName]"
  283. :key="item.value"
  284. :label="item.label"
  285. :value="item.value"
  286. >
  287. </el-option>
  288. </el-select>
  289. <el-date-picker
  290. v-if="column.inputType === 'DatePicker'"
  291. v-model="params[column.key]"
  292. :type="column.type"
  293. :disabled="column.disabled"
  294. :clearable="column.clearable"
  295. :placeholder="column.placeholder"
  296. :value-format="column.valueFormat"
  297. :picker-options="column.pickerOptions"
  298. style="width: 100%"
  299. >
  300. </el-date-picker>
  301. <file-upload
  302. v-if="column.inputType === 'Upload'"
  303. v-model="params[column.key]"
  304. :file-type="column.fileType"
  305. ></file-upload>
  306. </el-form-item>
  307. </el-col>
  308. <el-col :span="24">
  309. <el-form-item label-width="0">
  310. <el-tabs v-model="tabName">
  311. <el-tab-pane
  312. v-for="(column, index) in tabColumns"
  313. :key="index"
  314. :label="column.title"
  315. :name="column.key"
  316. lazy
  317. >
  318. <el-table :size="size" :data="params[column.key]">
  319. <el-table-column label="序号">
  320. <template slot-scope="scope">
  321. {{ scope.$index + 1 }}
  322. </template>
  323. </el-table-column>
  324. <el-table-column
  325. v-for="(cColumn, cIndex) in column.tableColumns"
  326. :key="cIndex"
  327. :prop="cColumn.key"
  328. :label="cColumn.title"
  329. :width="cColumn.width"
  330. show-overflow-tooltip
  331. >
  332. <template slot-scope="scope">
  333. <el-input
  334. v-if="cColumn.inputType === 'Input'"
  335. v-model="scope.row[cColumn.key]"
  336. :size="size"
  337. :disabled="cColumn.disabled"
  338. :clearable="cColumn.clearable"
  339. :placeholder="cColumn.placeholder"
  340. style="width: 100%"
  341. ></el-input>
  342. <dr-computed-input
  343. v-else-if="cColumn.inputType === 'ComputedInput'"
  344. v-model="scope.row[cColumn.key]"
  345. :source="scope.row"
  346. :computed="cColumn.computed"
  347. :placeholder="cColumn.placeholder"
  348. style="width: 100%"
  349. ></dr-computed-input>
  350. <dr-popover-select
  351. v-else-if="cColumn.inputType === 'PopoverSelect'"
  352. v-model="scope.row[cColumn.key]"
  353. :size="size"
  354. :title="cColumn.title"
  355. :source.sync="scope.row"
  356. :type="cColumn.referName"
  357. :disabled="cColumn.disabled"
  358. :readonly="cColumn.readonly"
  359. :clearable="cColumn.clearable"
  360. :placeholder="cColumn.placeholder"
  361. :data-mapping="cColumn.dataMapping"
  362. @change="fetchRefer"
  363. >
  364. </dr-popover-select>
  365. <el-input-number
  366. v-else-if="cColumn.inputType === 'InputNumber'"
  367. v-model="scope.row[cColumn.key]"
  368. :size="size"
  369. :disabled="cColumn.disabled"
  370. :clearable="cColumn.clearable"
  371. :placeholder="cColumn.placeholder"
  372. :controls-position="cColumn.controlsPosition"
  373. style="width: 100%"
  374. ></el-input-number>
  375. <el-select
  376. v-else-if="cColumn.inputType === 'Select'"
  377. v-model="scope.row[cColumn.key]"
  378. :disabled="cColumn.disabled"
  379. :clearable="cColumn.clearable"
  380. :placeholder="cColumn.placeholder"
  381. style="width: 100%"
  382. >
  383. <el-option
  384. v-for="item in dict.type[cColumn.referName]"
  385. :key="item.value"
  386. :label="item.label"
  387. :value="item.value"
  388. >
  389. </el-option>
  390. </el-select>
  391. <span v-else> {{ scope.row[cColumn.key] }}</span>
  392. </template>
  393. </el-table-column>
  394. <el-table-column fixed="right" label="操作" width="100">
  395. <template slot="header" slot-scope="scope">
  396. <el-button
  397. circle
  398. icon="el-icon-plus"
  399. :size="size"
  400. @click="useRowAdd(tabName)"
  401. >
  402. </el-button>
  403. </template>
  404. <template slot-scope="scope">
  405. <el-button
  406. circle
  407. icon="el-icon-check"
  408. :size="size"
  409. @click.native.prevent="useRowSubmit(tabName, scope)"
  410. >
  411. </el-button>
  412. <el-button
  413. circle
  414. icon="el-icon-minus"
  415. :size="size"
  416. @click.native.prevent="useRowRemove(tabName, scope)"
  417. >
  418. </el-button>
  419. </template>
  420. </el-table-column>
  421. </el-table>
  422. </el-tab-pane>
  423. </el-tabs>
  424. </el-form-item>
  425. </el-col>
  426. </el-row>
  427. </el-form>
  428. </el-drawer>
  429. </template>