<template>
  <el-dialog
    title="修改专属导购"
    :visible.sync="dialogVisible"
    width="600px"
    @open="beforeOpen"
    @close="afterClose">
    <el-form :model="form" ref="form" label-width="130px">
      <el-form-item label="专属导购" prop="mainClerkId" :rules="[
        { required: true, message: '请选择专属导购', trigger: 'blur' }  
      ]">
        <el-select v-model="form.mainClerkId">
          <el-option v-for="item in clerkOptions" :key="item.clerkId" :label="item.clerkName" :value="item.clerkId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="原因备注">
        <gic-textarea v-model="form.remark" :max="50"></gic-textarea>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取消</el-button>
      <el-button type="primary" @click="confirmModify">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { doFetch, doFetchqs } from "../../components/axios/api";
import url from "../../components/axios/url";

export default {
  name: 'ModifyGuide',
  data() {
    return {
      form: {
        mainClerkId: '',
        remark: ''
      },
      clerkOptions: []
    }
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    memberId: [String, Number],
    mainStoreId: [String, Number]
  },
  methods: {
    beforeOpen() {
      this.axios.get(url.getClerkList, { params: { storeId: this.mainStoreId, requestProject: 'member' } }).then(res => {
        const { errorCode, message, result = [] } = res.data || {};
        if(errorCode != 0) return this.$message.error(message);
        this.clerkOptions = result;
      })
    },
    afterClose() {
      this.$refs.form.resetFields();
      this.closeDialog();
      this.form = {
        mainClerkId: '',
        remark: ''
      }
    },
    closeDialog() {
      this.$emit('getList');
      this.$emit('update:dialogVisible', false);
    },
    confirmModify() {
      this.$refs.form.validate(valid => {
        if(!valid) return;
        const { mainClerkId, remark } = this.form;
        let params = {
          memberId: this.memberId,
          mainClerkId,
          remark
        }
        doFetch(url.modifyClerk, params).then(res => {
          const { errorCode, message, result = [] } = res.data || {};
          if(errorCode != 0) return this.$message.error(message);
          this.$message.success('更改成功');
          this.closeDialog();
        })
      })
    },
  }
}
</script>
<style lang="scss" scoped>

</style>