<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="业务员" prop="salesmanId">
        <el-select v-model="queryParams.salesmanId" placeholder="请选择">
          <el-option
            v-for="(item,index) in salesmanList"
            :key="index"
            :label="item.companyUserName"
            :value="item.sysUserId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="冻结中" value="0" />
          <el-option label="已获得" value="1" />
          <el-option label="已失效" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="关联订单号" prop="linkOrderNo">
        <el-input
          v-model="queryParams.linkOrderNo"
          placeholder="请输入关联订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable size="small">
          <el-option
            v-for="dict in orderStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="关联会员名" prop="linkUserName">
        <el-input
          v-model="queryParams.linkUserName"
          placeholder="请输入关联会员名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关联会员手机号" prop="linkUserPhone">
        <el-input
          v-model="queryParams.linkUserPhone"
          placeholder="请输入会员手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createAt">
        <el-date-picker
          v-model="achievementTimeRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="是否发放：0-未发放,1-已发放" prop="isGive">-->
<!--        <el-input-->
<!--          v-model="queryParams.isGive"-->
<!--          placeholder="请输入是否发放：0-未发放,1-已发放"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @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"-->
<!--          v-hasPermi="['mall:mallAppSalesmanAchievement: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:mallAppSalesmanAchievement: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:mallAppSalesmanAchievement:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['mall:mallAppSalesmanAchievement:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallAppSalesmanAchievementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="业务员业绩主键ID" align="center" prop="achievementId" />-->
<!--      <el-table-column label="业务员ID" align="center" prop="salesmanId" />-->
      <el-table-column label="业务员名" align="center" prop="salesmanName" />
      <el-table-column label="金额" align="center" prop="price" />
      <el-table-column label="提成" align="center" prop="money" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">冻结中</div>
          <div v-if="scope.row.status == 1">已获得</div>
          <div v-if="scope.row.status == 2">已失效</div>
        </template>
      </el-table-column>
<!--      <el-table-column label="关联订单ID" align="center" prop="linkOrderId" />-->
      <el-table-column label="关联订单号" align="center" prop="linkOrderNo">
          <template slot-scope="{row}">
            <el-link type="primary" :underline="false" @click="handleCheckDetail(row)">{{row.linkOrderNo}}</el-link>
          </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="orderStatus" width="80">
        <template slot-scope="scope">
          <dict-tag :options="orderStatusOptions" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="配送方式：0-快递，1-自提" align="center" prop="deliveryType" />-->
<!--      <el-table-column label="关联会员ID" align="center" prop="linkUserId" />-->
      <el-table-column label="关联会员名" align="center" prop="linkUserName" />
      <el-table-column label="关联会员手机号" align="center" prop="linkUserPhone" width="120" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="150" />
<!--      <el-table-column label="更新时间" align="center" prop="updateAt" />-->
<!--      <el-table-column label="删除标记：0-正常，1-删除" align="center" prop="delFlag" />-->
<!--      <el-table-column label="是否发放：0-未发放,1-已发放" align="center" prop="isGive" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['mall:mallAppSalesmanAchievement:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mall:mallAppSalesmanAchievement: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"
    />

    <!-- 添加或修改app-业务员业绩对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="业务员ID" prop="salesmanId">
          <el-input v-model="form.salesmanId" placeholder="请输入业务员ID" />
        </el-form-item>
        <el-form-item label="业务员名" prop="salesmanName">
          <el-input v-model="form.salesmanName" placeholder="请输入业务员名" />
        </el-form-item>
        <el-form-item label="金额" prop="price">
          <el-input v-model="form.price" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="提成" prop="money">
          <el-input v-model="form.money" placeholder="请输入提成" />
        </el-form-item>
        <el-form-item label="状态：0-冻结中，1-已获得，2-已失效">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="关联订单ID" prop="linkOrderId">
          <el-input v-model="form.linkOrderId" placeholder="请输入关联订单ID" />
        </el-form-item>
        <el-form-item label="关联订单号" prop="linkOrderNo">
          <el-input v-model="form.linkOrderNo" placeholder="请输入关联订单号" />
        </el-form-item>
        <el-form-item label="订单状态：0-未付款，1-已付款，2-待接单，3-待发货，4-已装车，5-已完成，,8-已取消">
          <el-radio-group v-model="form.orderStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="配送方式：0-快递，1-自提" prop="deliveryType">
          <el-select v-model="form.deliveryType" placeholder="请选择配送方式：0-快递，1-自提">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="关联会员ID" prop="linkUserId">
          <el-input v-model="form.linkUserId" placeholder="请输入关联会员ID" />
        </el-form-item>
        <el-form-item label="关联会员名" prop="linkUserName">
          <el-input v-model="form.linkUserName" placeholder="请输入关联会员名" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-input v-model="form.createAt" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateAt">
          <el-input v-model="form.updateAt" placeholder="请输入更新时间" />
        </el-form-item>
        <el-form-item label="删除标记：0-正常，1-删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记：0-正常，1-删除" />
        </el-form-item>
        <el-form-item label="是否发放：0-未发放,1-已发放" prop="isGive">
          <el-input v-model="form.isGive" placeholder="请输入是否发放：0-未发放,1-已发放" />
        </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>

        <el-dialog  :visible.sync="menuRoleVisible" append-to-body>
          <el-form label-width="90px">
            <el-row>
              <el-col :span="parseInt(12)">
                <el-form-item label="收件人" prop="receiverName" >
                  <el-input v-model="form.receiverName" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(12)">
                <el-form-item label="手机号" prop="receiverPhone" >
                  <el-input v-model="form.receiverPhone" placeholder="" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="parseInt(8)">
                <el-form-item label="省份" prop="receiverProvince">
                  <el-input v-model="form.receiverProvince" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="城市" prop="receiverCity">
                  <el-input v-model="form.receiverCity" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="区县" prop="receiverArea">
                  <el-input v-model="form.receiverArea" placeholder="" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="地址" prop="receiverAddress">
                <el-input v-model="form.receiverAddress" placeholder="" disabled />
              </el-form-item>
            </el-row>
            <el-row>
              <el-col :span="parseInt(8)">
                <el-form-item label="总价" prop="orderPrice">
                  <el-input v-model="form.orderPrice" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="提成" prop="commissionPrice">
                  <el-input v-model="form.commissionPrice" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="总数量" prop="goodsNum">
                  <el-input v-model="form.goodsNum" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="是否接单" prop="status">
                  <el-input v-model="form.status === '3'? '已接单':'未接单'" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="接单姓名" prop="warehouseManageName">
                  <el-input v-model="form.warehouseManageName" placeholder="" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(8)">
                <el-form-item label="财务审核" prop="isFinance">
                  <el-input v-model="form.isFinance === '0'? '未审核':'已审核'" placeholder="" disabled />
                </el-form-item>
              </el-col>
            </el-row>

            <el-form-item label="备注" prop="remarks">
              <el-input v-model="form.remarks" placeholder="" disabled />
            </el-form-item>

            <el-row>
              <el-col :span="parseInt(12)" v-if="form.isProof === '1'">
                <el-form-item label="支付凭证" prop="payProof">
    <!--              <el-image style="width: 200px; height: 200px" :src="form.payProof" disabled :preview-src-list="[form.payProof]" />-->
                  <el-image
                    v-for="(imageUrl, index) in imageUrls"
                    :key="index"
                    :src="imageUrl"
                    style="width: 200px; height: 200px"
                    disabled :preview-src-list="[imageUrl]"
                  ></el-image>
                </el-form-item>
              </el-col>
              <el-col :span="parseInt(12)" v-if="form.isCar === '1'">
                <el-form-item label="装车视频" prop="carVideo">
                  <video style="width: 200px; height: 200px" :src="form.carVideo" disabled controls />
                </el-form-item>
              </el-col>
            </el-row>

          </el-form>
          <mall-app-order-goods v-if="menuRoleVisible" :page-type="1" :order-id="this.orderGoodsOrderId"  ref="OrderGoods"></mall-app-order-goods>
        </el-dialog>






  </div>
</template>

<script>
import { listMallAppSalesmanAchievement, getMallAppSalesmanAchievement, delMallAppSalesmanAchievement, addMallAppSalesmanAchievement, updateMallAppSalesmanAchievement, exportMallAppSalesmanAchievement } from "@/api/mall/mallAppSalesmanAchievement";
import {selectAppSalesmanList} from "@/api/mall/mallAppCompanyUser";
import {
  listMallAppOrderOrder,
  getMallAppOrderOrder,
  delMallAppOrderOrder,
  addMallAppOrderOrder,
  updateMallAppOrderOrder,
  exportMallAppOrderOrder,
  exportOrder
} from "@/api/mall/mallAppOrderOrder";
export default {
  name: "MallAppSalesmanAchievement",
  data() {
    return {
      // 订单状态
      orderStatusOptions: [],
      // 业绩时间范围
      achievementTimeRange:[],
      salesmanList:[],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // app-业务员业绩表格数据
      mallAppSalesmanAchievementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        salesmanId: null,
        salesmanName: null,
        price: null,
        money: null,
        status: null,
        linkOrderId: null,
        linkOrderNo: null,
        orderStatus: null,
        deliveryType: null,
        linkUserId: null,
        linkUserName: null,
        linkUserPhone: null,
        createAt: null,
        updateAt: null,
        delFlag: null,
        isGive: null,
        params:{
          beginAchievementTime:'',
          endAchievementTime:''
        }
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      menuRoleVisible:false,
      imageUrls:[],
      orderGoodsOrderId:''
    };
  },
  created() {
    this.getList();
    this.getDicts("app_order_status").then(response => {
      this.orderStatusOptions = response.data;
    });
    selectAppSalesmanList().then(res =>{
      this.salesmanList = res.data
    })
  },
  methods: {

    /** 订单详情 */
        handleCheckDetail(row){
          let linkOrderId = row.linkOrderId
          console.log(row,'参数')
          this.form = {}
          this.form.carVideo = [];
          getMallAppOrderOrder(linkOrderId).then(response => {
            this.form = response.data;
            this.imageUrls = response.data.payProof.split(',');
          });
          this.menuRoleVisible = true;
          this.orderGoodsOrderId =linkOrderId
        },

    /** 查询app-业务员业绩列表 */
    getList() {
      this.loading = true;
      if (null != this.achievementTimeRange && '' != this.achievementTimeRange) {
        this.queryParams.params["beginAchievementTime"] = this.achievementTimeRange[0];
        this.queryParams.params["endAchievementTime"] = this.achievementTimeRange[1];
      }
      listMallAppSalesmanAchievement(this.queryParams).then(response => {
        this.mallAppSalesmanAchievementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        achievementId: null,
        salesmanId: null,
        salesmanName: null,
        price: null,
        money: null,
        status: "0",
        linkOrderId: null,
        linkOrderNo: null,
        orderStatus: "0",
        deliveryType: null,
        linkUserId: null,
        linkUserName: null,
        createAt: null,
        updateAt: null,
        delFlag: null,
        isGive: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.achievementTimeRange = []
      this.queryParams.params["beginAchievementTime"] = '';
      this.queryParams.params["endAchievementTime"] = '';
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.achievementId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加app-业务员业绩";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const achievementId = row.achievementId || this.ids
      getMallAppSalesmanAchievement(achievementId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改app-业务员业绩";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.achievementId != null) {
            updateMallAppSalesmanAchievement(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallAppSalesmanAchievement(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const achievementIds = row.achievementId || this.ids;
      this.$confirm('是否确认删除app-业务员业绩编号为"' + achievementIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMallAppSalesmanAchievement(achievementIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有app-业务员业绩数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportMallAppSalesmanAchievement(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
