index.vue 12 KB

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