lilei 3 anos atrás
pai
commit
f24e44ec69

+ 26 - 22
src/api/settle.js

@@ -56,6 +56,32 @@ export const settleUnitQuerySum = (params) => {
     method: 'post'
   })
 }
+
+//详情  打印
+export const settleUnitPrint = params => {
+  const data = {
+    url: `/settle/unit/print/${params.type}`,
+    data: params,
+    method: 'post'
+  }
+  // 喷墨打印
+  if (params.type == 'INK') {
+    data.responseType = 'blob'
+  }
+  return axios.request(data)
+}
+
+// 详情  导出
+export const settleUnitExport = params => {
+  return axios.request({
+    url: `/settle/unit/excel`,
+    data: params,
+    method: 'post',
+    responseType: 'blob'
+  })
+}
+
+
 //  单位收付款 全部单据
 export const settleInfoAllList = (params) => {
   return axios({
@@ -91,25 +117,3 @@ export const settleInfoQuerySum = (params) => {
     method: 'post'
   })
 }
-
-//详情  打印
-export const settleDetailPrint = params => {
-  const data = {
-    url: `/settle/print/${params.sn}/${params.type}`,
-    method: 'get'
-  }
-  // 喷墨打印
-  if (params.type == 'INK') {
-    data.responseType = 'blob'
-  }
-  return axios.request(data)
-}
-
-// 详情  导出
-export const settleDetailExport = params => {
-  return axios.request({
-    url: `/settle/excel/${params.sn}`,
-    method: 'get',
-    responseType: 'blob'
-  })
-}

+ 1 - 0
src/views/financialManagement/companyReceivablePayable/chooseBillModal.vue

@@ -100,6 +100,7 @@ export default {
         bizNo: '',
         bizType: undefined
       },
+      allData: [],
       // 表头
       columns: [
         { title: '序号', dataIndex: 'no', width: '6%', align: 'center' },

+ 122 - 50
src/views/financialManagement/companyReceivablePayable/collectionPayment.vue

@@ -51,8 +51,9 @@
                   id="collectionPayment-settleAmount"
                   v-model="record.settleAmount"
                   :precision="2"
-                  :min="record.unsettleAmount<0 ? record.unsettleAmount : 0.01"
-                  :max="record.unsettleAmount<0 ? -0.01 : record.unsettleAmount"
+                  :min="record.unsettleAmount<0 ? record.unsettleAmount : 0"
+                  :max="record.unsettleAmount<0 ? 0 : record.unsettleAmount"
+                  @change="amountSettledChange"
                   size="small"
                   placeholder="请输入"
                   style="width: 100%;" />
@@ -84,8 +85,10 @@
                     <a-input-number
                       id="collectionPayment-amountSettled"
                       v-model="form.amountSettled"
+                      @change="amountSettledTotalChange"
                       :precision="2"
                       placeholder=""
+                      :max="Math.abs(currentTotalBalance)"
                       style="width: 100%;" />
                   </a-form-model-item>
                 </a-col>
@@ -96,7 +99,7 @@
                       v-model="form.discountAmount"
                       :precision="2"
                       :min="0"
-                      :max="amountSettled"
+                      :max="form.amountSettled"
                       placeholder="请输入"
                       style="width: 100%;"
                       allowClear />
@@ -144,16 +147,23 @@
         @click="handleSubmit"
         style="padding: 0 60px;">提交</a-button>
     </div>
-    <choose-bill-modal :openModal="openModal" :nowChoose="chooseLoadData" :settleClientSn="$route.params.sn" @ok="handleOk" @close="handleClose" />
+    <choose-bill-modal
+      ref="chooseBillModal"
+      :openModal="openModal"
+      :nowChoose="chooseLoadData"
+      :settleClientSn="$route.params.sn"
+      @ok="handleOk"
+      @close="handleClose" />
   </div>
 </template>
 
 <script>
 import { commonMixin } from '@/utils/mixin'
+import debounce from 'lodash/debounce'
 import { STable, VSelect } from '@/components'
 import chooseBillModal from './chooseBillModal.vue'
 import { settleStyleQueryAll } from '@/api/settleStyle'
-import { settleUnitSave, settleDetailPrint, settleDetailExport } from '@/api/settle'
+import { settleUnitSave, settleUnitPrint, settleUnitExport, settleInfoAllList } from '@/api/settle'
 import Print from '@/views/common/print.vue'
 import { hdPrint } from '@/libs/JGPrint'
 export default {
@@ -161,6 +171,8 @@ export default {
   components: { STable, VSelect, chooseBillModal, Print },
   mixins: [commonMixin],
   data () {
+    this.amountSettledChange = debounce(this.amountSettledChange, 800)
+    this.amountSettledTotalChange = debounce(this.amountSettledTotalChange, 800)
     return {
       spinning: false,
       loading: false, //  表格加载中
@@ -189,6 +201,7 @@ export default {
         amountSettled: 0,
         discountAmount: 0, //  折让金额
         settleStyleSn: undefined,
+        settleClientName: '',
         remark: ''
       },
       rules: {
@@ -197,24 +210,11 @@ export default {
         settleStyleSn: [{ required: true, message: '请选择结算方式', trigger: 'change' }]
       },
       openModal: false, //  弹框
-      isPositive: true // 是否是正值
+      isPositive: true, // 是否是正值
+      isChangeAs: false
     }
   },
   computed: {
-    // 打印预览/快捷打印
-    handlePrint (type, printerType) {
-      const _this = this
-      _this.spinning = true
-      let url = settleDetailPrint
-      const params = { sn: this.$route.params.sn }
-      if (type == 'export') { //  导出
-        url = settleDetailExport
-      }
-      // 打印或导出
-      hdPrint(printerType, type, url, params, '销售单', function () {
-        _this.spinning = false
-      })
-    },
     // 本次结算金额合计
     currentTotalBalance () {
       let val = 0
@@ -239,17 +239,6 @@ export default {
       })
       return val / 1000
     },
-    // 应结算金额
-    amountSettled () {
-      let val = 0
-      this.chooseLoadData.map(item => {
-        val += (Number(item.settleAmount) * 1000)
-      })
-      val = val / 1000
-      this.isPositive = val > 0
-      this.form.amountSettled = Math.abs(val)
-      return Math.abs(val)
-    },
     // 实结算金额
     actualSettlementAmount () {
       const val = (this.form.amountSettled * 1000 - this.form.discountAmount * 1000) / 1000
@@ -257,6 +246,64 @@ export default {
     }
   },
   methods: {
+    // 打印预览/快捷打印
+    handlePrint (type, printerType) {
+      const _this = this
+      const params = _this.getParams()
+      _this.spinning = true
+      let url = settleUnitPrint
+      if (type == 'export') { //  导出
+        url = settleUnitExport
+      }
+      // 打印或导出
+      hdPrint(printerType, type, url, params, '单位应收应付', function () {
+        _this.spinning = false
+      })
+    },
+    // 应结算金额
+    amountSettledChange () {
+      console.log(this.isChangeAs)
+      if (!this.isChangeAs) {
+        let val = 0
+        this.chooseLoadData.map(item => {
+          val += (Number(item.settleAmount) * 1000)
+        })
+        val = val / 1000
+        this.isPositive = val > 0
+        this.form.amountSettled = Math.abs(val)
+      }
+    },
+    // 修改本次结算金额,自动分配
+    amountSettledTotalChange (v) {
+      console.log(this.isChangeAs, v, this.totalBalance, this.isPositive)
+      if (v < Math.abs(this.totalBalance)) {
+        this.isChangeAs = true
+        const sa = v
+        const list = this.chooseLoadData
+        // 恢复初始值
+        list.map((item, index) => {
+          item.settleAmount = item.unsettleAmount
+        })
+        // 开始计算
+        let temp = 0
+        let ti = 0
+        for (let i = 0; i < list.length; i++) {
+          temp = temp + list[i].settleAmount * (this.isPositive ? 1 : -1)
+          if (temp >= sa) {
+            ti = i
+            break
+          }
+        }
+        console.log(ti, temp, sa)
+        list[ti].settleAmount = (list[ti].settleAmount - (temp - sa) * (this.isPositive ? 1 : -1)).toFixed(2)
+        // ti 之后的都改成0
+        for (let i = ti + 1; i < list.length; i++) {
+          list[i].settleAmount = 0
+        }
+        list.splice()
+        this.isChangeAs = false
+      }
+    },
     // 选择单据
     handleChoose () {
       this.openModal = true
@@ -265,6 +312,26 @@ export default {
     handleDel (record) {
       const ind = this.chooseLoadData.findIndex(item => item.id == record.id)
       this.chooseLoadData.splice(ind, 1)
+      this.amountSettledChange()
+    },
+    getParams () {
+      const _this = this
+      const form = _this.form
+      form.settleClientName = _this.$route.params.name
+      form.settleClientSn = _this.$route.params.sn || undefined
+      form.settleClientType = _this.chooseLoadData[0].settleClientType
+      form.settleType = _this.isPositive ? 'R' : 'P'
+      form.settleAmount = _this.form.amountSettled
+      form.realSettleAmount = _this.actualSettlementAmount
+      form.detailList = []
+      _this.chooseLoadData.map(item => {
+        form.detailList.push({
+          bizSn: item.bizSn,
+          settleAmount: item.settleAmount,
+          prFlag: item.prFlag
+        })
+      })
+      return form
     },
     // 提交
     handleSubmit () {
@@ -275,21 +342,8 @@ export default {
       }
       this.$refs.ruleForm.validate(valid => {
         if (valid) {
-          const form = _this.form
-          form.settleClientSn = _this.$route.params.sn || undefined
-          form.settleClientType = _this.chooseLoadData[0].settleClientType
-          form.settleType = _this.isPositive ? 'R' : 'P'
-          form.settleAmount = _this.form.amountSettled
-          form.realSettleAmount = _this.actualSettlementAmount
-          form.detailList = []
-          _this.chooseLoadData.map(item => {
-            form.detailList.push({
-              bizSn: item.bizSn,
-              settleAmount: item.settleAmount,
-              prFlag: item.prFlag
-            })
-          })
           _this.spinning = true
+          const form = this.getParams()
           settleUnitSave(form).then(res => {
             if (res.status == 200) {
               _this.$message.success(res.message)
@@ -306,7 +360,12 @@ export default {
       })
     },
     handleOk (selectedRows) {
-      this.chooseLoadData = selectedRows
+      this.chooseLoadData = selectedRows.sort((a, b) => {
+        const at = new Date(a.auditTime).getTime()
+        const bt = new Date(b.auditTime).getTime()
+        return bt - at
+      })
+      this.amountSettledChange()
     },
     //  结算方式
     getSettleStyle () {
@@ -325,19 +384,32 @@ export default {
     // 关闭
     handleClose () {
       this.openModal = false
+    },
+    // 默认获取所有单据
+    getsettleInfoAllList () {
+      settleInfoAllList({ settleClientSn: this.$route.params.sn, notEqZero: 1 }).then(res => {
+        res.data.map(item => {
+          item.settleAmount = item.unsettleAmount
+        })
+        this.chooseLoadData = res.data || []
+        this.amountSettledChange()
+      })
+    },
+    pageInit () {
+      this.getSettleStyle()
+      this.chooseLoadData = []
+      this.getsettleInfoAllList()
     }
   },
   mounted () {
     if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
-      this.getSettleStyle()
-      this.chooseLoadData = []
+      this.pageInit()
     }
   },
   activated () {
     // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
     if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
-      this.getSettleStyle()
-      this.chooseLoadData = []
+      this.pageInit()
     }
   },
   beforeRouteEnter (to, from, next) {

+ 2 - 2
vue.config.js

@@ -108,8 +108,8 @@ const vueConfig = {
     // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
     proxy: {
       '/api': {
-        target: 'http://192.168.16.105:8503/qpls-md',
-        // target: 'http://p.iscm.360arrow.com/qpls-md',
+        // target: 'http://192.168.16.151:8503/qpls-md',
+        target: 'http://p.iscm.360arrow.com/qpls-md',
         // ws: false,
         ws: true,
         changeOrigin: true,