<template>
  <div class="app-container">
    <el-card  >
      <el-form ref="form" :model="form"  label-width="100px">
        <el-form-item label="接诊开关" >
          <el-switch  v-model="form.status" ></el-switch>
        </el-form-item>
        <el-form-item label="图文价格" >
          <el-input-number v-model="form.price1" :precision="2" :step="0.1" :min="0"></el-input-number>
        </el-form-item>
        <el-form-item label="视频问诊价格" >
          <el-input-number v-model="form.price2" :precision="2" :step="0.1" :min="0"></el-input-number>
        </el-form-item>
      </el-form>
      <div style="display: flex; justify-content: flex-end;">
        <el-button  type="primary" @click="submitForm">确定</el-button>
      </div>
    </el-card>
  </div>
</template>
<script>
import { getDoctorDetails,editDoctor } from "@/api/doctor.js";
export default {
  name: 'Index',
  
  data() {
    return {
       form:{},
    }
  },
  created() {
    this.getDoctorPrice();
  },
  methods: {
    getDoctorPrice(){
      getDoctorDetails().then(response => {
            this.form = response.data;
            this.form.status = this.form.workStatus==0?false:true;
            var data=JSON.parse(this.form.priceJson)
            for(let i in data){
              if(data[i].type==1){
                 this.form.price1=data[i].price;
              }else if(data[i].type==2){
                this.form.price2=data[i].price;
              }
            }
        });
    },
    submitForm(){
      var prices = [
        { price: this.form.price1, type: 1 },
        { price: this.form.price2, type: 2 }
      ];
      var pricesJson = JSON.stringify(prices);
      var form={
        workStatus:this.form.status?1:0,
        priceJson:pricesJson
      }
      editDoctor(form).then(response => {
        this.msgSuccess("修改成功");
        this.getDoctorPrice();
      });
    },
  },
  
}
</script>
 