relateOneStep.vue 11.3 KB
<template>
  <div class="relate-one-step">
    <div class="box">
      <div class="container checked-box">
        <div class="title">已选项</div>
        <div v-show="!checkedList.trade.length && !checkedList.order.length" class="empty-box">
          <img style="margin-top: 60px;" class="order-empty" src="@/assets/order-empty.png">
          <div>暂无选项,请在下方数据列中选择</div>
        </div>
        <div v-show="checkedList.trade.length || checkedList.order.length" class="content">
          <div class="block" v-for="(item, index) in tableFormData" :key="index">
            <div class="row" v-for="(row, rowIdx) in checkedList[item.type]" :key="rowIdx">
              <el-checkbox class="check-box" v-model="row.checked" @change="handleChecked(item.type, item.tableParams.uniqueKey, row, rowIdx, true)"></el-checkbox>
              <div>
                <div v-for="(subItem, subIndex) in item.tableParams.tableColumns" :key="subIndex">
                  <div>
                    <span class="label">{{subItem.label}}:</span>
                    <span>{{subItem.prefix}}</span>{{row[subItem.prop]}}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="box">
      <div class="container" v-for="(item, index) in tableFormData" :key="index">
        <div class="title">{{item.title}}</div>
        <div class="content">
          <div class="search-box">
            <d2-search ref="showSearch" class="search-box" :search-form="searchForm[item.type]" :search-select-obj="searchSelectObj" :form-data="searchFormData[item.type]" />
            <el-button @click="handleSearch(item)" size="small" type="primary">搜索</el-button>
          </div>
          <div v-show="!baseData[item.type].length" class="empty-box">
            <img style="margin-top: 132px;" class="order-empty" src="@/assets/order-empty.png">
            <div>没有找到相关结果</div>
          </div>
          <div v-show="baseData[item.type].length">
            <div class="row" v-for="(row, rowIdx) in baseData[item.type]" :key="rowIdx">
              <el-checkbox :disabled="checkedList[item.type].length >= checkedMaxLen" class="check-box" v-model="row.checked" @change="handleChecked(item.type, item.tableParams.uniqueKey, row, rowIdx)"></el-checkbox>
              <div>
                <div v-for="(subItem, subIndex) in item.tableParams.tableColumns" :key="subIndex">
                  <div>
                    <span class="label">{{subItem.label}}:</span>
                    <span>{{subItem.prefix}}</span>{{row[subItem.prop]}}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <el-pagination background @current-change="e => handleCurrentChange(e, item)" :current-page.sync="pageObj[item.type].currentPage" :page-size="pageObj[item.type].pageSize" layout="total, prev, pager, next" :total="pageObj[item.type].total" :pager-count="5">
        </el-pagination>
      </div>
    </div>
    <div class="flex">
      <div class="footer">
        <el-button :disabled="!checkedList.trade.length || !checkedList.order.length || price.trade != price.order" type="primary" @click="handleNext">下一步</el-button>
        <div v-if="checkedList.trade.length || checkedList.order.length" :class="[price.trade == price.order ? 'success-txt' : 'red-txt']">交易金额=¥{{price.trade}},主订单金额=¥{{price.order}},金额校验{{price.trade == price.order ? '通过' : '不通过'}}!</div>
      </div>
    </div>
  </div>
</template>
<script>
import { Util } from "@/common/util"
import api from "@api/orderManage"
export default {
  name: "relateOneStep",
  data() {
    return {
      checkedMaxLen: 9,
      searchSelectObj: {
        trade: {
          attr: 'tradeNo',
          value: ''
        },
        order: {
          attr: 'orderCode',
          value: ''
        }
      },
      searchForm: {
        trade: {},
        order: {}
      },
      searchFormData: {
        trade: [{
          type: 'selectInput',
          selectName: 'trade',
          isClear: true,
          maxlength: 50,
          selectOption: [{
            label: '交易参考号',
            name: 'tradeNo'
          }, {
            label: '金额',
            name: 'totalFee'
          }],
          handleSelectChange: (value) => {
            this.searchSelectObj.trade.value = ''
          }
        }],
        order: [{
          type: 'selectInput',
          selectName: 'order',
          isClear: true,
          maxlength: 50,
          selectOption: [{
            label: '主订单号',
            name: 'orderCode'
          }, {
            label: '金额',
            name: 'finalPrice'
          }],
          handleSelectChange: (value) => {
            this.searchSelectObj.order.value = ''
          }
        }]
      },
      tableFormData: [{
        type: 'trade',
        title: '交易参考号',
        tableParams: {
          uniqueKey: 'tradeNo',
          tableColumns: [{
            label: '交易参考号',
            prop: 'tradeNo'
          }, {
            label: '支付时间',
            prop: 'accountDateTxt'
          }, {
            label: '交易金额',
            prop: 'totalFee',
            prefix: '¥'
          }]
        }
      }, {
        type: 'order',
        title: '主订单号',
        checkedName: 'tradeCheckedList',
        tableParams: {
          uniqueKey: 'orderCode',
          tableColumns: [{
            label: '主订单号',
            prop: 'orderCode'
          }, {
            label: '支付时间',
            prop: 'orderTimeTxt'
          }, {
            label: '交易金额',
            prop: 'finalPrice',
            prefix: '¥'
          }]
        }
      }],
      baseData: {
        trade: [],
        order: []
      },
      checkedList: {
        trade: [],
        order: []
      },
      pageObj: {
        trade: {
          total: 0,
          pageSize: 10,
          currentPage: 1
        },
        order: {
          total: 0,
          pageSize: 10,
          currentPage: 1
        }
      },
      price: {
        trade: 0,
        order: 0
      },
      apiObj: {
        trade: {
          type: 'trade',
          apiName: 'waitOrderTradeListApi',
          uniqueKey: 'tradeNo',
          searchName: 'tradeSearchData',
          fn: () => {
            this.baseData.trade.forEach(item => {
              item.accountDateTxt = Util.dateFormate(item.accountDate, "YYYY-MM-DD HH:mm:ss")
            })
          }
        },
        order: {
          type: 'order',
          apiName: 'waitOrderListApi',
          uniqueKey: 'orderCode',
          searchName: 'orderSearchData',
          fn: () => {
            this.baseData.order.forEach(item => {
              item.orderTimeTxt = Util.dateFormate(item.orderTime, "YYYY-MM-DD HH:mm:ss")
            })
          }
        }
      }
    }
  },
  mounted() {
    this.getList(this.apiObj.trade)
    this.getList(this.apiObj.order)
  },
  watch: {},
  methods: {
    addPrice(type) {
      const addValNameObj = {
        trade: 'totalFee',
        order: 'finalPrice',
      }
      this.price[type] = this.checkedList[type].length ? this.checkedList[type].map(item => item[addValNameObj[type]]).reduce((prev, cur) => {
        return prev + cur
      }).toFixed(2) : 0
    },
    // 选中/取消
    handleChecked(type, uniqueKey, row, rowIdx, changeListStatus) {
      let checkedIdx = this.checkedList[type].findIndex(k => k[uniqueKey] == row[uniqueKey])
      checkedIdx == -1 ? this.checkedList[type].push(JSON.parse(JSON.stringify(row))) : this.checkedList[type].splice(checkedIdx, 1)
      // 已选项,取消选项后,改变原来list的选中状态
      if (changeListStatus) {
        let idx = this.baseData[type].findIndex(k => k[uniqueKey] == row[uniqueKey])
        if (idx != -1) {
          this.baseData[type][idx].checked = !this.baseData[type][idx].checked
        }
      }
      this.addPrice(type)
    },
    getList(obj) {
      const params = {
        ...this.searchForm[obj.type],
        pageSize: this.pageObj[obj.type].pageSize,
        currentPage: this.pageObj[obj.type].currentPage
      }
      api[obj.apiName](params).then(res => {
        res.list.forEach(item => {
          let idx = this.checkedList[obj.type].findIndex(k => k[obj.uniqueKey] == item[obj.uniqueKey])
          item.checked = idx != -1
        })
        this.baseData[obj.type] = res.list
        this.pageObj[obj.type].total = res.total
        obj.fn && obj.fn()
      })
    },

    getSelectInputParams(obj) {
      const list = Object.keys(this.searchSelectObj)
      var params = {}
      list.forEach(i => {
        if (i == obj.type) {
          const item = this.searchSelectObj[i]
          item.value && (params[item.attr] = item.value)
        }
      })
      return params
    },

    handleSearch(obj) {
      this.searchForm[obj.type] = this.getSelectInputParams(obj)
      this.handleCurrentChange(1, obj)
    },

    handleCurrentChange(e, obj) {
      this.pageObj[obj.type].currentPage = e
      this.getList(this.apiObj[obj.type])
    },
    handleNext() {
      this.$emit('handleNext', this.checkedList)
    }
  }
}
</script>
<style lang="scss">
.relate-one-step {
  .d2-search .d2-search-block {
    padding: 0;
  }
  .flex {
    display: flex;
    justify-content: center;
  }
  .box {
    display: flex;
    justify-content: center;
    .search-box {
      display: flex;
    }
    .container {
      box-sizing: border-box;
      width: 456px;
      height: 544px;
      border-radius: 2px;
      opacity: 1;
      border: 1px solid #e5e5e5;
    }
    .container:first-child {
      margin-right: 48px;
    }
    .container.checked-box {
      width: 959px;
      height: 296px;
      margin: 20px 0;
    }
    .title {
      box-sizing: border-box;
      width: 100%;
      height: 40px;
      line-height: 40px;
      color: #333333;
      font-size: 16px;
      text-align: center;
      border-bottom: 1px solid #e5e5e5;
      background: #f8faff;
    }
    .content {
      box-sizing: border-box;
      height: 456px;
      overflow-y: scroll;
      padding: 16px;
    }
    .empty-box {
      width: 100%;
      text-align: center;
      color: #666666;
      font-size: 14px;
      .order-empty {
        width: 64px;
        height: 40px;
        margin-bottom: 16px;
      }
    }
    .checked-box .content {
      display: flex;
      height: 256px;
    }
    .checked-box .content .block {
      width: 50%;
    }
    .search-box {
      min-width: 0;
      height: 32px;
      line-height: 32px;
      margin-bottom: 16px;
      .el-input-group {
        width: 350px;
      }
    }
    .row {
      display: flex;
      align-items: center;
      padding-bottom: 16px;
      color: #333333;
      font-size: 14px;
      .label {
        color: #666666;
      }
      .check-box {
        margin-right: 8px;
      }
    }
    .el-pagination {
      box-sizing: border-box;
      height: 48px;
      line-height: 48px;
      padding: 10px 20px;
      border-top: 1px solid #e5e5e5;
    }
  }
  .success-txt {
    color: #2cca74;
    font-size: 14px;
  }
  .red-txt {
    color: #ca2c41;
    font-size: 14px;
  }
  .footer {
    width: 959px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    flex-direction: row-reverse;
  }
}
</style>