<template>
  <section class="p_all_20">
   
    <div class="container0">
          <div class="upper-box">
            <div class="left-box">
              <img :src="QRcode" v-if="QRcode">
              <p class="firstLine">微信扫一扫</p>
              <p class="secLine">立即绑定</p>
            </div>
            <div class="right-box">
              <h3>订阅服务通知流程：</h3>
              <p>
                左侧是带有您的系统账号参数的二维码，通过微信扫描二维码，页面跳转至E淘家居公众号界面，关注公众号后自动绑定该供货商的账号，即可在公众号
                接受交易订单消息。
              </p>
              <img src="../../../assets/img/step.png" alt>
            </div>
          </div>
          <div class="bottom-box">
            <div class="tit">当前已绑定账号列表</div>
            <el-table :data="tableData" style="width: 100%" border>
              <el-table-column type="index" :index="indexMethod" align="center"></el-table-column>
              <el-table-column prop="wxIco" label="微信头像" width="150" align="center">
                <template slot-scope="scope">
                  <image-alert showDefaultImg :image="scope.row.wxIco"></image-alert>
                </template>
              </el-table-column>
              <el-table-column prop="wxNick" label="微信昵称" width="120" align="center"></el-table-column>
              <el-table-column prop="bindTime" label="日期" width="150" align="center"></el-table-column>
              <el-table-column prop="infoRemark" label="用户信息备注" width="300" header-align="center" align="center">
                <template slot-scope="scope" align="right">
                  <div class="root">
                    <ul>
                      <li>{{scope.row.name}}</li>
                      <li>{{scope.row.phone}}</li>
                      <li>{{scope.row.infoRemark}}</li>
                    </ul>
                    <el-button
                    class="edit-btn"
                      type="primary"
                      icon="el-icon-edit"
                      @click="handleEdit(scope.$index,scope.row)"
                      circle
                    ></el-button>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="csSetting" label="消息抄送" align="center">
                <template slot-scope="scope">
                  <el-switch
                    v-model="scope.row.csSetting"
                    :active-value="1"
                    :inactive-value="0"
                    @change="onEditStute(scope.$index,scope.row)"
                    active-color="#13ce66"
                  ></el-switch>
                </template>
              </el-table-column>
              <el-table-column prop label="操作" align="center" width="120">
                <template slot-scope="scope">
                  <div>
                    <el-button
                
                    type="danger"
                    @click="onRemoveBind(scope.$index,scope.row)"
                  >解除绑定</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
    </div>
    <el-dialog title="用户信息" :visible.sync="dialogFormVisible">
      <div class="user-info-box">
        <div class="userLine">
          <span>名字：</span>
          <el-input class="info" v-model="form.name" placeholder="请输入内容"></el-input>
        </div>
        <div class="userLine">
          <span>电话：</span>
          <el-input class="info" v-model="form.phone" placeholder="请输入内容"></el-input>
        </div>
        <div class="userLine">
          <span>地址：</span>
          <el-input class="info" v-model="form.address" placeholder="请输入内容"></el-input>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="onEditUserinfo">确定</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import imageAlert from "@/components/common/imageAlert";
// import smsManagement from '@/components/page/person/msn/ETaoSMSManagement'
export default {
  name: "msnEtao",
  data() {
    return {
      QRcode: "",
      dialogFormVisible: false,
      tableData: [],
      form: {
        name: "",
        phone: "",
        address: ""
      }
    };
  },

  components: {
    imageAlert,
    // smsManagement
  },
  mounted() {
    this.getTableData();
  },
  methods: {
    onRemoveBind(index, row) {
      var userId = row.userId;
      this.$confirm("确定解除绑定?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$axios
          .post("/wechat/etao/remove", {
            userId
          })
          .then(res => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: res.data.message
              });
            } else {
              this.$message.error(res.data.message);
            }
          })
      }).catch(() => {});
    },
    onEditStute(index, row) {
      var status = row.csSetting;
      var userId = row.userId;
      this.$axios
        .post("/wechat/etao/message", {
          status,
          userId
        })
        .then(res => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: res.data.message
            });
          } else {
            this.tableData[index]['csSetting']=status==1?0:1;
            this.$message.error(res.data.message);
          }
        })
        .catch(() => {});
    },
    onEditUserinfo() {
      this.$axios
        .post("/wechat/etao/modify", this.form)
        .then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.getTableData();
            this.$message({
              message: res.data.message,
              type: "success"
            });
          } else {
            this.$message.error(res.data.message);
          }
        });
    },
    getTableData() {
      this.$axios.get("/wechat/etao/info").then(res => {
        if (res.data.code == 200) {
          var data = res.data.data;
          this.tableData = data.wxInfo;
          this.QRcode = data.qrCode;
        }
      });
    },
    handleClick(tab, event) {
    },
    indexMethod(index) {
      return index + 1;
    },
    handleEdit(index, row) {
      this.dialogFormVisible = true;
      // this.form=row;
      this.form.name = row.name;
      this.form.phone = row.phone;
      this.form.address = row.infoRemark;
      this.form.userId = row.userId;
    }
  }
};
</script>

<style lang="scss" scoped>

  .container0 {
    // width: 1010px;
    .upper-box {
      display: flex;
      border-bottom: 1px solid #f3f3f3;
      justify-content: start;
      padding: 15px;
      .left-box {
        width: 162px;
        // height: 470px;
        background-image: url("../../../assets/img/bg_mobile.png");
        background-repeat: no-repeat;
        background-position: right center;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        // margin-left: 100px;
        img {
          width: 100px;
          height: 100px;
        }
        .firstLine {
          box-sizing: border-box;
          padding: 30px 0 10px 0;
        }
      }
      .right-box {
        box-sizing: border-box;
        margin-left: 30px;
        // padding: 80px 0 0 50px;
        h3 {
          margin-bottom: 10px;
        }
        p {
          width: 620px;
          line-height: 30px;
          margin-bottom: 60px;
        }
        img {
          width: 620px;
          height: 178px;
        }
      }
    }
    .bottom-box {
      margin: 10px 0 0 10px;
      text-align: center;
      .tit {
        text-align: left;
        padding: 15px;
      }
      .root {
        ul {
          display: inline-block;
          vertical-align: middle;
        }
        .edit-btn{
          display: none;
        }
        &:hover .edit-btn{
          display: inline-block;
        }
      }
    }
  }
  .user-info-box {
    .userLine {
      box-sizing: border-box;
      padding-bottom: 30px;
      .info {
        width: 90%;
      }
    }
  }

</style>
