<template>
  <div style="padding-top:42px;" data-key="DUI_ZHANG">
    <div style="position: absolute; top: 118px; right: 16px">
      <img
        :src="RecordStatusImg"
        style="width: 83px; height: 66px"
      >
    </div>
    <div class="quickOperation">
      快捷操作：
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="reconciliation"
      >
        对账单对账
      </Button>
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click='varianceReconciliation'
      >
        差异对账
      </Button>
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="addRecordExplain"
      >
        添加对账说明
      </Button>
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="refreshPage"
      >
        刷新
      </Button>
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="SaveExchange"
      >
        保存
      </Button>
      <Button
        type="fcdefault"
        @click="backToList"
      >
        返回
      </Button>
    </div>
    <div class="content">
      <div
        v-for="(item,tabId) in tabList"
        :key="tabId"
        class="block"
      >
        <foldPanel
          v-model="item.blockShow"
          :title="item.tabtext"
        >
          <div
            slot="content"
            class="block"
          >
            <div
              v-if="tabId==&quot;0&quot;||tabId==&quot;1&quot;"
              class="formContent"
            >
              <div
                v-if="tabId=='1'"
              >
                <Col
                  span="24"
                >
                <div
                  class="refund-content"
                >
                  <div
                    class="count-part"
                    style="display:flex;"
                  >
                    <div class="item">
                      <div class="text">
                        （平台收入合计
                      </div>
                      <Input
                        v-model="tabList[3].TotalIncome"
                        class="input-money"
                        placeholder=""
                        disabled
                      />
                      <div class="text">
                        元
                      </div>
                      <div class="plus">
                        +
                      </div>
                    </div>
                    <div class="item">
                      <div class="text">
                        平台支出合计
                      </div>
                      <Input
                        v-model="tabList[3].TotalExpenditure"
                        class="input-money"
                        placeholder=""
                        disabled
                      />
                      <div class="text">
                        元）
                      </div>
                      <div class="plus">
                        -
                      </div>
                    </div> 
                    <div class="item">
                       <div class="text">
                        （系统收入合计
                      </div>
                      <Input
                        v-model="tabList[2].TotalIncome"
                        class="input-money"
                        placeholder=""
                        disabled
                      />
                      <div class="text">
                        元
                      </div>
                      <div class="plus">
                        +
                      </div>
                    </div>
                    <div class="item">
                      <div class="text">
                        系统支出合计
                      </div>
                      <Input
                        v-model="tabList[2].TotalExpenditure"
                        class="input-money"
                        placeholder=""
                        disabled
                      />
                      <div class="text">
                        元
                      </div>
                      <div class="plus">
                        +
                      </div>
                    </div>
                    <div class="item">
                      <div class="text">
                        差异调整
                      </div>
                      <Input
                        v-model="DIFFADJUSTAMOUNT"
                        class="input-money"
                        placeholder=""
                        disabled
                      />
                      <div class="text">
                        元）
                      </div>
                    </div>
                  </div>
                  <div class="total-part">
                    差异金额
                    <span
                      style="font-size: 24px;font-family: PingFangSC-Medium, PingFang SC;font-weight: 500;color: #FD8B2E;"
                    >￥{{ DIFFERENCESAMOUNT }}</span>
                  </div>
                </div>
                </Col>
              </div>
              <Form
                :label-width="120"
                label-position="right"
                inline
              >
                <FormItem
                  v-for="(form,index) in item.list"
                  :key="index"
                  :label="form.title"
                >
                  <Input
                    v-model="form.value"
                    disabled
                    placeholder=""
                    style="width: 300px"
                  />
                </FormItem>
              </Form>
            </div>

            <div v-if="tabId=='2' || tabId=='3'">
              <Table
                border
                height="300"
                :columns="item.systemBillColumns"
                :data="item.systemBillData"
                size="large"
              />
              <div class="pageContent">
                <Page
                  v-if="tabId=='2'"
                  size="small"
                  :current="item.CurrentPage"
                  :page-size="item.pageSize"
                  show-elevator
                  :total="item.totalCount"
                  show-total
                  show-sizer
                  @on-change="changePageSys"
                  @on-page-size-change="changeSizeSys"
                />
                <Page
                  v-if="tabId=='3'"
                  size="small"
                  :current="item.CurrentPage"
                  :page-size="item.pageSize"
                  show-elevator
                  :total="item.totalCount"
                  show-total
                  show-sizer
                  @on-change="changePagePlat"
                  @on-page-size-change="changeSizePlat"
                />
              </div>
              <div v-if='item.isHasCalculate' class='UnderTableCalcu'>
                <div class="item">
                  <p>{{item.TotalIncomeTitle}}</p>
                  <p>￥{{item.TotalIncome}}</p>
                </div>
                <div class="item">
                  <p>{{item.TotalExpenditureTitle}}</p>
                  <p>￥{{item.TotalExpenditure}}</p>
                </div>
                <div class="item">
                  <p>{{item.lastCalcuTitle}}</p>
                  <p>￥{{item.TotalReceive}}</p>
                </div>
              </div>
            </div>
          </div>
        </foldPanel>
      </div>
    </div>
    <!-- 添加对账说明弹框 -->
    <Modal
      v-model="addRecordExplainShow"
      title="添加对账说明"
      title-align="left"
      width="450"
      :closable="closable"
      :mask="mask"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot"
    >
      <div class="chooseStorageForm SplitForm minPiecesForm">
        <Form
          ref="formValidate"
          :model="ExplainForm"
          :label-width="90"
          class="chooseStorageBox"
        >
          <FormItem
            label="对账说明"
          >
            <Input
              type="textarea"
              :rows="4"
              v-model="ExplainForm.explain"
            />
          </FormItem>
        </Form>
      </div>
      <div class="bottomBtnBox">
        <Button
          size="small"
          class="cancelBtn"
          ghost
          @click="cancelModal('explain')"
        >
          取消
        </Button>
        <Button
          type="primary"
          size="small"
          class="sureBtn"
          @click="sureChangeExplain"
        >
          确定
        </Button>
      </div>
    </Modal>
    <!-- 对账单差异对账弹框 -->
    <Modal
      v-model="varianceReconciliationShow"
      title="对账单差异对账"
      title-align="left"
      width="450"
      :closable="closable"
      :mask="mask"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot"
    >
      <div class="chooseStorageForm SplitForm minPiecesForm">
        <Form
          ref="formValidate"
          :model="VarianceForm"
          :label-width="90"
          class="chooseStorageBox"
        >
          <FormItem
            label="差异金额"
          >
            <Input
              disabled
              placeholder=""
              v-model="VarianceForm.amount"
            />
          </FormItem>
        </Form>
      </div>
      <div class="bottomBtnBox">
        <Button
          size="small"
          class="cancelBtn"
          ghost
          @click="cancelModal('varianceReconciliation')"
        >
          取消
        </Button>
        <Button
          type="primary"
          size="small"
          class="sureBtn"
          @click="sureVarianceReconciliation"
        >
          确定
        </Button>
      </div>
    </Modal>
    <Modal
      v-model="showTip"
      mask
      :mask-closable="maskClosable"
      title="警告"
      title-align="left"
      class-name="showTipModel"
      width="400px"
      @on-ok="closePage"
    >
      <p><i class="iconfont iconbj_doubt fcWarning " />修改的数据未保存，确定返回？</p>
    </Modal>
  </div>
</template>
<script>
  import foldPanel from '../customizedContent/FoldPanel.vue'; // 折叠面板组件 
  
  const R3 = window.R3;
  const { network, urlSearchParams, store } = R3;
  export default {
    components: { foldPanel },
    data() {
      return {
        showTip: false,
        RecordStatusImg: require('../../assets/orderEditorImg/unRecord.png'),
        addRecordExplainShow: false,
        varianceReconciliationShow: false,
        mask: true,
        closable: true,
        maskClosable: false,
        hideFoot: true,
        ExplainForm: {
          explain: ''
        },
        VarianceForm: {
          amount: '',
        },
        DIFFADJUSTAMOUNT: '', //差异调整金额
        DIFFERENCESAMOUNT: '', // 差异金额
        systemCurrentPage: 1, //系统账单当前页码
        platCurrentPage: 1, // 平台账单当前页码
        tabList: [
          {
            tabId: '1',
            tabtext: '基本信息',
            blockShow: true,
            list: [
              {
                skey: 'SOURCECODE',
                value: '',
                title: '平台交易单号:'
              },
              {
                skey: 'PLATFORM:PLATFORMNAME',
                value: '',
                title: '平台:'
              },
              {
                skey: 'IESSHOPID:SHOPTITLE',
                value: '',
                title: '店铺:'
              }
            ]
          },
          {
            tabId: '2',
            tabtext: '对账信息',
            blockShow: true,
            list: [
              {
                skey: 'RECONCILIATIONSTATUS:DISPLAY',
                value: '',
                title: '对账状态:'
              },
              {
                skey: 'RECONCILIATIONAMOUNT',
                value: '',
                title: '已对账金额:'
              },
              {
                skey: 'ISDIFFRECONCILIATION:DISPLAY',
                value: '',
                title: '是否差异对账:'
              },
              {
                skey: 'DIFFADJUSTAMOUNT',
                value: '',
                title: '差异调整金额:'
              },
              {
                skey: 'DIFFRECONCILIATIONTYPE:DISPLAY',
                value: '',
                title: '对账差异类型:'
              },
              {
                skey: 'RECONCILIATIONFAILMSG',
                value: '',
                title: '对账失败原因:'
              },
              {
                skey: 'RECONCILIATIONEXPLAIN',
                value: '',
                title: '对账说明:'
              },
              {
                skey: 'CHECKTIME',
                value: '',
                title: '对账时间:'
              },
              {
                skey: 'USERID:ENAME',
                value: '',
                title: '对账人:'
              },
            ],
          },
          {
            tabId: '3',
            tabtext: '系统账单',
            blockShow: true,
            systemBillColumns: [
              // {
              //   type: 'index',
              //   title: '序号',
              //   align: 'center',
              // },
              {
                key: 'CHECKSTSTUS',
                title: '对账状态',
                align: 'center',
              },
              {
                key: 'MANUAL_CHECK_STATUS',
                title: '手工对账状态',
                align: 'center',
                render: (h, params) => {
                  const vm = this;
                  return h('Select', {
                    style: {
                      zIndex: 999,
                    },
                    props: {
                      transfer: true,
                      value: params.row.MANUAL_CHECK_STATUS, // 获取选择的下拉框的值
                    },
                    on: {
                      'on-change': (e) => {
                        vm.tabList[2].systemBillData[params.index].MANUAL_CHECK_STATUS = e
                      }
                    }
                  },
                  vm.statusOptions.map(item => h('Option', {
                    props: {
                      value: item.value, // 绑定的值
                    }
                  }, item.name)
                  ));
                }
              },
              {
                key: 'INCOMEAMOUNT',
                title: '收入金额',
                align: 'center',
              },
              {
                key: 'SPENDINGAMOUNT', 
                title: '支出金额', 
                align: 'center',
              },
              {
                key: 'SOURCECODE',
                title: '平台单号',
                align: 'center',
              },
              {
                key: 'DOCNO', 
                title: '系统业务单据编号', 
                align: 'center',
              },
              {
                key: 'DOCTYPE',
                title: '单据类型',
                align: 'center',
              },
              {
                key: 'CHECKTIME', 
                title: '对账时间', 
                align: 'center',
              },
              {
                key: 'VERIFICATION_STATUS', 
                title: '核销状态', 
                align: 'center',
              },
              {
                key: 'PAYMENTTYPE',
                title: '收支类型',
                align: 'center',
              },
              {
                key: 'REMARKS',
                title: '备注',
                align: 'center',
                render: (h, params) => {
                  let this_=this
                  return h(
                    'div',
                    {
                      style: {
                        height:'30px'
                      },
                    },
                    [
                      h('Tooltip',
                      {
                        attrs: {
                          placement:"top",
                          content:params.row.REMARKS,
                          maxWidth:"385",
                          transfer:true,
                          disabled:params.row.REMARKS.length > 8?false:true
                        },
                      },
                      [h(
                        'Input',
                        {
                          style: {
                            width:'120px',
                          },
                          props: {
                            value: params.row.REMARKS,
                            maxlength: 150
                          },
                          on: {
                            'on-blur': (event) => {
                              this.tabList[2].systemBillData[params.index].REMARKS = event.target.value
                            }
                          }
                        },
                        ),
                      ]
                    ),
                    ]
                  )
                }
              },
              {
                key: 'BILLDATE', 
                title: '系统账单时间', 
                align: 'center',
              },
              {
                key: 'PLATFORM_BILLDATE', 
                title: '平台账单时间', 
                align: 'center',
                width: 180,
                render: (h, params) => {
                  const vm = this;
                  // 获取当前明细条数
                  const detailCount = vm.tabList[2].totalCount;
                  const isEditable = detailCount > 10; // 大于10条允许编辑
                  
                  if (isEditable) {
                    // 允许编辑 - 使用日期选择器
                    return h('DatePicker', {
                      style: {
                        width: '170px',
                      },
                      props: {
                        value: params.row.PLATFORM_BILLDATE,
                        type: 'datetime',
                        format: 'yyyy-MM-dd HH:mm:ss',
                        placeholder: '请选择日期',
                        transfer: true,
                      },
                      on: {
                        'on-change': (date) => {
                          params.row.PLATFORM_BILLDATE = date;
                          vm.tabList[2].systemBillData[params.index] = params.row;
                          // vm.tabList[2].systemBillData[params.index].PLATFORM_BILLDATE = date;
                        }
                      }
                    });
                  }
                  
                  // 不允许编辑 - 只显示文本
                  return h('span', {
                    style: {
                      color: '#999',
                      cursor: 'not-allowed'
                    }
                  }, params.row.PLATFORM_BILLDATE || '');
                }
              },
              {
                key: 'PLATFORM',
                title: '平台',
                align: 'center',
              },
              {
                key: 'IESSHOPID', 
                title: '店铺', 
                align: 'center',
              },
              {
                key: 'SKUNAME',
                title: '商品名称',
                align: 'center',
              },
              {
                key: 'SKU', 
                title: '商品SKU', 
                align: 'center',
              },
              {
                key: 'BRANDNAME',
                title: '商品品牌',
                align: 'center',
              },
              {
                key: 'SKUNUMBER', 
                title: '商品数量', 
                align: 'center',
              },
            ],
            systemBillData: [],
            CurrentPage: 1,
            pageSize: 10,
            totalCount: 0,
            isHasCalculate: true,
            TotalIncomeTitle: '系统收入合计',
            TotalIncome: '',
            TotalExpenditureTitle: '系统支出合计',
            TotalExpenditure: '',
            lastCalcuTitle: '系统应收合计',
            TotalReceive: '',
          },
          {
            tabId: '4',
            tabtext: '平台账单',
            blockShow: true,
            systemBillColumns: [
              {
                key: 'CHECKSTSTUS',
                title: '对账状态',
                align: 'center',
              },
              {
                key: 'MANUAL_CHECK_STATUS',
                title: '手工对账状态',
                align: 'center',
                render: (h, params) => {
                  const vm = this;
                  return h('Select', {
                    style: {
                      zIndex: 999,
                    },
                    props: {
                      transfer: true,
                      value: params.row.MANUAL_CHECK_STATUS, // 获取选择的下拉框的值
                    },
                    on: {
                      'on-change': (e) => {
                        vm.tabList[3].systemBillData[params.index].MANUAL_CHECK_STATUS = e
                      }
                    }
                  },
                  vm.statusOptions.map(item => h('Option', {
                    props: {
                      value: item.value, // 绑定的值
                    }
                  }, item.name)
                  ));
                }
              },
              {
                key: 'INCOMEAMOUNT',
                title: '平台账单收入',
                align: 'center',
              },
              {
                key: 'SPENDINGAMOUNT', 
                title: '平台账单支出', 
                align: 'center',
              },
              {
                key: 'SOURCECODE',
                title: '平台单号',
                align: 'center',
              },
              {
                key: 'FINANCIALSERIALNUMBER', 
                title: '财务流水号', 
                align: 'center',
              },
              {
                key: 'BILLTYPE',
                title: '单据类型',
                align: 'center',
              },
              {
                key: 'REMARKS',
                title: '备注',
                align: 'center',
                render: (h, params) => {
                  let this_=this
                  return h(
                    'div',
                    {
                      style: {
                        height:'30px'
                      },
                    },
                    [
                      h('Tooltip',
                      {
                        attrs: {
                          placement:"top",
                          content:params.row.REMARKS,
                          maxWidth:"385",
                          transfer:true,
                          disabled:params.row.REMARKS.length > 8?false:true
                        },
                      },
                      [h(
                        'Input',
                        {
                          style: {
                            width:'120px',
                          },
                          props: {
                            value: params.row.REMARKS,
                            maxlength: 150
                          },
                          on: {
                            'on-blur': (event) => {
                              this.tabList[3].systemBillData[params.index].REMARKS = event.target.value
                            }
                          }
                        },
                        ),
                      ]
                    ),
                    ]
                  )
                }
                
              },
              {
                key: 'CHECKTIME', 
                title: '对账时间', 
                align: 'center',
              },
              {
                key: 'VERIFICATION_STATUS', 
                title: '核销状态', 
                align: 'center',
              },
              {
                key: 'ARRIVETIME', 
                title: '到账时间', 
                align: 'center',
              },
              {
                key: 'ACCOUNTNAME',
                title: '账户名称',
                align: 'center',
              },
              {
                key: 'ACCOUNTNUMBER', 
                title: '账号', 
                align: 'center',
              },
              {
                key: 'ACCOUNTTYPE',
                title: '账户类型',
                align: 'center',
              },
              {
                key: 'GOODSNAME', 
                title: '商品名称', 
                align: 'center',
              },
            ],
            systemBillData: [],
            CurrentPage: 1,
            pageSize: 10,
            totalCount: 0,
            isHasCalculate: true,
            TotalIncomeTitle: '平台收入合计',
            TotalIncome: '',
            TotalExpenditureTitle: '平台支出合计',
            TotalExpenditure: '',
            lastCalcuTitle: '平台实收合计',
            TotalReceive: '',
          }
        ],
        statusOptions: [ //手工对账状态 未对账、已对账，默认未对账
          {
            name: '未对账',
            value: '0'
          },
          {
            name: '已对账',
            value: '1'
          },
        ],
        systemBillDataOld: [],//原始系统对账数据
        platformBillDataOld: [],//原始系统对账数据
      };
    },
    created() {
      this.pageMsgId = window.vm.$route.params.customizedModuleId;
      this.getRecordFetail();
      this.getSystemRecordList();
      this.getPlatRecordList();
    },
    methods: {
      backToList() { // 返回对账单列表页面
        let flag = true;
        //遍历循环当前系统账单和平台账单，是否有修改的数据

        for(let i=0;i<this.systemBillDataOld.length;i++){
          if((this.systemBillDataOld[i].MANUAL_CHECK_STATUS != this.tabList[2].systemBillData[i].MANUAL_CHECK_STATUS)||(this.systemBillDataOld[i].REMARKS != this.tabList[2].systemBillData[i].REMARKS)){
            flag = false;
            break;
          }
        }
        for(let i=0;i<this.platformBillDataOld.length;i++){
          if((this.platformBillDataOld[i].MANUAL_CHECK_STATUS != this.tabList[3].systemBillData[i].MANUAL_CHECK_STATUS)||(this.platformBillDataOld[i].REMARKS != this.tabList[3].systemBillData[i].REMARKS)){
            flag = false;
            break;
          }
        }
        if(!flag){
          this.showTip = true;
        }else{
          this.closePage();
        }
      },
      refreshPage() {
        this.ExplainForm.explain = '';
        this.systemCurrentPage = 1;
        this.platCurrentPage = 1;
        this.tabList[2].pageSize = 10;
        this.tabList[3].pageSize = 10;
        this.getRecordFetail();
        this.getSystemRecordList();
        this.getPlatRecordList();
      },
      closePage() {
        const { fullPath } = this.$route;
        const {
          keepAliveModuleName, tableName
        } = this.$store.state.global.activeTab;
        this.$store.commit('global/tabCloseAppoint', {
          tableName,
          routeFullPath: fullPath,
          keepAliveModuleName,
          stopRouterPush: true,
        });
        // 跳转
        setTimeout(()=>{
          R3.store.commit('global/tabOpen', {
            type: 'S',
            tableName: 'T_OMSSTATEACCOUNT',
            tableId: '11448',
            back: true
          });
        }, 0);
      },
      // 添加对账说明
      addRecordExplain () {
        this.addRecordExplainShow = true;
      },
      // 对账单差异对账
      varianceReconciliation () {
        this.varianceReconciliationShow = true;
      },
      // 对账单对账
      reconciliation() {
        let ids = [];
        ids.push(this.pageMsgId)
        let params = {
          ids:ids
        }
        network.post('/p/cs/reconciliation ',params).then((res) => {
          if(res.data.code == 0){
            this.$Message.success(res.data.message);
            this.refreshPage();
          }else {
            // this.$Message.error(res.data.message);
          }
        })
      },
      cancelModal(type) {
        if(type == 'explain'){
          this.addRecordExplainShow = false;
        }else if(type == 'varianceReconciliation'){
          this.varianceReconciliationShow = false
        }
      },
      // 确定添加对账说明
      sureChangeExplain() {
        let params = {
          ID: this.pageMsgId,
          reconciliationexplain: this.ExplainForm.explain,
        }
        network.post('/p/cs/addReconciliationInstructions',params).then((res) => {
          if(res.data.code == 0){
            this.$Message.success(res.data.message);
            this.cancelModal('explain');
            this.refreshPage();
          }else {
            this.$Message.error(res.data.message);
          }
        })
      },
      // 确定进行差异对账
      sureVarianceReconciliation() {
        let params = {
          ids: [Number(this.pageMsgId)]   // ID
        }
        network.post('/p/cs/differencesReconciliation',params).then((res) => {
          if(res.data.code == 0){
            this.$Message.success(res.data.message);
            this.cancelModal('varianceReconciliation');
            this.refreshPage();
          }else {
            // this.$Message.error(res.data.message);
          }
        })
      },
      getRecordFetail() {
        // let virtual={
        //   fixedcolumns: {ID: this.pageMsgId}, //this.pageMsgId
        //   range: 10,
        //   startindex: 0,
        //   table: "T_OMSSTATEACCOUNT",
        // }
        let virtual={
          table: "T_OMSSTATEACCOUNT",
          objid: this.pageMsgId,
        }
        network.post('/p/cs/object/query',virtual).then((res) => {
          let list = []
          list.push(res.data)
          list.forEach(item => {
            this.tabList[0].list.forEach(itemOne => {
              if(item[itemOne.skey]){
                itemOne.value = item[itemOne.skey]
              }
            })
            this.tabList[1].list.forEach(itemOne => {
              if(itemOne.skey == 'DIFFADJUSTAMOUNT' && item[itemOne.skey] == ''){
                itemOne.value = 0; //差异调整金额
              } else {
                itemOne.value = item[itemOne.skey]
              }

              // if(item[itemOne.skey]){
              //   itemOne.value = item[itemOne.skey]
              // }else if(itemOne.skey == 'DIFFADJUSTAMOUNT'){
              //   itemOne.value = 0; //差异调整金额
              // }
            })
            if(item.RECONCILIATIONSTATUS == 0){ // 未对账
              this.RecordStatusImg = require('../../assets/orderEditorImg/unRecord.png');
            }else if(item.RECONCILIATIONSTATUS == 1){ // 对账成功
              this.RecordStatusImg = require('../../assets/orderEditorImg/recordSuccess.png');
            }else if(item.RECONCILIATIONSTATUS == 2){ // 部分对账
              this.RecordStatusImg = require('../../assets/orderEditorImg/partRecord.png');
            }else if(item.RECONCILIATIONSTATUS == 3) { // 对账失败
              this.RecordStatusImg = require('../../assets/orderEditorImg/recordError.png');
            }
            this.DIFFADJUSTAMOUNT = item.DIFFADJUSTAMOUNT?item.DIFFADJUSTAMOUNT:0; //差异调整金额
            this.DIFFERENCESAMOUNT = item.DIFFERENCESAMOUNT?item.DIFFERENCESAMOUNT:0; //差异金额
            this.VarianceForm.amount = item.DIFFERENCESAMOUNT?item.DIFFERENCESAMOUNT:0; //差异金额
            this.tabList[2].TotalIncome = item.SYSINCOMEAMOUNT?item.SYSINCOMEAMOUNT:0; //系统收入合计
            this.tabList[2].TotalExpenditure = item.SYSSPENDINGAMOUNT?item.SYSSPENDINGAMOUNT:0; //系统支出合计
            this.tabList[2].TotalReceive = item.SYSRECEIVEDAMOUNTSUM?item.SYSRECEIVEDAMOUNTSUM:0; //系统应收合计
            this.tabList[3].TotalIncome = item.PLATINCOMEAMOUNT?item.PLATINCOMEAMOUNT:0; //平台收入合计
            this.tabList[3].TotalExpenditure = item.PLATSPENDINGAMOUNT?item.PLATSPENDINGAMOUNT:0; //平台支出合计
            this.tabList[3].TotalReceive = item.PLATRECEIVEDAMOUNTSUM?item.PLATRECEIVEDAMOUNTSUM:0; //平台实收合计
          })
        })
      },
      getSystemRecordList() { // 系统账单
            let virtual={
                fixedcolumns: {TOMSSTATEACCOUNTID: this.pageMsgId},
                isdroplistsearch: true,
                startindex: (this.systemCurrentPage-1)*this.tabList[2].pageSize,
                range: this.tabList[2].pageSize,
                table: "T_V_OMSSYSTEMBILL"
            }
            network.post('/p/cs/list/query',virtual).then((res) => {
              let data = [];
              for (let i = 0; i < res.data.rows.length; i++) {
                for (let j = 0; j < Object.keys(res.data.rows[i]).length; j++) {
                  let keyName = Object.keys(res.data.rows[i])[j];
                  if(keyName=='MANUAL_CHECK_STATUS'){
                    res.data.rows[i][keyName] = res.data.rows[i][keyName].refobjval.toString();
                  }else {
                    res.data.rows[i][keyName] = res.data.rows[i][keyName].val;
                  }
                }
                data.push(res.data.rows[i]);
              }
              this.tabList[2].systemBillData = data
              this.tabList[2].totalCount =  res.data.total
              this.systemBillDataOld = this.tabList[2].systemBillData.map(item => {
                  return Object.assign({}, { 'ID': item.ID,'MANUAL_CHECK_STATUS': item.MANUAL_CHECK_STATUS, "REMARKS": item.REMARKS, "PLATFORM_BILLDATE": item.PLATFORM_BILLDATE })
              })
            })
      },
      getPlatRecordList() { // 平台账单
          let virtual={
                fixedcolumns: {TOMSSTATEACCOUNTID: this.pageMsgId},
                isdroplistsearch: true,
                startindex: (this.platCurrentPage-1)*this.tabList[3].pageSize,
                range: this.tabList[3].pageSize,
                table: "T_V_OMSPLATFORMBILL"
            }
            network.post('/p/cs/list/query',virtual).then((res) => {
              let data = [];
              for (let i = 0; i < res.data.rows.length; i++) {
                for (let j = 0; j < Object.keys(res.data.rows[i]).length; j++) {
                  let keyName = Object.keys(res.data.rows[i])[j];
                  if(keyName=='MANUAL_CHECK_STATUS'){
                    res.data.rows[i][keyName] = res.data.rows[i][keyName].refobjval.toString();
                  }else {
                    res.data.rows[i][keyName] = res.data.rows[i][keyName].val;
                  }
                }
                data.push(res.data.rows[i]);
              }
              this.tabList[3].systemBillData = data
              this.tabList[3].totalCount =  res.data.total
              this.platformBillDataOld = this.tabList[3].systemBillData.map(item => {
                  return Object.assign({}, { 'ID': item.ID,'MANUAL_CHECK_STATUS': item.MANUAL_CHECK_STATUS, "REMARKS": item.REMARKS })
              })
            })
      },
      // 系统账单表分页
      changePageSys(val){
        this.systemCurrentPage = val;
        this.getSystemRecordList();
      },
      changeSizeSys(val) {
        this.tabList[2].pageSize = val;
        this.systemCurrentPage = 0;
        this.getSystemRecordList();
      },

      // 平台账单表分页
      changePagePlat(val){
        this.platCurrentPage = val;
        this.getPlatRecordList();
      },
      changeSizePlat(val) {
        this.tabList[3].pageSize = val;
        this.platCurrentPage = 0;
        this.getPlatRecordList();
      },
      // 新增保存按钮
      SaveExchange() {
        let system_bill = [];
        let platform_bill = [];
        console.log(this.systemBillDataOld,'==========')
        this.tabList[2].systemBillData.forEach((item,index) => {
          if((item.MANUAL_CHECK_STATUS != this.systemBillDataOld[index].MANUAL_CHECK_STATUS) || (item.REMARKS != this.systemBillDataOld[index].REMARKS) || (item.PLATFORM_BILLDATE != this.systemBillDataOld[index].PLATFORM_BILLDATE)){
            let obj = {
              "id":item.ID,
              "manual_check_status":item.MANUAL_CHECK_STATUS,
              "remarks":item.REMARKS,
            }
            if(item.PLATFORM_BILLDATE){
              obj.platform_billdate = item.PLATFORM_BILLDATE
            }
            system_bill.push(obj)
          }
        })
        this.tabList[3].systemBillData.forEach((item,index) => {
          if((item.MANUAL_CHECK_STATUS != this.platformBillDataOld[index].MANUAL_CHECK_STATUS) || item.REMARKS != this.platformBillDataOld[index].REMARKS){
            let obj = {
              "id":item.ID,
              "manual_check_status":item.MANUAL_CHECK_STATUS,
              "remarks":item.REMARKS
            }
            platform_bill.push(obj)
          }
        })
        let flag = true;
        //遍历循环当前系统账单和平台账单，是否有修改的数据

        for(let i=0;i<this.systemBillDataOld.length;i++){
          if((this.systemBillDataOld[i].MANUAL_CHECK_STATUS != this.tabList[2].systemBillData[i].MANUAL_CHECK_STATUS)||(this.systemBillDataOld[i].REMARKS != this.tabList[2].systemBillData[i].REMARKS)){
            flag = false;
            break;
          }
          console.log(this.systemBillDataOld[i].PLATFORM_BILLDATE,this.tabList[2].systemBillData[i].PLATFORM_BILLDATE,'==========')
          if((this.systemBillDataOld[i].PLATFORM_BILLDATE != this.tabList[2].systemBillData[i].PLATFORM_BILLDATE)){
            flag = false;
            break;
          }
        }
        for(let i=0;i<this.platformBillDataOld.length;i++){
          if((this.platformBillDataOld[i].MANUAL_CHECK_STATUS != this.tabList[3].systemBillData[i].MANUAL_CHECK_STATUS)||(this.platformBillDataOld[i].REMARKS != this.tabList[3].systemBillData[i].REMARKS)){
            flag = false;
            break;
          }
        }

        if(!flag) {
          let params = {
            id: this.pageMsgId,
            system_bill,
            platform_bill
          }
          console.log(params)
          debugger
          network.post('/p/cs/reconciliation/saveInfo',params).then(res => {
            if(res.data.code == 0){
              this.getSystemRecordList();
              this.getPlatRecordList();
              this.$Message.success(res.data.message)
            }
          })
        }else {
          return this.$Message.warning('暂无数据修改，无需保存！')
        }
        
      }
    }
  };
</script>
<style lang="less" scoped>
  .quickOperation{
    position: fixed;
    top: 82px;
    background: #fff;
    width: 100%;
    z-index: 10;
    height: 64px;
    display: flex;
    align-items: center;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    padding-left: 16px;
    border-bottom: 1px solid #D8D8D8;
  }
  .r3-vertical-content .quickOperation{ 
    top: 32px;
  }
  .content {
    margin: 16px;
    .block {
      padding-top: 24px;
    }
  }
  .order-setting-input-error:before{
    content: '*';
    color: red;
  }
  .refund-content{
    margin:0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;

    .count-part{
        height: 60px;
        margin-bottom: 16px;
        border-bottom: 1px solid #D8D8D8;
        .item{
            display: flex;
            align-items: center;
            .text{
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
            }
        }
        .img-framelanflag{
            cursor: pointer;
            vertical-align: middle;
            margin-top: -3px;
            margin-left: 5px;
            width: 16px;
        }
        .input-money{
            width: 80px;margin:0 8px
        }
        .plus{
            margin: 0 16px;
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #979797;
        }
    }
    .total-part{
        display: flex;
        align-items: center;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
    }
  }
  .UnderTableCalcu {
    display: flex;
    margin-top: 20px;
    .item {
      width: 250px;
      font-size: 14px;
      font-weight: 600;
      color: #333;
      text-align: center;
      p {
        margin-bottom: 10px;
      }
    }
  }
  .bottomBtnBox {
      width: calc(100% + 32px);
      margin: 16px auto 0px;
      margin-left: -16px;
      text-align: center;
      border-top: 1px solid #DEDEDE;
      padding-top: 16px;
      .cancelBtn,.sureBtn {
        width: 72px;
        height: 32px;
        font-size: 12px;
      }
      .cancelBtn {
        color: #909399;
        border: 1px solid #DADADA;
        margin-right: 8px;
      }
  }
  .pageContent {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
  }
</style>
