index.vue 12 KB

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