var e=(e,a,l)=>new Promise(((s,t)=>{var o=e=>{try{n(l.next(e))}catch(a){t(a)}},r=e=>{try{n(l.throw(e))}catch(a){t(a)}},n=e=>e.done?s(e.value):Promise.resolve(e.value).then(o,r);n((l=l.apply(e,a)).next())}));import{_ as a}from"./uni-search-bar.48a9b35c.js";import{s as l,M as s,r as t,c as o,D as r,I as n,d as u,e as i,f as d,a as c,g,i as p,j as f,F as h,m,u as v,l as y,b as _,p as P,k as I,t as b}from"./index-45b322f7.js";import{_ as U}from"./su-sticky.dcc8e273.js";import{_ as k}from"./uni-load-more.575c3b96.js";import{_ as L}from"./s-layout.940eafb4.js";import{i as w}from"./itemList.bfc32ea9.js";import{h as x}from"./index.f474d5f6.js";import{_ as T}from"./_plugin-vue_export-helper.1b428a4d.js";import"./uni-icons.c22fa7d9.js";const C=T({__name:"goodsUsageSelect",setup(T){const C=l.$store("order"),S=s({currentPageNo:1,pageSize:20,supplierId:"",goodsId:"",materialId:"",bizTypeId:"",isSearch:!1,isUsageTypeLastPage:!1,isUsageLastPage:!1}),j=t([]),z=o((()=>{if(0==M.value.length)return j.value;return M.value[M.value.length-1].children})),N=t(""),M=t([]),D=o((()=>""==N.value?"*":N.value)),E=o((()=>M.value.length>0?S.isUsageTypeLastPage&&S.isUsageLastPage?"noMore":"more":S.isSearch?S.isUsageLastPage?"noMore":"more":S.isUsageTypeLastPage?"noMore":"more"));function $(){C.modifyGoodsUsage(S.supplierId,S.goodsId,{id:"",name:""}),l.$router.back()}function G(a){return e(this,null,(function*(){S.currentPageNo=1;let e=H(a);yield F(a),yield O(a),M.value.push(e)}))}function V(){R(),""!=N.value&&null!=N.value&&null!=N.value&&(S.isSearch=!0),O(0)}function B(e){let a=H(e);C.modifyGoodsUsage(S.supplierId,S.goodsId,a),l.$router.back()}function F(a){return e(this,arguments,(function*(e,a=S.pageSize){E.value="loading";const s=yield l.$api.baseData.getGoodsUsageType({parent_id:e,pageSize:a,pageNo:S.currentPageNo});if(0==s.errorCode){if(s.data.rows.forEach((e=>e.type="firstLevelType")),null==e||null==e||""==e)j.value=s.data.rows;else{let a=H(e);s.data.rows.forEach((a=>{a.parentId=e})),null==a.children||null==a.children?a.children=s.data.rows:a.children.push(...s.data.rows)}S.isUsageTypeLastPage=s.data.lastPage}}))}function O(a){return e(this,null,(function*(){E.value="loading";const e=yield l.$api.baseData.getGoodsUsage({name:D.value,number:D.value,group_id:a,settle_org_id:C.malOrgRelation.settleOrgId,pageSize:S.pageSize,pageNo:S.currentPageNo});if(console.log("获取到的商品用途的数量为："+e.data.rows.length),0==e.errorCode)if(e.data.rows.forEach((e=>{e.type="subLevelType",e.parentId=a})),S.isSearch)j.value.push(...e.data.rows);else{let l=H(a);null==l.children?l.children=e.data.rows:l.children.push(...e.data.rows),S.isUsageLastPage=e.data.lastPage}}))}function A(){R(),S.isSearch=!1,F(0)}function R(){S.currentPageNo,j.value=[],M.value=[],S.isUsageLastPage=!1,S.isUsageTypeLastPage=!1}function q(){if("noMore"==E.value)return;S.currentPageNo+=1;let e=0;S.isSearch?O(0):M.value.length>0?(e=M.value[M.value.length-1].id,S.isUsageTypeLastPage||F(e),S.isUsageLastPage||O(e)):S.isUsageTypeLastPage||F(0)}function H(e){let a=null;for(let l of j.value)if(a=J(e,l),null!=a&&null!=a)break;return a}function J(e,a){if(null==a||null==a||a.id==e)return a;if(null==a.children||null==a.children)return null;for(let l of a.children){let a=J(e,l);if(null!=a&&null!=a)return a}}return r((e=>{R(),S.materialId=e.materialId,S.bizTypeId=e.bizTypeId,S.supplierId=e.supplierId,S.goodsId=e.goodsId,F(0)})),n((()=>{q()})),(e,l)=>{const s=c(_("uni-search-bar"),a),t=P,o=c(_("su-sticky"),U),r=c(_("uni-load-more"),k),n=c(_("s-layout"),L);return u(),i(n,null,{default:d((()=>[g(o,{bgColor:"#fff",stickyToTop:!1},{default:d((()=>[g(t,{class:"search-block ss-flex ss-row-center"},{default:d((()=>[g(s,{class:"search-bar",placeholder:"请搜索商品用途编号/名称",onConfirm:V,onCancel:A,modelValue:N.value,"onUpdate:modelValue":l[0]||(l[0]=e=>N.value=e)},null,8,["modelValue"])])),_:1})])),_:1}),g(t,{class:"ss-flex-col content-box"},{default:d((()=>[g(t,{class:"ss-flex-col"},{default:d((()=>[M.value.length>0?(u(),i(t,{key:0,class:"ss-flex pathBox"},{default:d((()=>[(u(!0),p(h,null,f(M.value,((e,a)=>(u(),i(t,{class:"ss-flex",onClick:e=>function(e,a){M.value[a+1].children=[],M.value.splice(a+1)}(0,a)},{default:d((()=>[0!=a?(u(),i(v(x),{key:0,fill:"#999999"})):m("",!0),g(t,{class:I(["pathName",{oldPath:a!=M.value.length-1}])},{default:d((()=>[y(b(e.name),1)])),_:2},1032,["class"])])),_:2},1032,["onClick"])))),256))])),_:1})):m("",!0),g(w,{listData:v(z),onClickFirstLevelEntry:G,onClickEntry:B},null,8,["listData"])])),_:1}),v(z).length>0?(u(),i(r,{key:0,status:v(E),"content-text":{contentdown:"上拉加载更多"},onClick:q},null,8,["status"])):m("",!0)])),_:1}),g(t,{class:"bottom-bar ss-col-center"},{default:d((()=>[g(t,{class:"clear-btn",onClick:$},{default:d((()=>[y("清空并退出")])),_:1})])),_:1})])),_:1})}}},[["__scopeId","data-v-8166ac71"]]);export{C as default};
