index.vue 12 KB

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