<template>
    <div class="branding">
        <div class="branding_header">
            <div class="branding_item_btn">
                <div @click="checkBtn">{{$t('pub.searchBtn')}}</div>
                <div @click="addBtn">{{$t('fnc.tianjia')}}</div>
            </div>
        </div>
        <div class="branding_name">
            <div>{{$t('salesModule.BrandName')}}</div>
            <div>
                <el-input v-model="checkData.Name" size="mini" :placeholder="$t('pub.pleaseImport')"></el-input>
            </div>
        </div>
        <div class="branding_list">
            <div class="branding_item" v-for="(option, index) in list" :key="index">
                <div>{{option.name}}</div>
                <div class="branding_item_btn">
                    <div @click="editBtn(index)">{{$t('pub.edit')}}</div>
                    <div @click="delBtn(option.id)">{{$t('system.ph_shanchu')}}</div>
                </div>
            </div>
        </div>
        <el-pagination background @current-change="handleCurrentChange" :current-page.sync="checkData.pageIndex" layout="total,prev, pager, next, jumper" :page-size='20' :total='checkData.pageCount'></el-pagination>
        <div v-show="editShow" class="branding_buttom">
            <div class="branding_buttom_header">
                <div>{{editType==='add'?'新增':'修改'}}{{$t('pub.Brand')}}</div>
                <div class="branding_item_btn">
                    <div @click="editOk">{{$t('pub.saveBtn')}}</div>
                    <div @click="editToHide">{{$t('pub.cancelBtn')}}</div>
                </div>
            </div>
            <div class="branding_name">
                <div>{{$t('demo.BrandName')}}</div>
                <div>
                    <el-input v-model="editData.Name" size="mini" :placeholder="$t('pub.pleaseImport')"></el-input>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
  name: "branding",
  data() {
    return {
      checkData: {
        Name: "",
        pageIndex: 1,
        pageSize: 20,
        pageCount: 1
      },
      editData: {
        ID: 0,
        Name: ""
      },
      list: [],
      pageSize: 0,
      editShow: false,
      editType: "add"
    };
  },
  created: function() {
    this.getList();
  },
  methods: {
    editToShow: function(type) {
      this.editType = type;
      this.editShow = true;
    },
    editToHide: function() {
      this.editShow = false;
      this.editData.ID = 0;
      this.editData.Name = "";
    },
    addBtn: function() {
      this.editData.ID = 0;
      this.editData.Name = "";
      this.editToShow("add");
    },
    editBtn: function(key) {
      this.editData.ID = this.list[key].id;
      this.editData.Name = this.list[key].name;
      this.editToShow("edit");
    },
    checkBtn: function() {
      this.checkData.pageIndex = 1;
      this.getList();
    },
    editOk: function() {
      if (this.editData.Name === "") {
        this.$message.error(this.$t('rule.EnterBrandName'));
      } else {
        this.apipost(
          "customer_post_Set",
          this.editData,
          res => {
            if (res.data.resultCode == 1) {
              this.editToHide();
              this.$message.success(res.data.message);
              this.getList();
            } else {
              this.$message.error(res.data.message);
            }
          },
          err => {}
        );
      }
    },
    delBtn: function(key) {
      this.$confirm(this.$t('tips.shifoushanchu'), this.$t('tips.tips'), {
        confirmButtonText: this.$t('pub.sureBtn'),
        cancelButtonText: this.$t('pub.cancelBtn'),
        type: "warning"
      }).then(() => {
          this.apipost(
            "customer_post_RemoveDictValue",
            {id: key},
            res => {
              if (res.data.resultCode === 1) {
                this.$message.success(res.data.message);
                this.getList();
              } else {
                this.$message.error(res.data.message);
              }
            },
            err => {}
          );
        })
        .catch(() => {
          this.$message.info(this.$t('tips.cancleDelete'));
        });
    },
    getList: function() {
      this.apipost(
        "customer_get_GetTravelOrderList",
        this.checkData,
        res => {
          if (res.data.resultCode == 1) {
            let data = res.data.data;
            this.checkData.pageCount = data.count;
            this.list = data.pageData;
          } else {
            this.$message.error(res.data.message);
          }
        },
        err => {}
      );
    },
    handleCurrentChange: function(val) {
      this.checkData.pageIndex = val;
      this.getList();
    }
  }
};
</script>

<style>
.branding {
  width: 100%;
  font-size: 0px;
}
/* 顶部按钮 */
.branding_header {
  position: absolute;
  right: 20px;
  top: 5px;
}

/* 头部搜索 */
.branding_name {
  margin: 20px 0;
  width: 100%;
  height: 34px;
}
.branding_name > div {
  display: inline-block;
  height: 34px;
  line-height: 34px;
  vertical-align: middle;
}
.branding_name > div:nth-child(1) {
  font-family: MicrosoftYaHei;
  font-size: 12px;
  color: #666666;
}
.branding_name > div:nth-child(2) {
  margin: 0 0 0 20px;
  width: 200px;
}

/* 数据列表 */
.branding_list {
  width: 100%;
  min-height: 400px;
}

.branding_item {
  display: inline-block;
  margin: 0 18px 18px 0;
  padding: 10px;
  width: 230px;
  height: 100px;
  background-color: #ffffff;
}
.branding_item > div:nth-child(1) {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: bold;
  font-size: 16px;
  color: #333333;
}
.branding_item > div:nth-child(2) {
  margin: 30px 0 0 0;
}
.branding_item_btn {
  height: 30px;
}
.branding_item_btn > div:nth-child(1) {
  display: inline-block;
  width: 60px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  font-size: 14px;
  color: #ffffff;
  background-color: #e95252;
  border: 1px solid #e95252;
  border-radius: 15px;
  cursor: pointer;
}
.branding_item_btn > div:nth-child(2) {
  margin: 0 0 0 10px;
  display: inline-block;
  width: 60px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  font-size: 14px;
  color: #e95252;
  background-color: #ffffff;
  border: 1px solid #e95252;
  border-radius: 15px;
  cursor: pointer;
}

/* 添加窗口 */
.branding_buttom {
  position: absolute;
  left: 0px;
  bottom: 0px;
  width: 100%;
  height: 130px;
  background-color: #ffffff;
  border-top: 3px solid #38425d;
}

.branding_buttom_header {
  margin: 10px 0 0 0;
  height: 30px;
}

.branding_buttom_header > div:nth-child(1) {
  margin: 0 0 0 30px;
  float: left;
  position: relative;
  height: 30px;
  line-height: 30px;
  font-weight: bold;
  font-size: 16px;
  color: #000000;
}
.branding_buttom_header > div:nth-child(1)::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 7px;
  width: 3px;
  height: 16px;
  background-color: #e95252;
}
.branding_buttom_header > div:nth-child(2) {
  margin: 0 10px 0 0;
  float: right;
}
.branding_buttom > .branding_name {
  display: inline-block;
  padding: 0 0 0 30px;
}
</style>