<template>
  <div>
    <el-button style="width:100%;display:block" size="mini" :type="type=='detail' ? '' :'text'" @click="editBtn">变 更</el-button>
    <el-dialog title="新 增" append-to-body :visible.sync="dialogFormVisible" width="30%">
      <div slot="title" style="font-size: 15px">
        状态变更
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="90px" label-position="left" size="mini">
          <el-col :span="24">
            <el-form-item label="数据状态" prop="datastatus">
              <el-select v-model="form.datastatus" placeholder="请选择数据状态" size="small">
                <el-option
                  v-for="item in datastatus"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="交易状态" prop="tradingstatus">
              <el-select v-model="form.tradingstatus" placeholder="请选择交易状态" size="small">
                <el-option
                  v-for="item in tradingstatus"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="客户状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择客户状态" size="small">
                <el-option
                  v-for="item in status"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  data(){
    return {
      datastatus:[
        {label:'正常',value:0},
        {label:'作废',value:1},
        {label:'锁定',value:2}
      ],
      tradingstatus:[
        {label:'未成交',value:0},
        {label:'已成交',value:1},
        {label:'多次成交',value:2}
      ],
      status:[
        {label:'潜在',value:0},
        {label:'合作中',value:1},
        {label:'已终止',value:2}
      ],
      dialogFormVisible:false,
      form:{
        datastatus:'',
        tradingstatus:'',
        status:''
      },
      rules:{
        datastatus:[
          { required: true, message: '请选择数据状态', trigger: 'blur'},
        ],
        tradingstatus:[
          { required: true, message: '请选择交易状态', trigger: 'blur'},
        ],
        status:[
          { required: true, message: '请选择客户状态', trigger: 'blur'},
        ],

      }
    }
  },
  props:['data','type'],
  methods:{
    editBtn () {
      this.dialogFormVisible = true
      this.form = Object.assign({},this.form,this.data)
    },
    onSubmit(){      
      this.$refs['form'].validate(async(valid) => {
        if (!valid) return false
        let res1,res2,res3
        res1 = await this.$api.requested({
          "id": 20221010164402,
          "content": {
              "sa_customersids": [
                this.data.sa_customersid
              ],
              "datastatus": this.form.datastatus
          },
        })
        res3 = await this.$api.requested({
          "id": 20221010164502,
          "content": {
              "sa_customersids": [
                this.data.sa_customersid
              ],
              "tradingstatus": this.form.tradingstatus
          },
        })
        res2 = await this.$api.requested({
          "id": 20221010164602,
          "content": {
              "sa_customersids": [
                this.data.sa_customersid
              ],
              "status": this.form.status
          },
        })
        this.tool.showMessage(res2 || res1 || res3,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    },
    // datastatusFun () {
    //   return new Promise(async (res,rej) => {
    //     let res = await this.$api.requested({
    //       "id": "20221010164302",
    //       "version":1,
    //       "content": {
    //         sa_customersids:[this.data.sa_customersids]
    //       },
    //       datastatus:this.form.datastatus
    //     })
    //     console.log(res);
        
    //   })
    // }
  }
}
</script>

<style scoped>
  /deep/.el-select,.el-cascader  {
    width: 100% !important;
  }
</style>