"use strict";const l=require("../../common/vendor.js"),e=require("./model.js"),o=require("../../common/libraries/apiLoading.js"),u=require("../../gen/Apis.js"),a=require("../../common/libraries/sendWxWork.js");require("../../common/libraries/request.js"),require("../../common/store/useWatermarkStore.js");const i=require("../../common/store/useWeAppAuthStore.js");require("../../common/store/useWorkStore.js");const n=require("../../common/libraries/naviHelper.js"),d=i.useWeAppAuthStore(),t=()=>{var l,a;o.getApiLoading(u.Apis.Bill.HouseBills.List,{...null==(a=null==(l=e.useModel)?void 0:l.formData)?void 0:a.value,type:1}).then((l=>{var o;null==(o=null==l?void 0:l.data)||o.map((l=>{var e;l.checked=!0,null==(e=null==l?void 0:l.bills)||e.map((l=>{l.checked=!0}))})),e.useModel.items.value=[...e.useModel.items.value,...null==l?void 0:l.data]}))},s=()=>{var l,o,u;let a=[];return null==(u=null==(o=null==(l=e.useModel)?void 0:l.items)?void 0:o.value)||u.map((l=>{var e,o;(null==(e=null==l?void 0:l.bills)?void 0:e.length)&&(null==(o=null==l?void 0:l.bills)||o.map((l=>{(null==l?void 0:l.checked)&&(null==a||a.push(null==l?void 0:l.id))})))})),(null==a?void 0:a.length)?(v(),a):(n.showToast("请至少选择一个月账单！"),!1)},v=()=>{var l,o,u;let a=0;null==(u=null==(o=null==(l=e.useModel)?void 0:l.items)?void 0:o.value)||u.map((l=>{var e;null==(e=null==l?void 0:l.bills)||e.map((l=>{(null==l?void 0:l.checked)&&(a+=parseFloat(l.amount||0))}))})),e.useModel.total_amount.value=a},r={handleGetList:t,handleCollapseClick:(l,o)=>{var u,a,i;let n=null==(i=null==(a=null==(u=e.useModel)?void 0:u.items)?void 0:a.value[l])?void 0:i.show;e.useModel.items.value[l].show=!n},hanldeSearch:l=>{var o,u;e.useModel.items.value=[],e.useModel.formData.value={...null==(u=null==(o=e.useModel)?void 0:o.formData)?void 0:u.value,...l,page:1},t()},handleCalculatePrice(l,o,u){var a;let i=null==u?void 0:u.checked;if(e.useModel.items.value[l].bills[o].checked=!i,i)e.useModel.items.value[l].checked=!1;else{let o=null==(a=e.useModel.items.value[l].bills)?void 0:a.every((l=>null==l?void 0:l.checked));e.useModel.items.value[l].checked=o,console.log(o)}},handleCollapseAllCheckedBtn:async(l,o)=>{var u,a,i,n;let d=null==o?void 0:o.checked;e.useModel.items.value[l].checked=!d,null==(n=null==(i=null==(a=null==(u=e.useModel)?void 0:u.items)?void 0:a.value[l])?void 0:i.bills)||n.map((l=>{l.checked=!d}))},handleQuery(e){l.index.navigateTo({url:`/INDEX/bill/show/index?asset_houses_id=${null==e?void 0:e.asset_houses_id}&month=${null==e?void 0:e.month}`}),console.log(e,"res")},handleSubmitOrder(){var a,i,d,t,s,v,r;let m=[];null==(d=null==(i=null==(a=e.useModel)?void 0:a.items)?void 0:i.value)||d.map((l=>{var e;null==(e=null==l?void 0:l.bills)||e.map((l=>{var e;null==(e=null==l?void 0:l.details)||e.map((e=>{(null==l?void 0:l.checked)&&m.push(null==e?void 0:e.id)}))}))})),(null==m?void 0:m.length)?o.getApiLoading(u.Apis.HouseOrder.HouseOrders.Store,{bill_ids:m,amount:null==(s=null==(t=e.useModel)?void 0:t.total_amount)?void 0:s.value,total_payable_amount:null==(r=null==(v=e.useModel)?void 0:v.total_amount)?void 0:r.value}).then((e=>{var o;l.index.navigateTo({url:`/INDEX/pay/index?id=${null==(o=null==e?void 0:e.data)?void 0:o.id}`})})):n.showToast("至少选择一个账单！")},handleQRCode(){var a,i,n,d;let t=s()||[];(null==t?void 0:t.length)&&o.getApiLoading(u.Apis.HouseOrder.HouseOrders.Store,{bill_ids:t||[],total_payable_amount:null==(i=null==(a=e.useModel)?void 0:a.total_amount)?void 0:i.value,amount:null==(d=null==(n=e.useModel)?void 0:n.total_amount)?void 0:d.value}).then((o=>{var u,a,i,n,d,t,s,v,r,m;l.index.navigateTo({url:`/BILL/poster/index?id=${null==(a=null==(u=e.useModel.formData)?void 0:u.value)?void 0:a.asset_houses_id}&order_id=${null==(i=null==o?void 0:o.data)?void 0:i.id}&time=${null==(n=null==o?void 0:o.data)?void 0:n.created_at}&name=${null==(t=null==(d=e.useModel.formData)?void 0:d.value)?void 0:t.name}&amount=${(null==(v=null==(s=e.useModel)?void 0:s.total_amount)?void 0:v.value)||(null==(m=null==(r=e.useModel)?void 0:r.total_amount)?void 0:m.value)}`})}))},handleSelectExternalContact(){var o;let u=s()||[];if(console.log(u,"bill_ids"),!(null==u?void 0:u.length))return!1;"wxwork"===(null==(o=null==d?void 0:d.data)?void 0:o.environment)?l.index.qy.getContext({success:function(l){var o,i,n;"single_chat_tools"===l.entry?a.sendChatMessage({page:`/INDEX/bill_order/index.html?bill_ids=${JSON.stringify(u)}&house_id=${e.useModel.formData.value.asset_houses_id}`,title:`分享给您${null==(n=null==(i=null==(o=e.useModel)?void 0:o.formData)?void 0:i.value)?void 0:n.name}物业账单`,imgUrl:"https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01K5B5RY2TQQAJ1GT2RZSK426V.jpg"}):a.navigateToMiniProgram({path:"/pages/forward/index?source=OutstandingFeeList",envVersion:"develop",extraData:{source:"OutstandingFeeList"}})}}):a.navigateToMiniProgram({path:"/pages/forward/index?source=OutstandingFeeList",envVersion:"develop",extraData:{source:"OutstandingFeeList"}})}};exports.method=r;
