index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. root: function () {
  27. return this.$parent.$parent;
  28. },
  29. },
  30. watch: {
  31. "params.puOrgName": watchPuOrgName(),
  32. "params.priceApplyOrgs": watchPriceApplyOrgs(),
  33. "params.priceApplyItems": watchPriceApplyItems(),
  34. },
  35. methods: {
  36. //
  37. async fetchRefer(prop, type, source) {
  38. const { fetchTax, fetchUnit, fetchExist } = useMethods();
  39. if (type === "MATERIAL_PARAM") {
  40. const { puOrg, customer, supplier } = this.params;
  41. const { rateCode, unitIdName, code: materialCode } = prop;
  42. // task 1
  43. fetchTax(rateCode).then(({ ntaxrate }) => {
  44. source.tax = ntaxrate === "0E-8" ? "0.00000000" : ntaxrate;
  45. });
  46. // task 2
  47. fetchUnit(unitIdName).then(({ id, code, name }) => {
  48. source.unit = id;
  49. source.unitCode = code;
  50. source.unitName = name;
  51. source.puUnit = id;
  52. source.puUnitCode = code;
  53. source.puUnitName = name;
  54. });
  55. // task 3
  56. fetchExist({ puOrg, customer, supplier, materialCode }).then(
  57. ({ recentlyPrice, isApprovalFirst, isPriceAdjustment }) => {
  58. source.recentlyPrice = recentlyPrice;
  59. source.isApprovalFirst = isApprovalFirst;
  60. source.isPriceAdjustment = isPriceAdjustment;
  61. }
  62. );
  63. }
  64. if (type === "ORG_PARAM") {
  65. console.log(prop, type, source);
  66. }
  67. },
  68. //
  69. async fetchItem(prop) {
  70. try {
  71. // try
  72. this.loading = true;
  73. const { code, data } = await ITEM(prop);
  74. if (code === 200) {
  75. this.params = data;
  76. return true;
  77. } else {
  78. return false;
  79. }
  80. } catch (err) {
  81. // catch
  82. console.error(err);
  83. } finally {
  84. // finally
  85. this.loading = false;
  86. }
  87. },
  88. //
  89. async open(prop) {
  90. this.visible = await this.fetchItem(prop);
  91. },
  92. //
  93. async hide() {
  94. this.visible = false;
  95. this.params = this.resetParams();
  96. this.tabName = this.tabColumns[0].key;
  97. },
  98. //
  99. async useRowAdd(prop) {
  100. const {
  101. $notify,
  102. tabColumns,
  103. params: { puOrgName, supplierName },
  104. } = this;
  105. if (!supplierName) {
  106. return $notify.info("请选择供应商");
  107. }
  108. if (!puOrgName) {
  109. return $notify.info("请选择采购组织");
  110. }
  111. const { tableColumns } = tabColumns.find(
  112. (element) => element.key === prop
  113. );
  114. this.params[prop].push(initParams(tableColumns));
  115. },
  116. //
  117. async useRowRemove(prop, scope) {
  118. const { $index } = scope;
  119. this.params[prop] = this.params[prop].map((item, index) => ({
  120. ...item,
  121. delFlag: index === $index ? "2" : item.delFlag,
  122. }));
  123. },
  124. //
  125. async useSubmit(prop) {
  126. this.$refs[prop].validate(async (valid) => {
  127. if (valid) {
  128. try {
  129. // try
  130. const params = { ...this.params };
  131. const { msg, code } = await SAVE(params);
  132. if (code === 200) {
  133. const { id } = this.params;
  134. const { fetchItem } = this.root.$refs.SeeModel;
  135. await fetchItem(id);
  136. this.hide();
  137. this.$emit("success");
  138. this.$notify.success(msg);
  139. }
  140. } catch (err) {
  141. // catch
  142. console.error(err);
  143. } finally {
  144. // finally
  145. this.loading = false;
  146. }
  147. } else {
  148. return false;
  149. }
  150. });
  151. },
  152. },
  153. created() {},
  154. mounted() {},
  155. destroyed() {},
  156. };
  157. </script>
  158. <template>
  159. <el-drawer
  160. :size="width"
  161. :title="title"
  162. :show-close="false"
  163. :visible.sync="visible"
  164. >
  165. <template slot="title">
  166. <span>{{ title }}</span>
  167. <span>
  168. <el-button
  169. :size="size"
  170. circle
  171. icon="el-icon-close"
  172. @click="hide"
  173. ></el-button>
  174. <el-button
  175. :size="size"
  176. circle
  177. icon="el-icon-check"
  178. @click="useSubmit('ruleForm')"
  179. ></el-button>
  180. </span>
  181. </template>
  182. <el-form
  183. ref="ruleForm"
  184. v-loading="loading"
  185. :size="size"
  186. :rules="rules"
  187. :model="params"
  188. label-width="auto"
  189. label-position="right"
  190. style="padding: 10px"
  191. >
  192. <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
  193. <el-col
  194. v-for="(column, index) in tableColumns"
  195. :key="index"
  196. :span="column.span || 8"
  197. >
  198. <el-form-item :prop="column.key" :label="column.title">
  199. <el-input
  200. v-if="column.inputType === 'Input'"
  201. v-model="params[column.key]"
  202. :disabled="column.disabled"
  203. :readonly="column.readonly"
  204. :clearable="column.clearable"
  205. :placeholder="column.placeholder"
  206. style="width: 100%"
  207. ></el-input>
  208. <dr-popover-select
  209. v-if="column.inputType === 'PopoverSelect'"
  210. v-model="params[column.key]"
  211. :source.sync="params"
  212. :title="column.title"
  213. :type="column.referName"
  214. :disabled="column.disabled"
  215. :readonly="column.readonly"
  216. :clearable="column.clearable"
  217. :placeholder="column.placeholder"
  218. :data-mapping="column.dataMapping"
  219. style="width: 100%"
  220. >
  221. </dr-popover-select>
  222. <el-select
  223. v-if="column.inputType === 'Select'"
  224. v-model="params[column.key]"
  225. :disabled="column.disabled"
  226. :clearable="column.clearable"
  227. :placeholder="column.placeholder"
  228. style="width: 100%"
  229. >
  230. <el-option
  231. v-for="item in dict.type[column.referName]"
  232. :key="item.value"
  233. :label="item.label"
  234. :value="item.value"
  235. >
  236. </el-option>
  237. </el-select>
  238. <file-upload
  239. v-if="column.inputType === 'Upload'"
  240. v-model="params[column.key]"
  241. :file-type="column.fileType"
  242. ></file-upload>
  243. </el-form-item>
  244. </el-col>
  245. <el-divider></el-divider>
  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="newParams[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>