<template>
  <el-dialog
    class="changeIccicDialog"
    title="修改ICCID"
    :visible.sync="isShow"
    :close-on-click-modal="false"
    width="680px"
  >
    <el-form
      label-position="left"
      label-width="92px"
      ref="formLineInfo"
      :model="formdata"
    >
      <div class="left">
        <el-form-item label="网络类型：" prop="type1">
          <el-select v-model="formdata.type1" placeholder="请选择">
            <el-option
              v-for="item in networkOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="ICCID1：" prop="iccid1">
          <el-input placeholder="请输入iccid1" v-model="formdata.iccid1">
          </el-input>
        </el-form-item>
        <el-form-item label="imsi1：" prop="imsi1">
          <el-input placeholder="请输入imsi1" v-model="formdata.imsi1">
          </el-input>
        </el-form-item>
        <el-form-item label="msisdn1：" prop="msisdn1">
          <el-input placeholder="请输入msisdn1" v-model="formdata.msisdn1">
          </el-input>
        </el-form-item>
        <el-form-item label="sim1：" prop="sim1">
          <el-input placeholder="请输入sim1" v-model="formdata.sim1">
          </el-input>
        </el-form-item>
      </div>
      <div class="right">
        <el-form-item label="网络类型：" prop="type2">
          <el-select v-model="formdata.type2" placeholder="请选择">
            <el-option
              v-for="item in networkOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="ICCID2：" prop="iccid2">
          <el-input placeholder="请输入iccid2" v-model="formdata.iccid2">
          </el-input>
        </el-form-item>
        <el-form-item label="imsi2：" prop="imsi2">
          <el-input placeholder="请输入imsi2" v-model="formdata.imsi2">
          </el-input>
        </el-form-item>
        <el-form-item label="msisdn2：" prop="msisdn2">
          <el-input placeholder="请输入msisdn2" v-model="formdata.msisdn2">
          </el-input>
        </el-form-item>
        <el-form-item label="sim2：" prop="sim2">
          <el-input placeholder="请输入sim2" v-model="formdata.sim2">
          </el-input>
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="isShow = false">取 消</el-button>
      <el-button type="primary" @click="submitForm()">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getSimcardApi, updateSimcardApi } from "@/utils/api/index";

export default {
  props: {},

  data() {
    return {
      isShow: false,
      termInfo: "",
      formdata: {},
      networkOptions: [
        {
          id: -1,
          name: "未绑定",
        },
        {
          id: 1,
          name: "大汉移动",
        },
        {
          id: 2,
          name: "公田移动rabchase",
        },
        {
          id: 3,
          name: "公田m2m10086",
        },
        {
          id: 4,
          name: "安徽",
        },
      ], //网络类型
    };
  },
  computed: {},
  methods: {
    getsimCard() {
      getSimcardApi({
        termId: this.termInfo.id,
      })
        .then((res) => {
          console.log(res);
          if (res.code == 200 && res.data !== null) {
            this.formdata = res.data;
          } else {
            this.formdata = {};
          }
        })
        .catch((err) => {});
    },
    // 保存确定操作
    submitForm() {
      console.log(this.formdata);

      this.$refs.formLineInfo.validate((valid) => {
        if (valid) {
          console.log(this.formdata);

          this.formdata.termId = this.termInfo.id;

          updateSimcardApi(this.formdata)
            .then((res) => {
              console.log(res);
              if (res.code == 200) {
                this.isShow = false;
                this.$message({
                  duration: 1500,
                  showClose: true,
                  message: "修改成功",
                  type: "success",
                });
              } else {
                this.$message({
                  duration: 1500,
                  showClose: true,
                  message: res.msg,
                  type: "error",
                });
              }
            })
            .catch((err) => {});
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    display(val) {
      console.log(val);
      this.termInfo = val;
      this.isShow = true;
      this.getsimCard();
    },
    hide() {
      this.isShow = false;
      this.formdata = {};
    },
  },
};
</script>
<style lang="less">
.changeIccicDialog {
  .el-form {
    display: flex;
    justify-content: space-between;
  }
  .el-select {
    width: 100%;
  }
}
</style>
