<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属区域" prop="areaArr">
        <el-cascader 
          v-model="queryParams.areaArr" :show-all-levels="false" :filterable="true"
          :options="treeOptions" :props="treeProps" collapse-tags
          @change="handleTreeChange"></el-cascader>
      </el-form-item>
      <el-form-item label="所属食堂" prop="canteenId">
        <el-select v-model="queryParams.canteenId" placeholder="请选择所属食堂" style="width: 100%;">
            <el-option v-for="item in canteenOptions"
                :key="item.canteenId"
                :label="item.canteenName"
                :value="item.canteenId"
            ></el-option>
        </el-select> 
      </el-form-item> 
      <el-form-item label="档口名称" prop="stallName">
        <el-input 
          v-model="queryParams.stallName"
          placeholder="请输入档口名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> 
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col> 
       
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableListData" height="800">
      <el-table-column label="档口编号" align="center" prop="stallNum" :show-overflow-tooltip="true" width="100" fixed="left"/>
      <el-table-column label="档口名称" align="center" prop="stallName" :show-overflow-tooltip="true" width="150" fixed="left"/>
      <el-table-column label="所属区域" align="center" prop="areaName" :show-overflow-tooltip="true" width="160"/>
      <el-table-column label="所属食堂" align="center" prop="canteenName" :show-overflow-tooltip="true" width="160"/>
      <el-table-column label="负责人" align="center" prop="custName" :show-overflow-tooltip="true" width="80"/>
      <el-table-column label="联系电话" align="center" prop="contactTel" :show-overflow-tooltip="true" width="100"/>
      <el-table-column label="档口标签" align="center" prop="labelNameStr" :show-overflow-tooltip="true" width="80"/>
      <el-table-column label="档口状态" align="center" prop="businessState" :show-overflow-tooltip="true" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.businessState==1">休息</span>
          <span v-if="scope.row.businessState==2">营业</span>
        </template> 
      </el-table-column>
      <el-table-column label="品类" align="center" prop="kindNameStr" :show-overflow-tooltip="true" width="80"/>
      <el-table-column label="营业时间" align="center" prop="startBusinessTime" :show-overflow-tooltip="true" width="180">
        <template slot-scope="scope">
          {{ scope.row.startBusinessTime }}-{{ scope.row.endBusinessTime }}
        </template> 
      </el-table-column> 
      <el-table-column label="预订餐" align="center" prop="ifReserve" :show-overflow-tooltip="true" width="140">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.ifReserve"
            active-text="开启"
            inactive-text="关闭"
            :active-value="1"
            :inactive-value="2"
            @change="changeIfReserve(scope.row)"
            >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="报餐" align="center" prop="ifBook" :show-overflow-tooltip="true" width="140">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.ifBook"
            active-text="开启"
            inactive-text="关闭"
            :active-value="1"
            :inactive-value="2"
            >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="叫号" align="center" prop="ifUseCallNum" :show-overflow-tooltip="true" width="140">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.ifUseCallNum"
            active-text="开启"
            inactive-text="关闭"
            :active-value="1"
            :inactive-value="2"
            >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="线上流水号前缀" align="center" prop="onLineMealCodePrefix" :show-overflow-tooltip="true" width="120"/>
      <el-table-column label="线下流水号前缀" align="center" prop="offLineMealCodePrefix" :show-overflow-tooltip="true" width="120"/>
      <el-table-column label="档口图片" align="center" prop="imgUrl" :show-overflow-tooltip="true" width="100">
        <template slot-scope="scope">
          <img :src="scope.row.imgUrl" alt="" style="width: 80px;height: 40px;" @click="openImg(scope.row)">
        </template>
      </el-table-column>
      <el-table-column label="配送设置" align="center" prop="stallName" :show-overflow-tooltip="true" width="80">
        <template slot-scope="scope">
          <span style="color: #4b80fd;">详情</span>
        </template>
      </el-table-column>
      <el-table-column label="预订/点餐/报餐设置" align="center" prop="" :show-overflow-tooltip="true" width="140">
        <template slot-scope="scope">
          <span style="color: #4b80fd;">详情</span>
        </template>
      </el-table-column>
      <el-table-column label="收款码" align="center" prop="payCodeUrl" :show-overflow-tooltip="true" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.payCodeUrl">未开启</span>
          <span v-else>未开启</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="crtime" :show-overflow-tooltip="true" width="160"/>
      <el-table-column label="更新时间" align="center" prop="uptime" :show-overflow-tooltip="true" width="160"/>
      <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text" 
            @click="handleRest(scope.row)" 
          >休息</el-button>
          <el-button
            size="mini"
            type="text" 
            @click="handleUpdate(scope.row)" 
          >编辑</el-button>
          <el-button
            size="mini"
            type="text" 
            @click="handleDelete(scope.row)" 
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title+'-档口'" :visible.sync="open" width="1000px" append-to-body>
      <el-tabs v-model="activeName" @tab-click="handleTabClick">
        <!-- 基础设置 -->
        <el-tab-pane label="基础设置" name="baseSetting" style="height: 550px;">
          <el-form ref="baseForm" :model="baseForm" :rules="baseFormRules" label-width="80px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="档口编号" prop="stallNum">
                  <el-input  v-model="baseForm.stallNum" placeholder="请输入档口编号" maxlength="30" disabled clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="档口名称" prop="stallName">
                  <el-input  v-model="baseForm.stallName" placeholder="请输入档口名称" maxlength="30" clearable/>
                </el-form-item> 
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="所属区域" prop="areaId">
                  <el-cascader v-model="areaId"
                    :options="treeOptions" :filterable="true" style="width: 400px;" :show-all-levels="false"
                    :props="{ 
                      emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                      checkStrictly: true,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                      value:'id',label:'treeName'
                    }"
                    clearable @change="handleTreeChange2" >
                  </el-cascader>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="所属食堂" prop="canteenId">
                  <el-select v-model="baseForm.canteenId" placeholder="请选择所属食堂" style="width: 100%;" @change="chosenCanteen">
                      <el-option v-for="item in canteenOptions2"
                          :key="item.canteenId"
                          :label="item.canteenName"
                          :value="item.canteenId"
                      ></el-option>
                  </el-select> 
                </el-form-item>
              </el-col> 
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="负责人" prop="labelName"> 
                  <el-select v-model="baseForm.labelName" placeholder="请选择负责人" style="width: 100%;" @focus="chosenCharger"></el-select> 
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系电话" prop="contactTel">
                    <el-input v-model="baseForm.contactTel" placeholder="请输入联系电话" maxlength="11" clearable 
                              @input="(v)=>(baseForm.contactTel=v.replace(/[^\d]/g,''))"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="营业时间">
                  <el-time-picker
                    is-range
                    v-model="rangeTime"
                    value-format="HH:mm:ss"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    placeholder="选择时间范围">
                  </el-time-picker>
                </el-form-item> 
              </el-col>
              <el-col :span="12">
                <el-form-item label="档口标签" prop="labelId"> 
                  <el-select v-model="baseForm.labelId" placeholder="请选择档口标签" style="width: 100%;">
                      <el-option v-for="item in labelOptions"
                          :key="item.labelId"
                          :label="item.labelName"
                          :value="item.labelId" 
                      ></el-option>
                  </el-select> 
                </el-form-item>
              </el-col> 
            </el-row>
            <el-row> 
              <el-col :span="12">
                <el-form-item label="档口品类" prop="kindId"> 
                  <el-select v-model="baseForm.kindId" placeholder="请选择档口品类" style="width: 100%;">
                      <el-option v-for="item in kindOptions"
                          :key="item.kindId"
                          :label="item.kindName"
                          :value="item.kindId" 
                      ></el-option>
                  </el-select> 
                </el-form-item>
              </el-col> 
              <el-col :span="12">
                <el-form-item label="线上流水号前缀" prop="onLineMealCodePrefix"> 
                  <el-input v-model="baseForm.onLineMealCodePrefix" placeholder="请输入线上流水号前缀" maxlength="20" clearable/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row> 
              <el-col :span="12">
                <el-form-item label="线下流水号前缀" prop="offLineMealCodePrefix"> 
                  <el-input v-model="baseForm.offLineMealCodePrefix" placeholder="请输入线下流水号前缀" maxlength="20" clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="是否启用叫号" prop="ifUseCallNum">
                  <el-switch
                    v-model="baseForm.ifUseCallNum"
                    active-text="开启"
                    inactive-text="关闭"
                    :active-value="1"
                    :inactive-value="2">
                  </el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            
            <el-row>
              <el-col :span="12">
                <el-form-item label="是否开启预订餐" prop="ifReserve">
                  <el-switch
                    v-model="baseForm.ifReserve"
                    active-text="开启"
                    inactive-text="关闭"
                    :active-value="1"
                    :inactive-value="2">
                  </el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="是否开启报餐" prop="ifBook">
                  <el-switch
                    v-model="baseForm.ifBook"
                    active-text="开启"
                    inactive-text="关闭"
                    :active-value="1"
                    :inactive-value="2">
                  </el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="是否开启收款码" prop="ifEnablePayCode">
                  <el-switch
                    v-model="baseForm.ifEnablePayCode"
                    active-text="开启"
                    inactive-text="关闭"
                    :active-value="1"
                    :inactive-value="2">
                  </el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="档口图片">
                  <el-upload
                        :http-request="
                            (obj) => imgUpLoad(obj, 'fileUrl')
                        "
                        action="#"
                        :limit="1"
                        :file-list="fileList"
                        :show-file-list="true"
                        list-type="picture-card"
                        accept=".png, .jpg, .jpeg"
                        :on-success="handleAvatarSuccess"
                        :class="{ disabled: uploadDisabled }"
                        :on-preview="handlePictureCardPreview"
                        :on-remove="handleRemove"
                    >
                        <i
                            class="el-icon-plus avatar-uploader-icon"
                        ></i>
                    </el-upload>
                </el-form-item>
              </el-col>
            </el-row> 
         
          </el-form>
        </el-tab-pane> 
        <!-- 配送设置 -->
        <el-tab-pane label="配送设置" name="deliverySetting">
          配送设置 
        </el-tab-pane>
        <!-- 预订/点餐/报餐设置 -->
        <el-tab-pane label="预订/点餐/报餐设置" name="orderSetting"> 
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog title="选择负责人" :visible.sync="openJob" width="800px" append-to-body>
      <el-form :model="dialogQueryParams" ref="dialogQueryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="" prop="keyWord">
          <el-input v-model="dialogQueryParams.keyWord" placeholder="请输入姓名，编号，手机号" clearable style="width: 240px"/>
        </el-form-item>
        <el-form-item label="" prop="stallName">
          <el-select v-model="baseForm.labelName" placeholder="请选择职位" style="width: 100%;">
              <el-option v-for="item in jobOptions"
                  :key="item.jobId"
                  :label="item.jobName"
                  :value="item.jobId" 
              ></el-option>
          </el-select> 
        </el-form-item> 
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDialogQuery">搜索</el-button> 
        </el-form-item>
      </el-form>
      <el-table :data="jobTableData" height="500">
        <el-table-column label="负责人姓名" align="center" prop="custName" :show-overflow-tooltip="true"/>
        <el-table-column label="负责人编号" align="center" prop="custNum" :show-overflow-tooltip="true"/>
        <el-table-column label="负责人手机号" align="center" prop="mobile" :show-overflow-tooltip="true"/>
        <el-table-column label="职位" align="center" prop="job" :show-overflow-tooltip="true"/>
        <el-table-column label="所属组织" align="center" prop="orgFullName" :show-overflow-tooltip="true"/>
      </el-table> 
      <pagination
        v-show="dialogTotal>0"
        :total="dialogTotal"
        :page.sync="dialogQueryParams.pageNum"
        :limit.sync="dialogQueryParams.pageSize"
        @pagination="queryCustJobPage"
      />

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="">确 定</el-button>
        <el-button @click="">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>





  </div>
</template>

<script>
import { systemAreaTreeApi } from "@/api/base/area";
import { getCanteenByAreaApi, getPageStallApi, getStallNumApi, addStallApi, getStallInfoModifyApi, updateStallApi, removeStallApi } from "@/api/base/stall";
import { getLabelListApi, getKindListApi, queryAllCustJobApi, queryCustJobPageApi, getMealtimeListApi,changeIfReserveApi,changeBusinessStateApi } from "@/api/base/stall";
import { imgUpLoadTwo } from '@/api/system/upload'
// import C from "highlight.js/lib/languages/1c";
export default {
  name: "",
  dicts: [],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      tableListData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      treeOptions:[],//区域树
      treeProps:{
        multiple: true,
        value:"id",
        label:"treeName",
        children:"children",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stallName: undefined,
        canteenId: undefined,
        areaIdList: [],
        areaArr: []
      },
      canteenOptions:[],//查询-食堂下拉选
      activeName:"baseSetting",
      areaId:"",
      stallId:"",//档口数据-编辑
      stallData:{},//档口数据-编辑
      baseForm: {
        "effIds": "", 
        "extendMap": {},
        "mainProject": null,
        "offLineMealCodePrefix": null,
        "onLineMealCodePrefix": null,
        "payCodeUrl": null,
        "areaId": "",
        "canteenId": "420840523025092608",  
        "stallName": "",
        "stallNum": "", 
        "contactTel": "",
        "custId": "379497835516661760",
        "endBusinessTime": "",
        "startBusinessTime": "",
        "ifBook": 2,
        "ifEnablePayCode": 2,
        "ifReserve": 2,
        "ifUseCallNum": 2, 
        "imgUrl": "http://sgwpdm.ah.sgcc.com.cn/stall/lnyst/378915229716713472/dishes/076073649b5c4f33a7a15d8a363c006d.jpg",
        "kindNameList": [],
        "labelNameList": []
      },//基础设置
      rangeTime:["08:00:00", "18:00:00"],//营业时间
      canteenOptions2:[],//弹窗食堂下拉选
      // 表单校验
      baseFormRules: {
        stallName: [
          { required: true, message: "档口名称不能为空", trigger: "blur" }
        ],
        areaId: [
          { required: true, message: "所属区域不能为空", trigger: "blur" }
        ],
        canteenId: [
          { required: true, message: "所属食堂不能为空", trigger: "blur" }
        ]
      },
      labelOptions:[],//标签下拉
      kindOptions:[],//品类下拉
      //选择负责人弹窗
      openJob: false,
      jobOptions:[],//职位标签下拉
      dialogQueryParams:{//负责人查询条件
        pageNum: 1,
        pageSize: 10, 
      },
      jobTableData:[],//负责人弹窗
      // 总条数
      dialogTotal: 0,  
      fileList: [],//档口图片
      checkUrlList: [],//档口图片
      checkUrlNameList: [],//档口图片
      dialogVisible:false,//图片弹窗
      dialogImageUrl:"",//图片弹窗

      deliveryModel:{},//配送设置 
      orderDTO:{},//订单设置
      mealtimeList:[],//餐次列表

    };
  },
  created() {
    this.getTreeData();
    this.getList();
    this.getLabel()
    this.getKind()
    this.queryAllCustJob()
    
  },
  computed: {
      //图片上传1张后，隐藏上传框
      uploadDisabled() {
          return this.checkUrlList.length > 0
      },
  },
  methods: {
      //区域树
      getTreeData() {
        systemAreaTreeApi({}).then((response) => {
          this.treeOptions = response;
          console.log(this.treeOptions) 
        });
      },
      handleTreeChange(e){
        console.log(e)
        let arr=[]
        e.forEach(item=>{
          arr.push(item[item.length - 1])
        }) 
        let param= {
          areaIdList:arr
        }
        this.queryParams.areaIdList=arr;
        getCanteenByAreaApi(param).then((response) => {
          this.canteenOptions=response||[]
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
          this.queryParams = {
            pageNum: 1,
            pageSize: 10,
            stallName: undefined,
            canteenId: undefined,
            areaIdList: [],
            areaArr: []
          }
          this.resetForm("queryForm");
          this.handleQuery();
      },
      /** 查询列表 */
      getList() {
          this.loading = true;
          let param = {
            "current": this.queryParams.pageNum, 
            "size": this.queryParams.pageSize,
            "stallName": this.queryParams.stallName,
            "canteenId": this.queryParams.canteenId,
            "areaIdList": this.queryParams.areaIdList
          }
          getPageStallApi(param).then(response => {
              this.tableListData = response.records;
              this.total = Number(response.total);
              this.loading = false;
          });
      },

      //修改档口是否支持预订餐
      changeIfReserve(row){ 
        let param = {
          "canteenId": row.canteenId,
          "stallId": row.stallId,
          "ifReserve": row.ifReserve
        }
        changeIfReserveApi(param).then((response) => {
           this.getList()
        }); 
      },




      handleTabClick(tab, event) {
        console.log(tab, event);
      },
      /** 新增按钮操作 */
      handleAdd() {
          this.stallId=""
          this.reset();
          this.getMealtimeList()
          this.open = true;
          this.title = "新增";
      },
      // 取消按钮
      cancel() {
          this.open = false;
          this.reset();
      },
      // 表单重置
      reset() {
          this.baseForm = {};
          this.rangeTime=["08:00:00", "18:00:00"]
          this.resetForm("baseForm");
      }, 
      /** 修改按钮操作 */
      handleUpdate(row) {
        console.log(row)
          this.reset(); 
          getStallInfoModifyApi({"stallId":row.stallId}).then(response => { 
              console.log(response)
              this.stallId = response.stallId;
              this.baseForm = response.stallSaveDTO;
              this.areaId = this.baseForm.areaId
              let arr=[this.baseForm.areaId] 
              // 选择区域后获取相应食堂
              getCanteenByAreaApi({ areaIdList:arr }).then((response) => {
                this.canteenOptions2=response||[] 
                this.$forceUpdate()
              }); 
              this.deliveryModel = response.deliveryModel;
              this.orderDTO = response.orderDTO; 
              this.mealtimeList = response.mealtimeList;
              this.open = true;
              this.title = "修改";
          });
      },
      /** 删除按钮操作 */
      handleDelete(row) { 
          this.$modal.confirm('是否确认删除数据项？').then(function() {
              return removeStallApi({"stallId":row.stallId});
          }).then(() => {
              this.getList();
              this.$modal.msgSuccess("删除成功");
          }).catch(() => {});
      },
      /** 休息按钮操作 */
      handleRest(row) { 
          let param = {
            "businessState": 1,
            "canteenTreeType": 2,
            "modifyId": row.stallId
          }
          this.$modal.confirm('是否确认休息？').then(function() {
              return changeBusinessStateApi(param);
          }).then(() => {
              this.getList();
              this.$modal.msgSuccess("操作成功");
          }).catch(() => {});
      },
      /** 提交按钮 */
      submitForm: function() {
          console.log(this.baseForm)
          console.log(this.rangeTime)
          this.$refs["baseForm"].validate(valid => {//基本设置表单校验
          if (valid) {
            this.baseForm.startBusinessTime=this.rangeTime[0]
            this.baseForm.endBusinessTime=this.rangeTime[1]
            let param ={
              "stallSaveDTO": this.baseForm,
              "deliveryModel": {//配送设置
                "deliveries": "",
                "deliveryList": [
                    {
                      "deliveryEndTime": "23:59:59",
                      "deliveryStartTime": "00:00:00",
                      "deliveryType": 2
                    },
                    {
                      "deliveryEndTime": "23:59:59",
                      "deliveryStartTime": "00:00:00",
                      "deliveryType": 3
                    },
                    {
                      "deliveryEndTime": "23:59:59",
                      "deliveryStartTime": "00:00:00",
                      "deliveryType": 4
                    },
                    {
                      "deliveryEndTime": "23:59:59",
                      "deliveryStartTime": "00:00:00",
                      "deliveryType": 5
                    },
                    {
                      "deliveryEndTime": "23:59:59",
                      "deliveryStartTime": "00:00:00",
                      "deliveryType": 6
                    }
                ],
                "ifEnableDelivery": "2",
                "minDeliveryFeeOnOff": 1
              },
              "orderDTO": {//订单设置
                "bookEndTime": "",
                "bookRefundEndTime": "",
                "cancelBookFeeRatio": "",
                "dayBeforeCancelBookChargeTime": "",
                "ifAllowReserveToday": "1",
                "ifBookSkipHoliday": "",
                "ifEnableOrder": 2,
                "ifReserveSkipHoliday": "1",
                "nearDinnerCancelBookChargeHour": "2",
                "reportMealLimitDay": 0,
                "reserveEndTime": "",
                "reserveLimitDay": 0,
                "reserveRefundEndTime": ""
              },
              "mealtimeList":this.mealtimeList
            } 
            if (this.stallId != "") {
              param.stallId = this.stallId
              updateStallApi(param).then(response => {
                    this.$modal.msgSuccess("修改成功");
                    this.open = false;
                    this.getList();
                });
            } else {
                addStallApi(param).then(response => {
                    this.$modal.msgSuccess("新增成功");
                    this.open = false;
                    this.getList();
                });
            }
          }
          });
      },
      
      //基础设置-选择区域
      handleTreeChange2(val){ 
        setTimeout(()=>{  
            let arr=[val]
            let param= { areaIdList:arr }
            // 选择区域后获取相应食堂
            getCanteenByAreaApi(param).then((response) => {
              this.canteenOptions2=response||[] 
                this.baseForm.canteenId=null
                this.baseForm.stallNum=null
            }); 
        },800)
      },
      //选择食堂后获取档口编号
      chosenCanteen(e){
        console.log(e)
        this.baseForm.canteenId=e
        this.$refs['baseForm'].clearValidate(['canteenId']);
        this.getStallNum()
      },
      //获取档口编号
      async getStallNum() {
        let params= {
          "superId":this.baseForm.canteenId,
          "canteenTreeType":2
        } 
        const res = await getStallNumApi(params);
        this.$set(this.baseForm,"stallNum",res.data)
        this.$forceUpdate()
      },
      //查询标签下拉
      getLabel() {
        let param = { "current": 1,"size": -1}
        getLabelListApi(param).then((response) => {
          this.labelOptions = response.records; 
        });
      },
      //查询标签下拉
      getKind() {
        let param = { "current": 1,"size": -1}
        getKindListApi(param).then((response) => {
          this.kindOptions = response.records; 
        });
      },
      //选择负责人
      chosenCharger(){ 
        this.queryCustJobPage()
        this.openJob=true
      },
      //人员职位职称下拉
      queryAllCustJob() {
        queryAllCustJobApi({}).then((response) => {
          this.jobOptions = response.data
          console.log(response) 
        });
      },
      //负责人弹窗-查询按钮
      handleDialogQuery(){
        this.dialogQueryParams.pageNum=1
        this.queryCustJobPage()
      },
      //负责人弹窗-人员分页查询接口
      queryCustJobPage() {
        let param = {
          "current": this.dialogQueryParams.pageNum,
          "ifQueryJob": 1,
          "size": this.dialogQueryParams.pageSize
        }
        queryCustJobPageApi(param).then((response) => {
          this.jobTableData = response.records
          this.dialogTotal = Number(response.total);
          console.log(response) 
        });
      },
      // 档口图片上传
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      openImg(row) {
        this.dialogImageUrl = row.imgUrl;
        this.dialogVisible = true;
      },
      // 图片上传
      imgUpLoad(param, name, index) {
          // console.log(param,'image')
          param.type = 'stall'
          imgUpLoadTwo(param).then((res) => {
              if (res.code == 200) {
                  this.checkUrlList.push(res.data.fileUrl)
                  this.checkUrlNameList.push(res.data.fileName)
              } else { 
                  this.$modal.msgError(res.msg)
              }
          })
          .catch((error) => { 
              this.$modal.msgError(error)
          })
      },
      handleAvatarSuccess(res, file) {
          console.log('success')
      },
      handleExceed(files, fileList) {
          this.$message.warning('最多只可以上传一张图片')
      },
      handleRemove(file, fileList) {
          let sum = 0
          this.checkUrlNameList.forEach((item, index) => {
              if (item == file.name) {
                  sum = index
              }
          })
          this.checkUrlNameList.splice(sum, 1)
          this.checkUrlList.splice(sum, 1)
      },
      //图片点击查看
      handlePictureCardPreview(file) {
          console.log(file)
          this.dialogImageUrl = file.url
          this.dialogVisible = true
      }, 
      //查询餐次时段列表
      getMealtimeList() {
        getMealtimeListApi({}).then((response) => {
          this.mealtimeList = response
          console.log(response) 
        });
      },







      
  }
};
</script>
