index.vue 13 KB

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