<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item>
          <el-select v-model="queryParams.fkProductType" placeholder="定价类目" clearable size="small">
            <el-option
              v-for="dict in priceTypeOptions"
              :key="dict.guid"
              :label="dict.typeName"
              :value="dict.guid"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="queryParams.checkState" placeholder="定价状态" clearable size="small">
            <el-option key="0" label="待审核" value="0"/>
            <el-option key="1" label="审核通过" value="1"/>
            <el-option key="2" label="审核未通过" value="2"/>
          </el-select>
        </el-form-item>
        <el-form-item>
            <el-date-picker
              v-model="queryParams.checkTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="定价日期">
            </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" 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"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['productManage:priceManage:add']"
          >新增定价</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="list">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="定价类目" align="center" prop="typeName" />
        <el-table-column label="价格（元/kg）" align="center" prop="price" />
        <el-table-column label="备注说明" align="center" prop="checkRemark" />
        <el-table-column label="定价日期" align="center" prop="modifiedTime" />
        <el-table-column label="定价状态" align="center"  width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.checkState == 0">待审核</span>
            <span v-else-if="scope.row.checkState == 1">审核通过</span>
            <span v-else="scope.row.checkState">审核未通过</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="280"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              v-if="scope.row.checkState == 0"
              @click="handleCheck(scope.row)"
              v-hasPermi="['productManage:priceManage:check']"
            >审核</el-button>
            <!-- <el-button
              size="mini"
              type="primary"
              icon="el-icon-view"
              @click="handleView(scope.row)"
            >查看</el-button> -->
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row)"
              icon="el-icon-delete"
              v-hasPermi="['productManage:priceManage:del']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <add-mobiel
      			v-if="modal.add.visibleModal"
      			:title="modal.add.title"
      			:action="modal.add.action"
      			:visible="modal.add.visibleModal"
      			:selectRow="modal.add.selectRow"
      			@closeAddModal="closeAddModal">
      		</add-mobiel>
      <check-mobiel
        v-if="modal.check.visibleModal"
        :title="modal.check.title"
        :action="modal.check.action"
        :visible="modal.check.visibleModal"
        :selectRow="modal.check.selectRow"
        @closeCheckModal="closeCheckModal">
      </check-mobiel>
  </div>
</template>

<script>
import { listPrice , delPrice , priceType } from "@/api/productManage/priceManage";
import addMobiel from './modal/addMobiel'
import checkMobiel from './modal/checkMobiel'
export default {
  name: "company",
  components: {
    addMobiel,
    checkMobiel
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 状态数据字典
      priceTypeOptions: [],
      // 表单参数
      form: {},
      //弹出层
      modal:{
        add:{
          action:'',
          title:'',
          visibleModal:false,
          selectRow:null
        },
        check:{
          action:'',
          title:'',
          visibleModal:false,
          selectRow:null
        }
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    this.getPriceType();
    this.getList();
  },
  methods: {
    /** 定价类型列表 */
    getPriceType(){
      priceType({}).then(res => {
          if(res.retHead.errCode == 0){
            this.priceTypeOptions = res.retBody
          }
        }
      );
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listPrice(this.queryParams).then(res => {
          if(res.retHead.errCode == 0){
            this.list = res.retBody
            this.total = res.retHead.total;
          }
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNo: 1,
        pageSize: 10
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
        this.modal.add.visibleModal = true
        this.modal.add.title = '新增定价'
        this.modal.add.action = 'add'
    },
    /** 审核按钮操作 */
    handleCheck(item){
        this.modal.check.visibleModal = true
        this.modal.check.title = '定价审核'
        this.modal.check.action = 'add'
        this.modal.check.selectRow = item
    },
    /** 查看按钮操作 */
    // handleView(item){
    //     this.modal.visibleModal = true
    //     this.modal.title = '定价详情'
    //     this.modal.action = 'view'
    //     this.modal.selectRow = item
    // },
    /** 查看按钮操作 */
    // handleEdit(item){
    //     this.modal.visibleModal = true
    //     this.modal.title = '定价编辑'
    //     this.modal.action = 'edit'
    //     this.modal.selectRow = item
    // },
    /** 删除按钮操作 */
    handleDelete(item) {
      let params = {
          guid:item.guid
      }
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPrice(params);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    //窗口关闭
    closeAddModal(flag = false){
      this.modal.add.visibleModal = false
      flag && this.getList()
    },
    closeCheckModal(flag = false){
      this.modal.check.visibleModal = false
      flag && this.getList()
    }
  }
};
</script>
