<!--
 * @Descripttion: 营销管理 - 充值提货卡
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <div class="form_all">
        <el-form
          ref="select"
          :model="select"
          label-width="auto"
        >
          <el-row :gutter="40">
            <!-- 一层 -->
            <el-col :span="4">
              <el-form-item :label="$t('MN_T_1')">
                <el-input
                  v-model="select.memberCode"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="$t('CK_KS_14')">
                <el-input
                  v-model="select.memberName"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="$t('MN_F_T_693')">
                <el-select
                  v-model="select.pickType"
                  clearable
                  :placeholder="$t('CK_KS_38')"
                >
                  <el-option
                    v-for="item in actStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="$t('PER_DA_9')">
                <el-date-picker
                  v-model="select.creationTime"
                  value-format="yyyy-MM-dd"
                  type="datetimerange"
                  format="yyyy-MM-dd"
                  :range-separator="$t('w_0139')"
                  :start-placeholder="$t('CK_KS_4')"
                  :end-placeholder="$t('CK_KS_5')"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="$t('w_0444')">
                <el-date-picker
                  v-model="select.modifiedTime"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  type="datetimerange"
                  :range-separator="$t('w_0139')"
                  :start-placeholder="$t('CK_KS_4')"
                  :end-placeholder="$t('CK_KS_5')"
                  @change="changeTime1"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="$t('w_0471')">
                <el-date-picker
                  v-model="select.receiveTime"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  type="datetimerange"
                  :range-separator="$t('w_0139')"
                  :start-placeholder="$t('CK_KS_4')"
                  :end-placeholder="$t('CK_KS_5')"
                  @change="changeTime2"
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button
                class="my_search"
                type="primary"
                @click="getDataList"
              > {{ $t('MN_T_2') }}</el-button>
              <el-button
                class="my_reset"
                @click="reset"
              > {{ $t('MN_T_3') }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button
            size="small"
            class="addBtn"
            v-hasButtons="['cardAdd']"
            @click="openDig"
          >{{$t('w_0328')}}</el-button>
          <el-button
            size="small"
            class="thebtn2"
            v-hasButtons="['cardExport']"
            @click="handleExport"
          > {{ $t('MN_T_8') }}</el-button>
        </div>
        <div class="maintable">
          <el-table
            :data="tableData"
            v-loading="loading"
            style="width: 100%"
            height="73vh"
            :header-cell-style="{ background: '#EEEEEE' }"
            :row-class-name="tableRowClassName"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              width="55"
            />
            <el-table-column
              align="center"
              prop="memberCode"
              :label="$t('MN_T_1')"
              width="140"
            />
            <el-table-column
              align="center"
              prop="memberName"
              :label="$t('CK_KS_14')"
            />
            <el-table-column
              align="center"
              prop=""
              :label="$t('MN_F_T_696')"
            >
              <template slot-scope="scope">
                <div v-for="item in scope.row.detailList">
                  {{ item.productName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="memberName"
              :label="$t('MN_F_43')"
              width="100"
            >
              <template slot-scope="scope">
                <div v-for="item in scope.row.detailList">
                  {{ item.quantity }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="pickTypeVal"
              :label="$t('MN_F_T_693')"
              width="100"
            />
            <el-table-column
              align="center"
              prop="actName"
              :label="$t('MN_F_T_639')"
            />
            <el-table-column
              align="center"
            prop="usableQuantity"
            :label="$t('MN_F_T_697')"
              width="120"
            />
            <el-table-column
              align="center"
              prop="usedQuantity"
              :label="$t('MN_F_T_698')"
              width="120"
            />
            <el-table-column
              align="center"
              prop="creationTime"
              :label="$t('PER_DA_9')"
              width="160"
            />
            <el-table-column
              align="center"
              prop="modifiedTime"
              :label="$t('w_0444')"
              width="160"
            />
            <el-table-column
              align="center"
              prop="receiveTime"
              :label="$t('w_0433')"
              width="160"
            />
            <el-table-column
              align="center"
              prop="time"
              :label="$t('MY_ORD_14')"
              fixed="right"
              width="120"
            >
              <template slot-scope="scope">
             
              <div class="btnHeng">
                <div @click="toFixed(scope.row.pkId,2)"
                     type="text"
                     v-if="scope.row.pickType!=8"
                     v-hasButtons="['cardUpdata']"
                     style="color:#F3A900"
                     size="small">
                  {{ $t('ENU_CONTROL_TYPE_2') }}
                </div>
                <div @click="toDel(scope.row.pkId)"
                     type="text"
                     v-hasButtons="['cardDel']"
                     size="small"
                     style="color: #C8161D">
                  {{ $t('CK_KS_47') }}
                </div>
              </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/giftGoods.js'
import {tgtype} from "@/api/giftGoods.js";
import {getPickList} from "@/api/manage";
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
 isAgree(val) {
      if (!val) {
        return this.$t('ENU_POPUP_TYPE_1');
      } else {
        return this.$t('ENU_POPUP_TYPE_2');
      }
    }
  },
  data() {
    return {
      creationTime: [],
      creationTime1: [],
      creationTime2: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading:false,
      moren: 'RechargeCardList',
      topList: [
        {
          name: this.$t('MN_F_T_153'),
          path: 'RechargeCardList'
        }
      ],
      form: {
        name: ''
      },
      rules: {
        name: [{ required: true, message: this.$t('MN_F_T_302'), trigger: 'blur' }]
      },
      actStatus: []
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
  },
  methods: {
    // 重置
    reset() {
      this.select = {
        pageNum: 1,
        pageSize: 50
      }
      this.getDataList()
    },
    getData() {
      api.tgtype().then((res) => {
        this.actStatus = res.data
      })
    },
    changeTime(val) {
      // this.select.startActStartDate = val[0]
      // this.select.startActEndDate = val[1]
    },
    changeTime1(val) {
      // this.select.endActStartDate = val[0]
      // this.select.endActEndDate = val[1]
    },
    changeTime2(val) {
      // this.select.startCreationTime = val[0]
      // this.select.endCreationTime = val[1]
    },
    // 点击修改
    toFixed(id, index) {
      // this.addOrEdit = false
      // this.dialogVisible = true
      this.$router.push({
        name: 'addRechargeCard',
        query: {
          pkId: id,
          type: 2
          // functionType:this.select.functionType
        }
      })
    },
    toDel(id){
      this.$router.push({
        name: 'addRechargeCard',
        query: {
          pkId: id,
          type: 3
          // functionType:this.select.functionType
        }
      })
    },
    // 删除
    handleDelete(id) {
      this.$confirm(this.$t('MN_F_T_303'), this.$t('w_0034'), {
        confirmButtonText: this.$t('w_0035'),
        cancelButtonText: this.$t('ENU_P_TYPE0'),
        type: 'warning'
      }).then(() => {
        api.activityRemove(id).then((res) => {
          this.getDataList()
        })
      })
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = ''
          if (this.addOrEdit == true) {
            url = classifySave
          } else {
            url = classifyUpdate
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.dialogVisible = false
              // 充值数据
              this.$refs[formName].resetFields()
              // 获取列表
              this.getDataList()
            }
          })
        } else {
          return false
        }
      })
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    openDig() {
      this.$router.push({
        name: 'addRechargeCard',
        query: {
          type: 1
        }
      })
    },

    // 获取列表
    getDataList() {
      this.loading = true
      getPickList(Object.assign({},this.queryParams,this.select))
        .then((res) => {
          this.tableData = res.rows
          this.total = res.total
          this.loading = false
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm( this.$t('MN_F_T_407'), this.$t('MN_F_T_304'), {
        confirmButtonText: this.$t('w_0035'),
        cancelButtonText: this.$t('ENU_P_TYPE0'),
        type: 'warning'
      }).then((_) => {
        this.download(
          '/activity/manage/pick/export',
          Object.assign({}, this.queryParams, this.select),
          `${this.$t('MN_F_T_699')}-${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style scoped lang="scss">
.thebtn2 {
  background: #ffad41;
  color: #ffffff;
  height: 32px;
}
::v-deep .el-range-editor{
  width: 100%!important;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    // background: #ffffff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    .main_a {
      background: #fff;
      border-radius: 8px;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    }
    .mainbtn {
      padding: 0 20px;
    }
    .maintable {
      flex: 1;
    }
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
.form_all {
  padding: 0 20px 0 20px;
  margin-bottom: 3px;
  background: #fff;
}
.btnHeng {
  display: flex;
  justify-content: space-around;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}
</style>
