<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item>
          <el-input
            v-model="queryParams.applyCustomName"
            placeholder="请输入企业名称"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.applyStatus"
            placeholder="申请状态"
            clearable
            size="small"
            style="width: 240px"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="queryParams.applyDate"
            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-table v-loading="loading" :data="list">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="认购企业" align="center" prop="applyCustomName" />
        <el-table-column label="认购数量（kg）" align="center" prop="amount"/>
        <el-table-column label="备注说明" align="center" prop="remark"/>
        <el-table-column label="申请日期" align="center" prop="applyDate">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.applyDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="申请状态" align="center" prop="applyStatus" :formatter="statusFormat"></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="primary"
              icon="el-icon-view"
              v-if="scope.row.applyStatus != 1"
              @click="handleCreate(scope.row)"
              v-hasPermi="['order:subscription:create']"
            >生成订单</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row)"
              icon="el-icon-delete"
              v-hasPermi="['order:subscription: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.visibleModal"
      			:title="modal.title"
      			:action="modal.action"
      			:visible="modal.visibleModal"
      			:selectRow="modal.selectRow"
      			@closeModal="closeModal">
      		</add-mobiel>
  </div>
</template>
<script>
import { listApplyList , delApplyItem , areaTree} from "@/api/order/subscription";
import addMobiel from './modal/addMobiel'
export default {
  name: "subscription",
  components: {
    addMobiel
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 状态数据字典
      statusOptions: [],
      // 表单参数
      form: {},
      //弹出层
      modal:{
        action:'',
        title:'',
        visibleModal:false,
        selectRow:null
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    //申请状态字典
    this.getDicts("order_searchStatus").then(response => {
      this.statusOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listApplyList(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.handleQuery();
    },
    /** 查看按钮操作 */
    handleCreate(item){
        this.modal.visibleModal = true
        this.modal.title = '订单生成'
        this.modal.action = 'edit'
        this.modal.selectRow = item
    },
    /** 删除按钮操作 */
    handleDelete(item) {
      console.log(item)
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delApplyItem(item.guid);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.applyStatus);
    },
    //窗口关闭
    closeModal(flag = false){
      this.modal.visibleModal = false
      flag && this.getList()
    }
  }
};
</script>
