<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="careerName">
        <el-input
          v-model="queryParams.careerName"
          placeholder="请输入职业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="等级" prop="level">
        <el-select v-model="queryParams.level">
          <el-option v-for="item in level"
                     :key="item.value"
                     :value="item.value"
                     :label="item.label"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否展示" prop="isShow">
        <el-select v-model="queryParams.isShow">
          <el-option v-for="item in isShow"
                     :key="item.value"
                     :value="item.value"
                     :label="item.label"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="城市划分等级" label-width="120px">
            <el-select v-model="queryParams.cityLevel" placeholder="请选择城市划分等级" clearable>
              <el-option
                v-for="dict in dict.type.city_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
        </el-form-item>
      <!-- <el-form-item label="省" prop="provinceId">
        <el-select v-model="queryParams.provinceId" @change="getCityList">
          <el-option v-for="item in provinceList"
                     :key="item.id"
                     :value="item.id"
                     :label="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="市" prop="cityId">
        <el-select v-model="queryParams.cityId">
          <el-option v-for="item in cityList"
                     :key="item.id"
                     :value="item.id"
                     :label="item.name"></el-option>
        </el-select>
      </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"
          v-hasPermi="['mall:mallCareerSalary:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mall:mallCareerSalary:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mall:mallCareerSalary:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mall:mallCareerSalary:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallCareerSalaryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="职业名称" align="center" prop="careerName" />
      <el-table-column label="等级" align="center" prop="level" >
        <template slot-scope="scope">
          <span v-if="scope.row.level === '0'">低端</span>
          <span v-if="scope.row.level === '1'">中低端</span>
          <span v-if="scope.row.level === '2'">中端</span>
          <span v-if="scope.row.level === '3'">中高端</span>
          <span v-if="scope.row.level === '4'">高端</span>
        </template>
      </el-table-column>
      <el-table-column label="平均年薪" align="center" prop="careerMoney" />
      <el-table-column label="收入排名" align="center" prop="moneyRanking" />
      <!-- <el-table-column label="省名" align="center" prop="provinceName" />
      <el-table-column label="市名" align="center" prop="cityName" /> -->
      <el-table-column label="城市等级" align="center" prop="cityName" >
        <template slot-scope="scope">
                  <dict-tag
                      :options="dict.type.city_level"
                      :value="scope.row.cityLevel"
                    />
        </template>
      </el-table-column>
      <!--<el-table-column label="区名" align="center" prop="areaName" />-->
      <!--<el-table-column label="是否展示" align="center" prop="isShow" >-->
      <!--  <template slot-scope="scope">-->
      <!--    <span v-if="scope.row.isShow === 0">展示</span>-->
      <!--    <span v-if="scope.row.isShow === 1">不展示</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="状态:：0-启用，1-不启用" align="center" prop="status" >-->
      <!--  <template slot-scope="scope">-->
      <!--    <span v-if="scope.row.status === 0">启用</span>-->
      <!--    <span v-if="scope.row.status === 1">不启用</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <!--<el-table-column label="创建时间" align="center" prop="createAt" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mall:mallCareerSalary:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mall:mallCareerSalary:remove']"
          >删除</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="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="职业名称" prop="careerName">
          <el-input v-model="form.careerName" placeholder="请输入职业名称" />
        </el-form-item>
        <el-form-item label="等级" prop="level">
          <el-select v-model="form.level" placeholder="请选择等级">
            <el-option v-for="item in level"
                       :key="item.value"
                       :value="item.value"
                       :label="item.label"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="平均年薪" prop="careerMoney">
          <el-input v-model="form.careerMoney" placeholder="请输入平均年薪" />
        </el-form-item>
        <el-form-item label="收入排名" prop="moneyRanking">
          <el-input-number :min="0" :precision="0" controls-position="right" v-model="form.moneyRanking" placeholder="请输入收入排名" />
        </el-form-item>
        <el-form-item label="城市划分等级" >
            <el-select v-model="form.cityLevel" placeholder="请选择城市划分等级" clearable>
              <el-option
                v-for="dict in dict.type.city_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
        </el-form-item>
        <!-- <el-form-item label="省" prop="provinceId">
          <el-select v-model="form.provinceId" @change="getFormCityList">
            <el-option v-for="item in provinceList"
                       :key="item.id"
                       :value="item.id"
                       :label="item.name"></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="市" prop="cityId">
          <el-select v-model="form.cityId">
            <el-option v-for="item in cityList"
                       :key="item.id"
                       :value="item.id"
                       :label="item.name"></el-option>
          </el-select>
        </el-form-item> -->
        <!--<el-form-item label="是否展示" prop="isShow">-->
        <!--  <el-radio-group v-model="form.isShow" >-->
        <!--    <el-radio v-for="(item, index) in isShow"-->
        <!--              :key="index"-->
        <!--              :label="item.value">-->
        <!--      {{ item.label }}-->
        <!--    </el-radio>-->
        <!--  </el-radio-group>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="状态" prop="status">-->
        <!--  <el-radio-group v-model="form.status" >-->
        <!--    <el-radio v-for="(item, index) in status"-->
        <!--              :key="index"-->
        <!--              :label="item.value">-->
        <!--      {{ item.label }}-->
        <!--    </el-radio>-->
        <!--  </el-radio-group>-->
        <!--</el-form-item>-->
        
        <el-form-item label="排序" prop="sort">
          <el-input-number controls-position="right" :min="0" :precision="0" v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input  v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMallCareerSalary, getMallCareerSalary, delMallCareerSalary, addMallCareerSalary, updateMallCareerSalary } from "@/api/mall/mallCareerSalary";
import {getCityOrArea, getProvince} from "@/api/set/setRegion";

export default {
  name: "MallCareerSalary",
  dicts: ['city_level'],
  props: ["careerId", "careerName"],
  data() {
    return {
      level: [
        {
          value: '0',
          label: "低端"
        },
        {
          value: '1',
          label: "中低端"
        },
        {
          value: '2',
          label: "中端"
        },
        {
          value: '3',
          label: "中高端"
        },
        {
          value: '4',
          label: "高端"
        }
      ],
      isShow: [
        {
          value: 0,
          label: "展示"
        },
        {
          value: 1,
          label: "不展示"
        },
      ],
      status: [
        {
          value: 0,
          label: "启用"
        },
        {
          value: 1,
          label: "不启用"
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 职业薪资表格数据
      mallCareerSalaryList: [],
      // 省份
      provinceList: [],
      // 城市
      cityList: [],
      // 区域
      areaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        careerId: null,
        careerName: null,
        level: null,
        careerMoney: null,
        moneyRanking: null,
        provinceId: null,
        cityId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        isShow: null,
        status: null,
        sort: null,
        remarks: null,
        createAt: null,
        updateAt: null,
        cityLevel:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    // this.getProvinceList();
  },
  methods: {
    /** 查询职业薪资列表 */
    getList() {
      this.loading = true;
      if(this.careerId != null){
        this.queryParams.careerId = this.careerId;
      }
      listMallCareerSalary(this.queryParams).then(response => {
        this.mallCareerSalaryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        careerSalaryId: null,
        careerId: null,
        careerName: null,
        level: null,
        careerMoney: null,
        moneyRanking: null,
        provinceId: null,
        cityId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        isShow: null,
        status: "0",
        sort: null,
        remarks: null,
        createAt: null,
        updateAt: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(!this.queryParams.cityLevel){
        this.queryParams.cityLevel = null;
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.queryParams.provinceId = null;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.careerSalaryId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.careerId != null){
        this.form.careerId = this.careerId;
        this.form.careerName = this.careerName;
      }
      this.open = true;
      this.title = "添加职业薪资";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const careerSalaryId = row.careerSalaryId || this.ids
      getMallCareerSalary(careerSalaryId).then(response => {
        this.form = response.data;
        getCityOrArea(this.form.provinceId).then(response=>{
          this.cityList = response.data.data;
        })
        this.open = true;
        this.title = "修改职业薪资";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.careerSalaryId != null) {
            updateMallCareerSalary(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallCareerSalary(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const careerSalaryIds = row.careerSalaryId || this.ids;
      this.$modal.confirm('是否确认删除职业薪资编号为"' + careerSalaryIds + '"的数据项？').then(function() {
        return delMallCareerSalary(careerSalaryIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mall/mallCareerSalary/export', {
        ...this.queryParams
      }, `mallCareerSalary_${new Date().getTime()}.xlsx`)
    },
    /** 省份 */
    // getProvinceList(){
    //   getProvince().then(response=>{
    //     this.provinceList = response.data.data;
    //   })
    // },
    /** 城市 */
    // getCityList(){
    //   if (this.queryParams.provinceId != null){
    //     getCityOrArea(this.queryParams.provinceId).then(response=>{
    //       this.cityList = response.data.data;
    //     })
    //   }
    // },
    /** 城市 */
    // getFormCityList(){
    //   this.form.cityId = null;
    //   if (this.form.provinceId != null){
    //     getCityOrArea(this.form.provinceId).then(response=>{
    //       this.cityList = response.data.data;
    //     })
    //   }
    // },
  }
};
</script>
