<template>
  <div>
    <el-dialog
      v-dialogDrag
      title="鑷畾涔夋爮浣�"
      class="el-dialog-double FieldConfigDialog"
      :visible.sync="visible"
      @close="$emit('update:showFieldConfig', false)"
      :close-on-click-modal="false"
    >
      <section class="content_wrap">
        <div class="title">鎷栧姩鍖哄潡璋冩暣鏄剧ず椤哄簭</div>
        <draggable v-model="newData" class="list-groud">
          <transition-group type="transition" :name="'flip-list'">
            <div v-for="item in newData" :key="item.content" class="list-li">
              <el-dropdown :hide-on-click="false" size="medium">
                <el-tag>
                  {{ item.content }}
                </el-tag>
                <el-dropdown-menu
                  slot="dropdown"
                  class="list-dropdown-menu dropArrow"
                >
                  <el-dropdown-item>
                    <label class="dropdown-list-title">瀹藉害:</label>
                    <el-input
                      type="danger"
                      onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                      v-model="item.width"
                      onchange="widthChange"
                      class="dropdown-list-input"
                    ></el-input>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </transition-group>
        </draggable>
      </section>
      <section class="field_wrap">
        <div class="title">閫夋嫨鑷畾涔夋樉绀哄垪</div>
        <el-checkbox-group
          v-model="checkData"
          class="list-groud"
          @change="checkChange"
        >
          <el-checkbox-button
            v-for="item in fieldData"
            :label="item.content"
            :key="item.content"
          ></el-checkbox-button>
        </el-checkbox-group>
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveClcik">淇濆瓨</el-button>
        <el-button type="primary" @click="clearClcik">娓呯┖</el-button>
        <el-button type="danger" @click="cancelForm">鍙栨秷</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import draggable from "vuedraggable";
export default {
  props: ["showFieldConfig"],
  components: { draggable },
  data() {
    return {
      title: "鏂板",
      visible: this.showFieldConfig,
      tags: [],
      checkData: [], //閫変腑鏍忎綅
      fieldData: [], //榛樿鏍忎綅
      newData: [], //閫変腑鍚� 閲嶇粍鏂扮殑鏁扮粍  鐢ㄤ簬宸查€変腑瀹藉害璁剧疆
      code: "",
    };
  },
  watch: {
    showFieldConfig() {
      this.visible = this.showFieldConfig;
      if (this.visible) {
      }
    },
  },
  methods: {
    getReceiptData(queryData, configData, code) {
      this.code = code; //妯″潡鏍囪瘑
      this.fieldData = configData; //榛樿鍏ㄩ儴閰嶇疆鐨勬爮浣�
      this.checkData = [];
      if (queryData.length > 0) {
        //璁剧疆濡傛灉鏈夐€変腑鐨勬爮浣�  鍒欓珮浜寜閽�
        queryData.forEach((item) => {
          if (item.code == this.code) {
            this.newData = JSON.parse(item.content); //閫変腑鍚� 閲嶇粍鏂扮殑鏁扮粍  鐢ㄤ簬鎷栧姩蹇尯鍩熸暟鎹缃�
            if (this.newData.length > 0) {
              JSON.parse(item.content).forEach((item2) => {
                this.checkData.push(item2.content);
              });
            }
          }
        });
      }
      console.log(this.checkData);
    },
    checkChange(val) {
      //閫夋嫨鑷畾涔夋樉绀哄垪閫変腑浜嬩欢
      this.newData = [];
      this.fieldData.forEach((item) => {
        val.forEach((item2) => {
          if (item.content == item2) {
            var data = {};
            data.content = item.content;
            data.width = item.width;
            data.field = item.field;
            this.newData.push(data); //閫変腑鐨勬暟鎹噸缁勬柊鏁扮粍
          }
        });
      });
    },
    saveClcik() {
      //淇濆瓨
      this.$emit("RefreshItem", this.newData);
      this.cancelForm();
    },
    clearClcik() {
      //娓呯┖
      this.newData = [];
      this.checkData = [];
    },
    cancelForm() {
      this.$emit("update:showFieldConfig", false);
    },
  },
};
</script>
<style lang="scss">
.FieldConfigDialog {
  .el-dialog {
    width: 700px !important;
    text-align: left;
    .el-dialog__header {
      background: #fff;
      font-size: 16px;
    }
    .el-dialog__body {
      background: #eff0f0;
      padding: 20px;
    }
    .el-dialog__footer {
      background: #fff;
    }
  }
  .list-groud {
    padding: 24px;
    background: #fff;
  }
  .title {
    padding: 10px 20px;
    color: #353b64;
    font-size: 14px;
    font-family: PingFangSC-Medium;
    font-weight: 500;
  }
  .el-tag {
    margin-left: 10px;
  }
  .el-checkbox-button__inner {
    border-left-color: #409eff;
    border: 1px solid #dcdfe6;
    border-radius: 4px !important;
    margin: 0 10px 10px 0;
    color: #455689;
    background: #e6e8f3;
    border-radius: 4px 4px 4px 4px;
    border: unset;
    font-size: 12px;
    padding: 8px 12px;
    height: unset;
  }
  .flip-list-move {
    transition: transform 0.5s;
  }
  .no-move {
    transition: transform 0s;
  }
  .el-tag {
    cursor: pointer;
    color: rgba(0, 0, 0, 0.65);
    background: #fff;
    border: 1px solid #d9d9d9;
  }
  .list-li {
    display: inline-block;
    margin: 0 0 10px 0;
  }
}
.dropdown-list-title {
  display: inline-block !important;
}
.dropdown-list-input.el-input {
  width: 65px;
}
.el-dropdown-link {
  cursor: pointer;
}
.list-dropdown-menu {
  .el-dropdown-menu__item:not(.is-disabled):hover {
    background: none !important;
    color: rgba(0, 0, 0, 0.65);
  }
}
.el-popper[x-placement^="bottom"].dropArrow .popper__arrow {
  display: inline !important;
} //鏄剧ず绠ご
</style>