relatActivityOrderDialog.vue 7.39 KB
<!-- 关联活动订单弹窗 -->
<template>
  <d2-dialog title="关联活动订单"
             :is-visible="relatActivityVisible"
             class="relatActivityDailog"
             width="80%"
             @closeDialog="handleClose"
             @confirmDialog="handleAddConfirm">
    <div>
      <!-- <d2-container> -->
      <div class="header"
           slot="header"
           style="padding: 10px 20px;">
        <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                   :search-select-obj="searchSelectObj"
                   :form-data="showFormData" />
        <div class="up-btns">
          <el-button @click="handleSearch"
                     size="small"
                     type="primary">
            查询
          </el-button>
          <el-button size="small"
                     @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
      <!-- </d2-container>
    <d2-container> -->
      <div class="d2-container-content">
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn"
                  :has-num="false">
          <div slot="single-button"
               slot-scope="scope">
            <el-radio v-model="radio"
                      :label="scope.scope.orderCode"><i></i></el-radio>
          </div>
        </d2-table>
      </div>
      <!-- </d2-container> -->
    </div>
  </d2-dialog>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { shopmallOrderList, relatedActivityOrder } from '@api/order'
export default {
  name: 'RelatActivityOrderDialog',
  components: {

  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      countObj: {},
      searchForm: {
        merchantName: '',
        activityName: ''
      },
      searchFormSearch: {},
      searchSelectObj: {
        orderOrTrade: {
          attr: 'inputtedOrderCode',
          value: ''
        }
      },
      showFormData: [{
        label: '支付时间',
        name: 'orderDate',
        type: 'datePicker',
        isClear: true,
        pickerOptions: 'rangePickerOptions'
      }, {
        label: '商户名称',
        name: 'merchantName',
        type: 'input',
        maxlength: 20,
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '所属活动',
        name: 'activityName',
        type: 'input',
        maxlength: 20,
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '客户名称',
        name: 'customerName',
        type: 'input',
        maxlength: 20,
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '手机号',
        name: 'customerPhone',
        type: 'input',
        inputType: "number",
        maxlength: 11,
        isClear: true,
        keyFn: this.keyDowmGetList
      }],
      getListApi: shopmallOrderList,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        singleSelectUniqueKey: 'id',
        tableOption: false,
        tableColumns: [{
          label: '订单编号',
          prop: 'orderCode',
          width: '200px'
        }, {
          label: '订单时间',
          prop: 'orderTime',
          width: '150px',
          formatter: (cellValue) => {
            return cellValue.orderTime ? Util.dateFormate(cellValue.orderTime, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }, {
          label: '客户名称',
          prop: 'customerName'
        }, {
          label: '手机号',
          prop: 'customerPhone',
          width: '120px'
        }, {
          label: '商品名称',
          prop: 'goodsName',
          formatter: (cellValue) => {
            if (cellValue.subOrderList && cellValue.subOrderList.length > 0) {
              return cellValue.subOrderList.reduce((str, item, index) => {
                // return item.goodsName
                if (index) {
                  str += '/' + item.goodsName
                } else {
                  str += item.goodsName
                }
                return str
              }, '')
              // return cellValue.subOrderList[0].goodsName
            } else {
              return ''
            }
          }
        }, {
          label: '活动名称',
          prop: 'activityName'
          // width: '200px'
        }, {
          label: '所属门店',
          prop: 'merchantName'
          // width: '200px'
        }, {
          label: '尾款总额',
          prop: 'balancePaymentPrice',
          formatter: (cellValue) => {
            return cellValue.balancePaymentPrice ? '¥' + cellValue.balancePaymentPrice : ''
          }
        }, {
          label: '支付时间',
          prop: 'payDate',
          width: '150px',
          formatter: (cellValue) => {
            return cellValue.payDate ? Util.dateFormate(cellValue.payDate, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }
        ]
      },
      baseData: {

      },

      merchantDialogVisible: false,
      ids: [],
      radio: ''
    }
  },

  props: {
    relatActivityVisible: {
      type: Boolean,
      default: false
    },
    orderId: {
      type: [String, Number],
      default: ''
    }
  },

  computed: {

  },
  mounted() {

  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)

        if (this.searchFormSearch.orderDate) {
          this.searchFormSearch.orderStartTime = Util.dateFormate(this.searchFormSearch.orderDate[0], 'YYYY-MM-DD HH:mm:ss')
          this.searchFormSearch.orderEndTime = Util.dateFormate(this.searchFormSearch.orderDate[1], 'YYYY-MM-DD') + ' 23:59:59'
          delete this.searchFormSearch.orderDate
        }
        // var orderOrTrade = this.getSelectInputParams()
        // this.searchFormSearch = Object.assign(this.searchFormSearch, orderOrTrade)
        resolve()
      })
    },

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

    handleSearch() {
      this.$refs.recordTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        merchantName: '',
        activityName: ''
      }
      this.$refs.recordTable.refreshTable()
    },

    handleAddConfirm() {
      console.log("radio", this.radio)
      if (!this.radio) {
        this.notice.warningTips('请选择要关联的订单')
        return
      }
      var params = {}
      params.id = this.orderId
      params.inputtedOrderCode = this.radio
      // return console.log('params', params);

      relatedActivityOrder(params).then(res => {
        this.notice.okTips('关联活动订单成功')
        this.handleClose(true)
      })
    },

    handleClose(flag) {
      this.$emit('dialogClose', flag)
    }

  }
}

</script>
<style scoped>
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}
.relatActivityDailog .el-dialog {
  margin-top: 20vh !important;
  min-width: 700px;
}
</style>