downloadAccountDialog.vue 9.9 KB
<!-- 下载对账单 -->
<template>
  <d2-dialog title="下载对账单"
             :is-visible="accountVisible"
             class="accountDailog"
             width="40%"
             btn-ok-label="确定下载"
             @closeDialog="handleClose"
             @confirmDialog="handleAddConfirm">
    <el-form ref="accountForm"
             :model="infoForm"
             :rules="formRules"
             label-width="120px">
      <el-form-item label="商户类型:"
                    prop="merchantType">
        <el-radio-group v-model="infoForm.merchantType"
                        @change="changeType">
          <el-radio-button label="2">
            4S店
          </el-radio-button>
          <el-radio-button label="7">
            服务商
          </el-radio-button>
          <el-radio-button label="6"
                           v-if="yqCheckVisible">
            园区店
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="infoForm.merchantType == '7'"
                    label="账单类型:"
                    prop="reportType">
        <el-radio-group v-model="infoForm.reportType">
          <el-radio-button label="1">
            普通对账单
          </el-radio-button>
          <el-radio-button label="2">
            安装费对账单
          </el-radio-button>
          <el-radio-button label="3">
            营销费对账单
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="选择商户:"
                    prop="merchant">
        <el-select v-model="infoForm.merchant"
                   multiple
                   :multiple-limit="10"
                   filterable
                   style="width:400px">
          <el-option v-for="item in baseData.merchantList"
                     :key="item.merchantId"
                     :label="item.merchantName"
                     :value="item.merchantId" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单支付时间:"
                    class="dateItem"
                    prop="payStartDate">
        <el-date-picker type="date"
                        placeholder="选择开始日期"
                        value-format="yyyy-MM-dd"
                        clearables
                        :picker-options="startDateOptions"
                        v-model="infoForm.payStartDate"
                        @change="changeStartDate"
                        style="width:185px" />
        <div style="margin:0 15px;">
          -
        </div>
        <el-date-picker type="date"
                        placeholder="选择结束日期"
                        value-format="yyyy-MM-dd"
                        clearable
                        v-model="infoForm.payEndDate"
                        :picker-options="pickerOptions0"
                        style="width:185px" />
      </el-form-item>
    </el-form>
  </d2-dialog>
</template>

<script>
import {
  rangePickerOptions
} from '@/common/constants.js'
import dayjs from 'dayjs'
import { deepClone } from '@/common/util'
import { getMerchantPageSearch } from '@api/publicAccount'
import { mapActions, mapState } from 'vuex'
export default {
  name: 'DownloadAccountDialog',
  data() {
    const validateLonlat = (rule, value, callback) => {
      if (value) {
        if (!this.infoForm.payEndDate) {
          callback(new Error('请选择结束日期'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      pickerOptions0: {
        disabledDate: time => {
          if (this.infoForm.payStartDate) {
            return (
              time.getTime() >
              dayjs(this.infoForm.payStartDate)
                .add(1, 'y')
                .valueOf() ||
              time.getTime() > Date.now() - 8.64e6 ||
              time.getTime() <
              new Date(this.infoForm.payStartDate).getTime() -
              1 * 24 * 60 * 60 * 1000
            )
          } else {
            return true
          }
        }
      },
      startDateOptions: {
        disabledDate: time => {
          return time.getTime() > Date.now() - 8.64e6
        }
      },
      EndDateOptions: {
        disabledDate: time => {
          if (this.infoForm.payStartDate) {
            return time.getTime() > Date.now()
          } else {
            return false
          }
        }
      },
      pickerOption: {
        rangePickerOptions: rangePickerOptions
      },
      userInfo: this.$store.state.d2admin.user.info,
      infoForm: {
        merchantType: '',
        merchant: [],
        payStartDate: '',
        payEndDate: '',
        reportType: '1'
      },

      formRules: {
        merchantType: [{ required: true, message: '请选择商户类型', trigger: 'change' }],
        merchant: [
          { required: true, message: '请选择商户', trigger: 'change' }
        ],
        payStartDate: [
          { required: true, message: '请选择时间', trigger: 'change' },
          { required: true, trigger: 'change', validator: validateLonlat }
        ]
      },
      selectLoading: false,
      // 基本数据
      baseData: {
        merchantList: []
      },
      yqCheckVisible: true
    }
  },

  props: {
    accountVisible: {
      type: Boolean,
      default: false
    },
    scene: {
      type: String,
      default: ''
    }
  },

  watch: {

  },

  created() {
  },
  components: {},

  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },

  mounted() {
    console.log(this.scene)
    if (this.scene == '2' || this.scene == '3' || this.scene == '4') {
      /** 新改逻辑:园区店选项只对精品升级/会员权益可见 */
      this.yqCheckVisible = false
    }
    // this.selectMerchant()
  },

  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    selectMerchant() {
      var params = {}
      params.currentPage = 1
      params.pageSize = 10000
      var merchantTypeList = []
      if (this.infoForm.merchantType) {
        if (this.infoForm.merchantType == 6) {
          merchantTypeList = [6, 8]
        } else {
          merchantTypeList.push(this.infoForm.merchantType)
        }
      }
      params.merchantTypeList = merchantTypeList
      getMerchantPageSearch(params).then(res => {
        this.baseData.merchantList = res.list
      })
    },

    clickMerchantType(e) {
      e === this.infoForm.merchantType
        ? (this.infoForm.merchantType = '')
        : (this.infoForm.merchantType = e)
      console.log(this.infoForm.merchantType)
    },

    changeType() {
      this.infoForm.merchant = []
      this.selectMerchant()
    },

    changeStartDate() {
      if (this.infoForm.payEndDate) {
        this.infoForm.payEndDate = ''
      }
    },

    remoteMethod(query) {
      this.selectLoading = true
      var params = {}
      params.currentPage = 1
      params.pageSize = 1000
      params.merchantName = query
      var merchantTypeList = this.infoForm.merchantType
        ? [this.infoForm.merchantType]
        : []
      params.merchantTypeList = merchantTypeList
      getMerchantPageSearch(params).then(res => {
        this.selectLoading = false
        this.baseData.merchantList = res.list
      })
    },

    handleAddConfirm() {
      this.$refs.accountForm.validate(valid => {
        if (valid) {
          var infoForm = deepClone(this.infoForm)
          console.log(infoForm)
          var params = {}
          var merchantList = []
          var obj
          infoForm.merchant.forEach(item => {
            obj = {}
            obj.merchantId = item
            obj.merchantName = this.baseData.merchantList.find(
              mer => mer.merchantId === item
            ).merchantName
            merchantList.push(obj)
          })
          params.payStartDate = infoForm.payStartDate + ' 00:00:00'
          params.payEndDate = infoForm.payEndDate + ' 23:59:59'
          merchantList.forEach((item, index) => {
            const merchantName = `merchantList[${index}].merchantName`
            const merchantId = `merchantList[${index}].merchantId`
            params[merchantName] = item.merchantName
            params[merchantId] = item.merchantId
          })
          params.merchantType = infoForm.merchantType
          if (infoForm.merchantType == '7') {
            params.reportType = infoForm.reportType
          }
          params.sceneType = this.scene
          params.method = 'dj.api.smartcarlife.goodsOrderProfitAllocation.exportAccountStatementForAudit.async'
          console.log('params', params)
          const list = [
            ...this.dowloadList,
            {
              name: '对账单',
              // uuid: JSON.parse(res).data,
              // ifSuccess: false
              exportParam: JSON.stringify(params),
              status: 'waiting',
              timeid: new Date().getTime()
            }
          ]
          this.actionSetDownloadList({ list, type: 'dowloadList' })
          this.handleClose()
        }
      })
    },

    handleClose() {
      this.$emit('accountClose', true)
    }
  }
}
</script>
<style scoped>
.dateItem {
  display: flex;
}
::v-deep .dateItem .el-form-item__content {
  display: flex;
  margin-left: 0 !important;
}
::v-deep .accountDailog {
  /*下拉选择框-多选-内容过长-用...代替    begin    */
  .el-tag.el-tag--info {
    background-color: #f4f4f5;
    border-color: #e9e9eb;
    color: #909399;
    max-width: calc(100% - 50px);
    /* white-space: nowrap;
     text-overflow: ellipsis;
     overflow: hidden;*/
  }
  .el-tag.el-tag--info {
    width: calc(100% - 200px);
  }
  .el-tag.el-tag--info .el-select__tags-text {
    width: calc(100% - 20px);
    float: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  /*下拉选择框-多选-内容过长-用...代替    end    */
  .accountDailog .el-dialog {
    min-width: 700px;
  }
  .accountDailog .el-select-dropdown__item {
    width: 395px !important;
  }
}
</style>