<template>
  <div class="diagnosis-list-content">
    <div class="select-content screenSet">
      <div class="title">
        助诊医生列表
      </div>

      <el-collapse-transition>
        <div v-show="isUp">
          <el-form
            ref="form"
            :inline="true"
            :model="searchParam"
            label-suffix=":"
            label-width="120px"
            label-position="right"
            style="width: 100%"
          >
            <el-row
              :gutter="30"
              type="flex"
              style="margin-bottom: 0"
            >
              <el-col :span="12">
                <el-form-item label="助诊医生">
                  <el-input
                    v-model="searchParam.searchKey"
                    size="middle"
                    placeholder="请输入医生姓名或联系电话"
                    style="width: 120%"
                  />
                </el-form-item>
              </el-col>
              <el-col
                :span="10"
                style="margin-left: 45px"
              >
                <el-form-item label="所在机构">
                  <el-input
                    v-model="searchParam.hospitalName"
                    size="middle"
                    placeholder="请输入所在机构名称"
                    style="width: 120%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              :gutter="30"
              type="flex"
              style="margin-bottom: 0"
            >
              <el-col :span="15">
                <el-form-item label="创建时间">
                  <el-date-picker
                    v-model="rangeTime"
                    type="daterange"
                    value-format="yyyy-MM-dd"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    style="width: 100%"
                    :picker-options="pickerOptions1"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item
                  label="分佣方式"
                  style="margin-left: 10px"
                >
                  <el-select
                    id="statusSelector"
                    v-model="searchParam.commissionType"
                    placeholder="请选择分佣方式"
                    clearable
                    style="width: 110%; height: 32px; line-height: 32px"
                  >
                    <el-option
                      v-for="item in commissionTypeList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col
                :span="3"
                style="
                  text-align: center;
                  padding-right: 55px;
                  padding-left: 0px;
                "
              >
                <el-button
                  type="primary"
                  size="small"
                  @click="search()"
                >
                  搜索
                </el-button>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-collapse-transition>

      <div
        class="select-bottom"
        @click="selectToggle"
      >
        <span v-if="!isUp">展开筛选<i class="el-icon-arrow-down" /></span>
        <span v-else>收起筛选<i class="el-icon-arrow-up" /></span>
      </div>
    </div>

    <div
      id="screenSet"
      class="component-content screenSet"
    >
      <el-row
        :gutter="30"
        type="flex"
        style="margin-bottom: 0; float: right"
      >
        <el-col
          :span="5"
          style="text-align: right; margin-bottom: 10px; margin-right: 40px"
        >
          <el-button
            type="primary"
            size="small"
            @click="refresh()"
          >
            刷新页面
          </el-button>
        </el-col>
        <el-col
          :span="5"
          style="text-align: right"
        >
          <el-button
            type="primary"
            size="small"
            @click="add()"
          >
            添加助诊医生
          </el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table
        v-loading="loading"
        class="search-table"
        :data="tableData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="50"
        />
        <el-table-column
          prop="userId"
          label="ID"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="userName"
          label="助诊医生"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="mobile"
          label="手机号"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="address"
          label="地区"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="hospitalName"
          label="所在机构"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="department"
          label="科室"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="title"
          label="职称"
          min-width="100"
          align="left"
        />
        <el-table-column
          prop="audioCommissionTypeStr"
          label="语音分佣规则"
          min-width="120"
          align="left"
        />
        <el-table-column
          prop="audioPrice"
          label="语音分佣"
          min-width="100"
          align="left"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.audioCommissionType == 1"
            >{{ scope.row.audioPrice | priceNum }}%</span>
            <span
              v-if="scope.row.audioCommissionType == 2"
            >{{ scope.row.audioPrice | priceNum }}元</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="videoCommissionTypeStr"
          label="视频分佣规则"
          min-width="120"
          align="left"
        />
        <el-table-column
          prop="videoPrice"
          label="视频分佣"
          min-width="100"
          align="left"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.videoCommissionType == 1"
            >{{ scope.row.videoPrice | priceNum }}%</span>
            <span
              v-if="scope.row.videoCommissionType == 2"
            >{{ scope.row.videoPrice | priceNum }}元</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="imgCommissionTypeStr"
          label="图文分佣规则"
          min-width="120"
          align="left"
        />
        <el-table-column
          prop="imgPrice"
          label="图文分佣"
          min-width="100"
          align="left"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.imgCommissionType == 1"
            >{{ scope.row.imgPrice | priceNum }}%</span>
            <span
              v-if="scope.row.imgCommissionType == 2"
            >{{ scope.row.imgPrice | priceNum }}元</span>
          </template>
        </el-table-column>
        <!--                        <el-table-column prop="price" label="价格(元)" min-width="60" align="left">-->
        <!--                          <template slot-scope="scope">-->
        <!--                            <span>{{scope.row.price | rounding}}</span>-->
        <!--                          </template>-->
        <!--                        </el-table-column>-->
        <!--                        <el-table-column prop="status" label="状态" min-width="80" align="left">-->
        <!--                          <template slot-scope="scope">-->
        <!--                            <span>{{scope.row.status | statusFilter}}</span>-->
        <!--                          </template>-->
        <!--                        </el-table-column>-->
        <el-table-column
          prop="createdTime"
          label="创建时间"
          min-width="160"
          align="left"
        />
        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          min-width="150"
        >
          <template slot-scope="scope">
            <div>
              <el-button
                type="primary"
                size="small"
                style="margin-top: 10px"
                @click="setPrice(scope.row, false)"
              >
                设置分佣
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          background
          :current-page="searchParam.pageNo"
          :page-sizes="[15, 30, 50, 100, 200]"
          :page-size="searchParam.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>

      <el-dialog
        :title="title"
        :visible.sync="setAddVisible"
        width="60%"
      >
        <!--            <el-row :gutter="30" class="row search" type="flex" style="margin-bottom:0;">-->
        <el-form
          ref="setPriceForm"
          :rules="addRules"
          :model="model"
          label-width="250px"
          label-suffix=":"
          label-position="right"
          size="mini"
          style="width: 100%"
        >
          <el-form-item
            label="助诊医生"
            class="required-label"
            prop="userName"
          >
            <el-col :span="15">
              <el-select
                v-model="model.userName"
                filterable
                remote
                placeholder="请输入专家姓名或医院名称,多个关键字用空格隔开，至少输入两个字符"
                clearable
                style="width: 130%"
                :remote-method="remoteMethod"
                :disabled="isEdit"
                @change="nameChange"
                @visible-change="noSelectHand"
              >
                <el-option
                  v-for="item in nameList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <span>{{ item.value }}</span>
                </el-option>
              </el-select>
            </el-col>
          </el-form-item>

          <!--                <el-col :span="15" style="margin-left: 105px;">-->
          <!--                  实际收入（接诊后实际到账金额）: ￥{{tempPrice | rounding}}-->
          <!--                </el-col>-->

          <el-form-item
            label="助诊医生职称"
            class="required-label"
          >
            <el-col :span="15">
              <el-input
                v-model="model.title"
                style="width: 130%"
                disabled
                size="small"
              />
            </el-col>
          </el-form-item>

          <el-form-item
            label="助诊医生所在机构"
            class="required-label"
          >
            <el-col :span="15">
              <el-input
                v-model="model.hospitalName"
                style="width: 130%"
                disabled
                size="small"
              />
            </el-col>
          </el-form-item>

          <el-form-item
            label="助诊医生所在科室"
            class="required-label"
          >
            <el-col :span="15">
              <el-input
                v-model="model.department"
                style="width: 130%"
                disabled
                size="small"
              />
            </el-col>
          </el-form-item>

          <el-form-item
            label="助诊电话"
            class="required-label"
          >
            <el-col :span="15">
              <el-input
                v-model="model.mobile"
                style="width: 130%"
                disabled
                size="small"
              />
            </el-col>
          </el-form-item>

          <el-form-item
            label="语音问诊分佣"
            prop="audioCommissionType"
            class="required-label"
          >
            <el-col :span="16">
              <el-radio-group
                v-model="model.audioCommissionType"
                size="small"
                style="line-height: 45px"
              >
                <div>
                  <el-radio
                    :label="1"
                    style="float: left; margin-top: 5px; line-height: 20px"
                  >
                    按比例分佣（%）
                  </el-radio>
                  <span
                    style="float: right; width: 100px"
                  ><el-input-number
                    v-model="model.audioPrice1"
                    size="small"
                    :precision="2"
                    :min="0"
                  /></span>
                </div>
                <div>
                  <el-radio
                    :label="2"
                    style="float: left; margin-top: 30px; line-height: 20px"
                  >
                    固定分佣金额（元）
                  </el-radio>
                  <span
                    style="float: right; width: 100px"
                  ><el-input-number
                    v-model="model.audioPrice2"
                    size="small"
                    :precision="2"
                    :min="0"
                    :max="9999"
                  /></span>
                </div>
              </el-radio-group>
            </el-col>
          </el-form-item>

          <el-form-item
            label="视频问诊分佣"
            prop="videoCommissionType"
            class="required-label"
          >
            <el-col :span="16">
              <el-radio-group
                v-model="model.videoCommissionType"
                size="small"
                style="line-height: 45px"
              >
                <div>
                  <el-radio
                    :label="1"
                    style="float: left; margin-top: 5px; line-height: 20px"
                  >
                    按比例分佣（%）
                  </el-radio>
                  <span
                    style="float: right; width: 100px"
                  ><el-input-number
                    v-model="model.videoPrice1"
                    size="small"
                    :precision="2"
                    :min="0"
                  /></span>
                </div>
                <div>
                  <el-radio
                    :label="2"
                    style="float: left; margin-top: 30px; line-height: 20px"
                  >
                    固定分佣金额（元）
                  </el-radio>
                  <span
                    style="float: right; width: 100px"
                  ><el-input-number
                    v-model="model.videoPrice2"
                    size="small"
                    :precision="2"
                    :min="0"
                    :max="9999"
                  /></span>
                </div>
              </el-radio-group>
            </el-col>
          </el-form-item>

          <el-form-item
            label="图文问诊分佣"
            prop="imgCommissionType"
            class="required-label"
          >
            <el-col :span="16">
              <el-radio-group
                v-model="model.imgCommissionType"
                size="small"
                style="line-height: 45px"
              >
                <div>
                  <el-radio
                    :label="1"
                    style="float: left; margin-top: 5px; line-height: 20px"
                  >
                    按比例分佣（%）
                  </el-radio>
                  <span
                    style="float: right; width: 100px"
                  ><el-input-number
                    v-model="model.imgPrice1"
                    size="small"
                    :precision="2"
                    :min="0"
                  /></span>
                </div>
                <div>
                  <el-radio
                    :label="2"
                    style="float: left; margin-top: 30px; line-height: 20px"
                  >
                    固定分佣金额（元）
                  </el-radio>
                  <span
                    style="float: right; width: 100px"
                  ><el-input-number
                    v-model="model.imgPrice2"
                    size="small"
                    :precision="2"
                    :min="0"
                    :max="9999"
                  /></span>
                </div>
              </el-radio-group>
            </el-col>
          </el-form-item>
        </el-form>
        <!--            </el-row>-->
        <span
          slot="footer"
          class="dialog-footer"
          style="text-align: center"
        >
          <el-button @click="setAddVisible = false">取 消</el-button>
          <el-button
            type="primary"
            @click="submit"
          >确定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
  import { getServiceType, getDoctorInfoByNameLike, getDownDoctor, saveDownDoctor, getRuleInfo, getProfit } from '@/api/assistList';
  let vm = null;
  export default {
    data() {
      return {
        isUp: false,
        endFlag: false,
        beginFlag: false,
        loading: false,
        setPriceVisible: false,
        rangeTime: '',
        searchParam: {
          searchKey: '',
          hospitalName: '',
          commissionType: 0,
          startTime: '',
          endTime: '',
          pageSize: 15,
          pageNo: 1,
        },
        batchUpdatePriceFlag: false,
        model: {
          name: '',
          userId: '',
          userName: '',
          mobile: '',
          address: '',
          hospitalName: '',
          title: '',
          audioCommissionType: '',
          audioPrice: '',
          audioPrice1: '',
          audioPrice2: '',
          videoCommissionType: '',
          videoPrice: '',
          videoPrice1: '',
          videoPrice2: '',
          imgCommissionType: '',
          imgPrice: '',
          imgPrice1: '',
          imgPrice2: '',
        },
        timeSelect: [],
        diagnosisSelect: [],
        serviceTypeList: [],
        tableData: [],
        totalRows: 0,
        setPriceRules: {},
        liveBack: false,
        timeClickFlag: true,
        multipleSelection: [],
        tempPrice: 0,
        statusList: [
          {
            value: 0,
            label: '全部',
          },
          {
            value: 1,
            label: '下架',
          },
          {
            value: 2,
            label: '上架',
          },
        ],
        profit: 0,
        selectedList: [],
        selectedPriceList: [],
        setAddVisible: false,
        title: '添加助诊医生',
        isEdit: false,
        nameList: [],
        commissionTypeList: [
          {
            value: 0,
            label: '全部',
          },
          {
            value: 1,
            label: '按比例分佣',
          },
          {
            value: 2,
            label: '固定分佣',
          },
        ],
        pickerOptions0: {
          disabledDate: (time) => {
            if (
              this.searchParam.endTimestamp != '' &&
              this.searchParam.endTimestamp != null
            ) {
              return (
                time.getTime() > new Date(this.searchParam.endTimestamp).getTime()
              );
            }
          },
        },
        pickerOptions1: {
          disabledDate: (time) => {
            return time.getTime() > new Date().getTime(); // 减去一天的时间代表可以选择同一天;
          },
        },
        addRules: {
          userName: [
            { required: true, message: '请输入助诊医生', trigger: 'blur' },
          ],
          audioCommissionType: [
            { required: true, message: '请设置语音问诊分佣', trigger: 'blur' },
          ],
          videoCommissionType: [
            { required: true, message: '请设置视频问诊分佣', trigger: 'blur' },
          ],
          imgCommissionType: [
            { required: true, message: '请设置图文问诊分佣', trigger: 'blur' },
          ],
          audioPrice1: [
            { required: true, message: '请设置图文问诊分佣', trigger: 'blur' },
            {
              pattern: /^(\d|[1-9]\d|100)(\.\d{1,2})?$/,
              message: '范围在0-100',
              trigger: 'blur',
            },
          ],
        },
      };
    },
    mounted() {
      vm = this;
      this.getServiceTypeList();
      this.search();
    },
    methods: {
      selectToggle() {
        this.isUp = !this.isUp;
      },
      // 服务名称
      getServiceTypeList() {
        getServiceType().then((res) => {
          if (res.code == '000000') {
            this.serviceTypeList = res.data;
          }
        });
      },

      search() {
        if (this.rangeTime) {
          this.searchParam.startTime = this.rangeTime[0];
          this.searchParam.endTime = this.rangeTime[1];
        } else {
          this.searchParam.startTime = '';
          this.searchParam.endTime = '';
        }
        this.loading = true;
        const params = this.searchParam;
        getDownDoctor(params).then((res) => {
          this.loading = false;
          if (res.code == '000000') {
            this.tableData = res.data.contentList;
            this.totalRows = res.data.total;
          }
        });
      },

      submit() {
        if (
          this.model.audioCommissionType == 1 &&
          this.model.audioPrice1 == undefined
        ) {
          this.$message({
            message: '请输入语音问诊分佣中的按比例分佣',
            type: 'warning',
          });
          return;
        } else if (
          this.model.audioCommissionType == 1 &&
          this.model.audioPrice1 > 100
        ) {
          this.$message({
            message: '请输入语音问诊分佣中的按比例分佣0-100',
            type: 'warning',
          });
          return;
        }
        if (
          this.model.audioCommissionType == 2 &&
          this.model.audioPrice2 == undefined
        ) {
          this.$message({
            message: '请输入语音问诊分佣中的固定分佣金额',
            type: 'warning',
          });
          return;
        }
        if (
          this.model.videoCommissionType == 1 &&
          this.model.videoPrice1 == undefined
        ) {
          this.$message({
            message: '请输入视频问诊分佣中的按比例分佣',
            type: 'warning',
          });
          return;
        } else if (
          this.model.videoCommissionType == 1 &&
          this.model.videoPrice1 > 100
        ) {
          this.$message({
            message: '请输入视频问诊分佣中的按比例分佣0-100',
            type: 'warning',
          });
          return;
        }
        if (
          this.model.videoCommissionType == 2 &&
          this.model.videoPrice2 == undefined
        ) {
          this.$message({
            message: '请输入视频问诊分佣中的固定分佣金额',
            type: 'warning',
          });
          return;
        }
        if (
          this.model.imgCommissionType == 1 &&
          this.model.imgPrice1 == undefined
        ) {
          this.$message({
            message: '请输入图文问诊分佣中的按比例分佣',
            type: 'warning',
          });
          return;
        } else if (
          this.model.imgCommissionType == 1 &&
          this.model.imgPrice1 > 100
        ) {
          this.$message({
            message: '请输入图文问诊分佣中的按比例分佣0-100',
            type: 'warning',
          });
          return;
        }
        if (
          this.model.imgCommissionType == 2 &&
          this.model.imgPrice2 == undefined
        ) {
          this.$message({
            message: '请输入图文问诊分佣中的固定分佣金额',
            type: 'warning',
          });
          return;
        }

        let timeoutId = null;
        timeoutId && clearTimeout(timeoutId);
        timeoutId = setTimeout(() => {
          this.clickHandle();
        }, 500);
      },
      // 防止按钮多次点击
      clickHandle() {
        this.$refs.setPriceForm.validate((valid) => {
          if (valid) {
            vm.loading = true;
            vm.setSubmitPrice();
            saveDownDoctor(vm.model).then(
              (res) => {
                vm.loading = false;
                // closeLoading(this);
                if (res.code == '000000') {
                  vm.$message({
                    message: '设置成功',
                    type: 'success',
                  });
                  vm.setAddVisible = false;
                  vm.search();
                } else {
                  vm.$message({
                    message: res.message,
                    type: 'error',
                  });
                }
              }
            );
          }
        });
      },
      handleSizeChange(value) {
        this.searchParam.pageSize = value;
        this.search();
      },
      handleCurrentChange(value) {
        this.searchParam.pageNo = value;
        this.search();
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      // 刷新页面
      refresh() {
        this.searchParam = {
          searchKey: '',
          hospitalName: '',
          commissionType: 0,
          startTime: '',
          endTime: '',
          pageSize: 15,
          pageNo: 1,
        };
        this.rangeTime = '';
        this.search();
      },
      setSelectedList() {
        if (this.multipleSelection.length > 0) {
          this.selectedList = [];
          for (let i = 0; i < this.multipleSelection.length; i++) {
            this.selectedList.push({
              doctorId: this.multipleSelection[i].doctorId,
              serviceType: this.multipleSelection[i].serviceType,
            });
          }
        }
      },
      setSelectedPriceList() {
        if (this.multipleSelection.length > 0) {
          this.selectedPriceList = [];
          for (let i = 0; i < this.multipleSelection.length; i++) {
            if (
              this.multipleSelection[i].price != 0 &&
              (this.multipleSelection[i].price == '' ||
                this.multipleSelection[i].price == null)
            ) {
              this.$message({
                message: '请先设置"问诊价格"',
                type: 'warning',
              });
              return false;
            }
            this.selectedPriceList.push({
              doctorId: this.multipleSelection[i].doctorId,
              serviceType: this.multipleSelection[i].serviceType,
              price: this.multipleSelection[i].price,
            });
          }
          return true;
        }
      },

      setPrice(row, batchUpdatePriceFlag) {
        if (this.$refs.setPriceForm) {
          this.$refs.setPriceForm.resetFields();
        }
        this.batchUpdatePriceFlag = batchUpdatePriceFlag;
        // this.setPriceVisible = true
        this.setAddVisible = true;
        this.isEdit = true;
        this.title = '设置分佣';
        vm.model.id = row.id;
        vm.model.userId = row.userId;
        vm.model.userName = row.userName;
        vm.model.mobile = row.mobile;
        vm.model.provinceName = row.provinceName;
        vm.model.cityName = row.cityName;
        vm.model.countyName = row.countyName;
        vm.model.townName = row.townName;
        vm.model.hospitalName = row.hospitalName;
        vm.model.department = row.department;
        vm.model.title = row.title;

        vm.model.audioCommissionType = '';
        vm.model.audioPrice = '';
        vm.model.audioPrice1 = undefined;
        vm.model.audioPrice2 = undefined;
        vm.model.videoCommissionType = '';
        vm.model.videoPrice = '';
        vm.model.videoPrice1 = undefined;
        vm.model.videoPrice2 = undefined;
        vm.model.imgCommissionType = '';
        vm.model.imgPrice = '';
        vm.model.imgPrice1 = undefined;
        vm.model.imgPrice2 = undefined;

        vm.model.audioCommissionType = row.audioCommissionType;
        // vm.model.videoCommissionType = row.videoCommissionType;
        // vm.model.imgCommissionType = row.imgCommissionType;
        if (row.audioCommissionType == 1) {
          vm.model.audioPrice1 = vm.priceNum(row.audioPrice);
        } else if (row.audioCommissionType == 2) {
          vm.model.audioPrice2 = vm.priceNum(row.audioPrice);
        }
        vm.model.videoCommissionType = row.videoCommissionType;
        if (row.videoCommissionType == 1) {
          vm.model.videoPrice1 = vm.priceNum(row.videoPrice);
        } else if (row.videoCommissionType == 2) {
          vm.model.videoPrice2 = vm.priceNum(row.videoPrice);
        }
        vm.model.imgCommissionType = row.imgCommissionType;
        if (row.imgCommissionType == 1) {
          vm.model.imgPrice1 = vm.priceNum(row.imgPrice);
        } else if (row.imgCommissionType == 2) {
          vm.model.imgPrice2 = vm.priceNum(row.imgPrice);
        }
      },
      initAdd() {
        getRuleInfo({
          userType: '2',
          defaultFlag: 1,
        }).then((res) => {
          if (res.code == '000000') {
            vm.initData = res.data;

            vm.model.audioCommissionType = res.data.audioCommissionType;
            if (vm.model.audioCommissionType == 1) {
              vm.model.audioPrice1 = vm.priceNum(res.data.audioPrice);
            } else if (vm.model.audioCommissionType == 2) {
              vm.model.audioPrice2 = vm.priceNum(res.data.audioPrice);
            }
            vm.model.videoCommissionType = res.data.videoCommissionType;
            if (vm.model.videoCommissionType == 1) {
              vm.model.videoPrice1 = vm.priceNum(res.data.videoPrice);
            } else if (vm.model.videoCommissionType == 2) {
              vm.model.videoPrice2 = vm.priceNum(res.data.videoPrice);
            }
            vm.model.imgCommissionType = res.data.imgCommissionType;
            if (vm.model.imgCommissionType == 1) {
              vm.model.imgPrice1 = vm.priceNum(res.data.imgPrice);
            } else if (vm.model.imgCommissionType == 2) {
              vm.model.imgPrice2 = vm.priceNum(res.data.imgPrice);
            }
          } else {
            this.$message({
              message: res.message,
              type: 'error',
            });
          }
        });
      },

      getProfit(row) {
        getProfit({
          doctorId: row.doctorId,
          serviceType: row.serviceType,
        }).then((res) => {
          if (res.code == '000000') {
            vm.profit = res.data;
            if (
              vm.setPriceForm.price != 0 &&
              (vm.setPriceForm.price == '' || vm.setPriceForm.price == null)
            ) {
              this.tempPrice = '';
            } else {
              this.tempPrice = this.setPriceForm.price * this.profit;
            }
          } else {
            this.$message({
              message: res.message,
              type: 'error',
            });
          }
        });
      },
      changePrice() {
        if (
          this.setPriceForm.price != 0 &&
          (this.setPriceForm.price == '' || this.setPriceForm.price == undefined)
        ) {
          this.tempPrice = '';
        } else {
          this.tempPrice = this.setPriceForm.price * this.profit;
        }
      },
      add() {
        this.setAddVisible = true;
        this.isEdit = false;
        this.title = '添加助诊医生';
        if (!this.isEdit) {
          vm.model.id = null;
          vm.model.userName = '';
          vm.model.mobile = '';
          vm.model.hospitalName = '';
          vm.model.department = '';
          vm.model.title = '';
          vm.model.userId = '';
          vm.model.audioCommissionType = '';
          vm.model.audioPrice = '';
          vm.model.audioPrice1 = undefined;
          vm.model.audioPrice2 = undefined;
          vm.model.videoCommissionType = '';
          vm.model.videoPrice = '';
          vm.model.videoPrice1 = undefined;
          vm.model.videoPrice2 = undefined;
          vm.model.imgCommissionType = '';
          vm.model.imgPrice = '';
          vm.model.imgPrice1 = undefined;
          vm.model.imgPrice2 = undefined;
          vm.initAdd();
        }
      },
      // 搜索
      remoteMethod(val) {
        if (val.length >= 2) {
          getDoctorInfoByNameLike({ name: val })
            .then(function (res) {
              if (res.code == '000000') {
                const list = res.data;
                vm.expertData = list;
                const newList = [];
                list.map((item, index) => {
                  newList[index] = {
                    value: `${item.name} ${item.mobilePhone} ${item.hospital} ${item.title}`,
                    id: item.doctorId,
                    name: item.name,
                  };
                });
                vm.nameList = newList;
              }
            })
            .catch(function (error) {
              console.log(error);
            });
        } else {
          vm.expertData = [];
          vm.nameList = [];
        }
      },
      nameChange(val) {
        if (val) {
          for (let i = 0; i < vm.expertData.length; i++) {
            if (val == vm.expertData[i].doctorId) {
              const item = vm.expertData[i];
              vm.model.userName = item.name;
              vm.model.mobile = item.mobilePhone;
              vm.model.hospitalName = item.hospital;
              vm.model.department = item.department;
              vm.model.title = item.title;
              vm.model.userId = item.doctorId;
            }
          }
        } else {
          vm.model.userName = '';
          vm.model.mobile = '';
          vm.model.hospitalName = '';
          vm.model.department = '';
          vm.model.title = '';
          vm.model.userId = '';
        }
        vm.nameList = [];
      },
      noSelectHand(val) {
        if (!val && !vm.model.name) {
          vm.nameList = [];
        }
      },
      priceNum(value) {
        if (value != '' && value != null && value != 'null') {
          return (value / 100).toFixed(2);
        } else if (value == 0) {
          return (value / 100).toFixed(2);
        } else {
          return value;
        }
      },
      setSubmitPrice() {
        if (this.model.audioCommissionType == 1 && this.model.audioPrice1 != '') {
          this.model.audioPrice = this.model.audioPrice1;
        } else if (
          this.model.audioCommissionType == 2 &&
          this.model.audioPrice2 != ''
        ) {
          this.model.audioPrice = this.model.audioPrice2;
        }

        if (this.model.videoCommissionType == 1 && this.model.videoPrice1 != '') {
          this.model.videoPrice = this.model.videoPrice1;
        } else if (
          this.model.videoCommissionType == 2 &&
          this.model.videoPrice2 != ''
        ) {
          this.model.videoPrice = this.model.videoPrice2;
        }
        if (this.model.imgCommissionType == 1 && this.model.imgPrice1 != '') {
          this.model.imgPrice = this.model.imgPrice1;
        } else if (
          this.model.imgCommissionType == 2 &&
          this.model.imgPrice2 != ''
        ) {
          this.model.imgPrice = this.model.imgPrice2;
        }

        if (this.model.audioPrice != null) {
          this.model.audioPrice = this.model.audioPrice * 100;
        }
        if (this.model.videoPrice != null) {
          this.model.videoPrice = this.model.videoPrice * 100;
        }
        if (this.model.imgPrice != null) {
          this.model.imgPrice = this.model.imgPrice * 100;
        }
      },
    },
  };
</script>
<style lang="scss" scoped>
.diagnosis-list-content {
  .select-content {
    margin-bottom: 10px;
    padding: 10px;
    background: #fff;
    overflow: hidden !important;
    .title {
      height: 50px;
      display: flex;
      justify-content: flex-start;
      align-items: center;
    }
    .select-bottom {
      height: 50px;
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #0d9078;
    }
  }
  .component-content {
    padding: 10px;
    background: #fff;
    overflow: hidden !important;
    .title {
      margin-bottom: 30px;
    }
  }
}
.required-label {
  .el-form-item__label::before {
    content: "*";
    color: #f56c6c;
    margin-right: 4px;
  }
}
.el-dialog__footer {
  padding: 10px 20px 20px;
  text-align: center;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
</style>
