index.vue 7.6 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].$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. },
  204. mounted() {},
  205. destroyed() {},
  206. };
  207. </script>
  208. <template>
  209. <el-button v-bind="$attrs" v-on="$listeners" @click="open">
  210. {{ title }}
  211. <el-drawer
  212. :size="width"
  213. :title="title"
  214. :visible.sync="visible"
  215. append-to-body
  216. destroy-on-close
  217. :show-close="false"
  218. @close="hide"
  219. >
  220. <div slot="title"
  221. style="
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. ">
  226. <h3>{{title}}</h3>
  227. <div style="text-align: right">
  228. <el-button
  229. type="primary"
  230. :size="$attrs.size"
  231. :loading="loading"
  232. @click="useSubmit('superForm')"
  233. >确 认</el-button>
  234. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  235. >取 消</el-button>
  236. </div>
  237. </div>
  238. <el-super-form
  239. v-model="params"
  240. :dict="dict"
  241. :rules="rules"
  242. :size="$attrs.size"
  243. :columns="TableColumns"
  244. ref="superForm"
  245. label-width="auto"
  246. label-position="right"
  247. style="padding: 20px"
  248. ></el-super-form>
  249. <el-tabs v-model="tabName" style="margin: 0 20px">
  250. <el-tab-pane
  251. v-for="{ item, TableColumns: columns } in TabColumns"
  252. :key="item.key"
  253. :label="item.title"
  254. :name="item.key"
  255. lazy
  256. >
  257. <el-super-table
  258. v-model="params[item.key]"
  259. :dict="dict"
  260. :ref="tabName"
  261. :columns="columns"
  262. :iconOperation="false"
  263. :size="$attrs.size"
  264. >
  265. <template slot="materialName" slot-scope="scope">
  266. <component
  267. v-bind="scope.attr"
  268. v-model="scope.row[scope.item.key]"
  269. :size="$attrs.size"
  270. :source.sync="scope.row"
  271. @change="changeMaterialName(scope)"
  272. >
  273. </component>
  274. </template>
  275. <el-table-column fixed="right" label="操作" width="75">
  276. <template slot="header" slot-scope="scope">
  277. <el-button
  278. type="text"
  279. :size="$attrs.size"
  280. @click="useRowAdd(tabName)"
  281. >增行
  282. </el-button>
  283. </template>
  284. <template slot-scope="scope">
  285. <el-button
  286. type="text"
  287. :size="$attrs.size"
  288. @click.native.prevent="useRowRemove(tabName, scope)"
  289. >删行
  290. </el-button>
  291. </template>
  292. </el-table-column>
  293. </el-super-table>
  294. </el-tab-pane>
  295. </el-tabs>
  296. </el-drawer>
  297. </el-button>
  298. </template>