12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { REFER } from "@/components/popover-select/api";
- const fetchOrg = async (prop) => {
- try {
- // try
- const { code, rows } = await REFER({
- search: prop,
- type: "ORG_PARAM",
- });
- if (code === 200) {
- return rows[0] || {};
- }
- } catch (err) {
- // catch
- console.error(err);
- } finally {
- // finally
- }
- };
- export default function useWatch() {
- const watchPuOrgName = () => ({
- handler: async function (newProp) {
- const index = this.params.priceApplyOrgs.findIndex(
- (item) => item.orgName === newProp
- );
- if (index === -1) {
- const {
- id: org,
- code: orgCode,
- name: orgName,
- } = await fetchOrg(this.params.puOrgName);
- await this.params.priceApplyOrgs.push({
- org,
- orgCode,
- orgName,
- createByName: undefined,
- updateByName: undefined,
- });
- }
- },
- deep: true,
- });
- const watchPriceApplyOrgs = () => ({
- handler: function (newValue) {
- this.newParams.priceApplyOrgs = newValue.filter(
- (item) => item.delFlag === "0"
- );
- },
- deep: true,
- });
- const watchPriceApplyItems = () => ({
- handler: function (newValue) {
- this.newParams.priceApplyItems = newValue.filter(
- (item) => item.delFlag === "0"
- );
- },
- deep: true,
- });
- return { watchPuOrgName, watchPriceApplyOrgs, watchPriceApplyItems };
- }
|