index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <script>
  2. import useColumns from "./columns";
  3. import { REFER } from "@/components/popover-select/api";
  4. import { ADD, CODE } from "@/api/business/purchase/contract";
  5. export default {
  6. name: "AddDrawer",
  7. props: {
  8. selectData: {
  9. type: [Array],
  10. require: true,
  11. },
  12. dict: {
  13. type: Object,
  14. require: true,
  15. },
  16. addType: {
  17. type: String,
  18. default: "add",
  19. },
  20. },
  21. components: {
  22. ElSuperForm: () => import("@/components/super-form/index.vue"),
  23. ElSuperTable: () => import("@/components/super-table/index.vue"),
  24. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  25. },
  26. data() {
  27. const {
  28. TabColumns,
  29. TableColumns,
  30. TabColumns: [
  31. {
  32. item: { key: tabName },
  33. },
  34. ],
  35. } = useColumns();
  36. const rules = this.$init.rules([...TabColumns, ...TableColumns]);
  37. const params = this.$init.params([...TabColumns, ...TableColumns]);
  38. return {
  39. width: "100%",
  40. visible: false,
  41. loading: false,
  42. rules: rules,
  43. params: params,
  44. tabName: tabName,
  45. TabColumns: TabColumns,
  46. TableColumns: TableColumns,
  47. };
  48. },
  49. computed: {
  50. title: {
  51. get() {
  52. const { addType } = this.$props;
  53. if (addType === "add") {
  54. this.params.source = "自制";
  55. return "新 增";
  56. }
  57. if (addType === "record") {
  58. this.params.source = "期初补录";
  59. return "期初补录";
  60. }
  61. },
  62. set() {},
  63. },
  64. },
  65. watch: {},
  66. methods: {
  67. //
  68. async fetchCode() {
  69. try {
  70. // try
  71. this.loading = true;
  72. const data = await CODE();
  73. if (data) {
  74. this.params.code = data;
  75. return true;
  76. } else {
  77. return false;
  78. }
  79. } catch (err) {
  80. // catch
  81. console.error(err);
  82. } finally {
  83. // finally
  84. this.loading = false;
  85. }
  86. },
  87. //
  88. async changeMaterialName(prop) {
  89. const { row } = prop;
  90. const { rateCode } = row;
  91. try {
  92. // try
  93. this.loading = true;
  94. const { code, rows } = await REFER({
  95. search: rateCode,
  96. type: "TAX_RATE_PARAM",
  97. });
  98. if (code === 200) {
  99. const [{ ntaxrate }] = rows;
  100. row.tax = ntaxrate === "0E-8" ? "0.00000000" : ntaxrate;
  101. }
  102. } catch (err) {
  103. // catch
  104. console.error(err);
  105. } finally {
  106. // finally
  107. this.loading = false;
  108. }
  109. },
  110. //
  111. async open() {
  112. const {
  113. user: {
  114. deptId: puDept,
  115. deptName: puDeptName,
  116. name: buyer,
  117. nickName: buyerName,
  118. orgId: puOrg,
  119. orgName: puOrgName,
  120. },
  121. } = this.$store.state;
  122. this.params.puOrg = puOrg;
  123. this.params.puOrgName = puOrgName;
  124. this.params.buyer = buyer;
  125. this.params.buyerName = buyerName;
  126. this.params.puDept = puDept;
  127. this.params.puDeptName = puDeptName;
  128. const { id, code, name } = await this.getCurrency("人民币");
  129. this.params.currency = id;
  130. this.params.currencyCode = code;
  131. this.params.currencyName = name;
  132. this.visible = await this.fetchCode();
  133. },
  134. async getCurrency(search) {
  135. let page = { pageNum: 1, pageSize: 10 };
  136. const { code, rows } = await REFER(
  137. {
  138. isPage: true,
  139. search,
  140. type: "CURRENCY_PARAM",
  141. },
  142. page
  143. );
  144. if (code == 200) {
  145. return rows[0];
  146. }
  147. },
  148. //
  149. async hide() {
  150. const {
  151. TabColumns,
  152. TableColumns,
  153. TabColumns: [
  154. {
  155. item: { key: tabName },
  156. },
  157. ],
  158. } = useColumns();
  159. this.visible = false;
  160. this.tabName = tabName;
  161. this.params = this.$init.params([...TabColumns, ...TableColumns]);
  162. },
  163. //
  164. async useRowAdd(prop) {
  165. const { TableColumns } = this.TabColumns.find(
  166. ({ item: { key } }) => key === prop
  167. );
  168. this.params[prop].push(this.$init.params(TableColumns));
  169. },
  170. //
  171. async useRowRemove(prop, scope) {
  172. const { $index } = scope;
  173. this.params[prop].splice($index, 1);
  174. },
  175. //
  176. async useSubmit(prop) {
  177. this.$refs[prop].validate(async (valid) => {
  178. if (valid) {
  179. try {
  180. // try
  181. this.loading = true;
  182. const params = { ...this.params };
  183. const { msg, code } = await ADD(params);
  184. if (code === 200) {
  185. this.hide();
  186. this.$emit("success");
  187. this.$notify.success(msg);
  188. }
  189. } catch (err) {
  190. // catch
  191. console.error(err);
  192. } finally {
  193. // finally
  194. this.loading = false;
  195. }
  196. } else {
  197. return false;
  198. }
  199. });
  200. },
  201. },
  202. created() {},
  203. mounted() {},
  204. destroyed() {},
  205. };
  206. </script>
  207. <template>
  208. <el-button v-bind="$attrs" v-on="$listeners" @click="open">
  209. {{ title }}
  210. <el-drawer
  211. :size="width"
  212. :title="title"
  213. :visible.sync="visible"
  214. append-to-body
  215. destroy-on-close
  216. :show-close="false"
  217. @close="hide"
  218. >
  219. <div
  220. slot="title"
  221. style="
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. "
  226. >
  227. <h3>{{ title }}</h3>
  228. <div style="text-align: right">
  229. <el-button
  230. type="primary"
  231. :size="$attrs.size"
  232. :loading="loading"
  233. @click="useSubmit('superForm')"
  234. >确 认</el-button
  235. >
  236. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  237. >取 消</el-button
  238. >
  239. </div>
  240. </div>
  241. <el-super-form
  242. v-model="params"
  243. :dict="dict"
  244. :rules="rules"
  245. :size="$attrs.size"
  246. :columns="TableColumns"
  247. ref="superForm"
  248. label-width="auto"
  249. label-position="right"
  250. style="padding: 20px"
  251. ></el-super-form>
  252. <el-tabs v-model="tabName" style="margin: 0 20px">
  253. <el-tab-pane
  254. v-for="{ item, TableColumns: columns } in TabColumns"
  255. :key="item.key"
  256. :label="item.title"
  257. :name="item.key"
  258. lazy
  259. >
  260. <el-super-table
  261. v-model="params[item.key]"
  262. :dict="dict"
  263. :ref="tabName"
  264. :columns="columns"
  265. :size="$attrs.size"
  266. index
  267. >
  268. <template slot="materialName" slot-scope="scope">
  269. <component
  270. v-bind="scope.attr"
  271. v-model="scope.row[scope.item.key]"
  272. :size="$attrs.size"
  273. :source.sync="scope.row"
  274. @change="changeMaterialName(scope)"
  275. >
  276. </component>
  277. </template>
  278. <el-table-column fixed="right" label="操作" width="75">
  279. <template slot="header" slot-scope="scope">
  280. <el-button
  281. type="text"
  282. :size="$attrs.size"
  283. @click="useRowAdd(tabName)"
  284. >增行
  285. </el-button>
  286. </template>
  287. <template slot-scope="scope">
  288. <el-button
  289. type="text"
  290. :size="$attrs.size"
  291. @click.native.prevent="useRowRemove(tabName, scope)"
  292. >删行
  293. </el-button>
  294. </template>
  295. </el-table-column>
  296. </el-super-table>
  297. </el-tab-pane>
  298. </el-tabs>
  299. </el-drawer>
  300. </el-button>
  301. </template>