<template>
  <div class="packing ">
    <div style="display: flex;justify-content:space-between;margin-bottom:10px">
      <div class="header_flex">
        <div>
          <el-button style="margin-right:20px" size="mini" type="primary" @click="
              (listDialogFormVisible = true),
                (packingForm = { saleMoney: 0, promotionProjectLists: [] })
            " v-role="7001002">新方案</el-button>
        </div>
        <div>
          <el-button size="mini" type="primary" @click="searchDialog = true">条件搜索</el-button>
          <el-button size="mini" type="info" @click="promotionPage((refreshtext = true))">刷新</el-button>
        </div>
      </div>
      <div>
        <!-- 状态  状态0:添加/1:修改/2:送审/3:回收/4:审核/5:反审核/6:关闭-->
        <el-button size="mini" type="" @click="detail" :disabled="radioRowValueList.state == undefined">明细</el-button>
        <el-button size="mini" type="primary" @click="editForm" :disabled="
            radioRowValueList.pushState != 0 ||
              radioRowValueList.state == undefined ||
              radioRowValueList.state == 2 ||
              radioRowValueList.state == 4 ||
              radioRowValueList.state == 6
          " plain v-role="7001003">修改</el-button>
        <el-button size="mini" type="primary" @click="sendAndit" :disabled="
            radioRowValueList.state == 2 ||
              radioRowValueList.state == 4 ||
              radioRowValueList.state == 3 ||
              radioRowValueList.state == undefined ||
              radioRowValueList.state == 6
          " v-role="7001004">送审
        </el-button>
        <el-button size="mini" type="primary" @click="recycle" :disabled="
            radioRowValueList.pushState != 0 ||
              radioRowValueList.state == undefined ||
              radioRowValueList.state == 1 ||
              radioRowValueList.state == 3 ||
              radioRowValueList.state == 4 ||
              radioRowValueList.state == 6 ||
              radioRowValueList.state == 5 ||
              radioRowValueList.state == 0
          " plain v-role="7001005">回收</el-button>
        <el-button v-role="7001006" size="mini" type="primary" @click="audit" :disabled="
            radioRowValueList.pushState != 0 ||
              radioRowValueList.state == undefined ||
              radioRowValueList.state == 0 ||
              radioRowValueList.state == 1 ||
              radioRowValueList.state == 3 ||
              radioRowValueList.state == 6 ||
              radioRowValueList.state == 5 ||
              radioRowValueList.state == 4
          ">
          审核</el-button>
        <el-button size="mini" type="primary" @click="unAudit" :disabled="
            radioRowValueList.pushState == 1 ||
              radioRowValueList.state == undefined ||
              radioRowValueList.state == 0 ||
              radioRowValueList.state == 1 ||
              radioRowValueList.state == 2 ||
              radioRowValueList.state == 6 ||
              radioRowValueList.state == 3 ||
              radioRowValueList.state == 5
          " plain v-role="7001007">反审核</el-button>
        <el-button size="mini" type="primary" @click="copyForm" :disabled="radioRowValueList.state == undefined">复制</el-button>
        <el-button v-role="7001008" size="mini" type="success" @click="issue" :disabled="
            radioRowValueList.endPromotion == 1 ||
              radioRowValueList.state != 4 ||
              radioRowValueList.state == 6
          ">
          <span v-if="radioRowValueList.pushCount > 0">推送</span><span v-else>发布</span>
        </el-button>
        <el-button v-role="7001009" size="mini" type="primary" @click="close" :disabled="
            radioRowValueList.endPromotion == 1 ||
              radioRowValueList.state == undefined ||
              radioRowValueList.state == 0 ||
              radioRowValueList.state == 1 ||
              radioRowValueList.state == 2 ||
              radioRowValueList.state == 3 ||
              radioRowValueList.state == 5 ||
              radioRowValueList.state == 6 ||
              (radioRowValueList.state == 4 && radioRowValueList.pushState == 0)
          ">
          关闭</el-button>
      </div>
    </div>
    <div class="schemeListDiv">
      <el-table :data="pageInfo.schemeList" @row-click="rowClick" @row-dblclick="rowDbClick" :header-cell-style="{
          background: 'linear-gradient(#6cb3ff, #1873d4)',
          color: '#eeeeee'
        }">
        <el-table-column label="选择" width="55" align="center" sortable type="index">
          <template slot-scope="scope">
            <el-radio v-model="radioRowValue" :label="scope.row.id" @change.native="(scope.row)">{{null}}</el-radio>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="76" fixed="left" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.state == 6" effect="dark" type="info">已关闭</el-tag>
            <span v-else>
              <el-tag v-if="scope.row.endPromotion == 0" size="medium" effect="dark" :type="
                  scope.row.state == 0
                    ? ''
                    : '' || scope.row.state == 1
                    ? 'danger'
                    : '' || scope.row.state == 2
                    ? 'success'
                    : '' || scope.row.state == 3
                    ? 'info'
                    : '' || scope.row.state == 4
                    ? 'success'
                    : '' || scope.row.state == 5
                    ? 'warning'
                    : '' || scope.row.pushState == 1
                    ? 'success'
                    : ''
                ">
                <div v-if="scope.row.state<5">
                  <span v-show="scope.row.state==0">新创建</span>
                  <span v-show="scope.row.state==1">已修改</span>
                  <span v-show="scope.row.state==2">已送审</span>
                  <span v-show="scope.row.state==3">已回收</span>
                  <span v-show="scope.row.state==5">反审核</span>
                  <span v-show="scope.row.state==4">已审核</span>
                </div>
                <div v-else>
                  <span v-show="scope.row.pushState==1&&scope.row.state!=6">已发布</span>
                </div>
              </el-tag>
              <el-tag v-else type="info" size="medium" effect="dark">已结束</el-tag>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="promotionNum" label="方案编码" align="center" min-width="130"></el-table-column>
        <el-table-column prop="createdDate" label="创建时间" show-overflow-tooltip align="center" min-width="80">
          <template slot-scope="scope">
            <div>{{ scope.row.createdDate | dateFormat }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="promotionName" :show-overflow-tooltip="true" label="方案名称" align="center" min-width="120"></el-table-column>
        <el-table-column prop="totalMoney" label="总价值" align="center" min-width="80"></el-table-column>
        <el-table-column prop="saleMoney" label="打包价" align="center" min-width="80"></el-table-column>
        <el-table-column prop="beginDate" label="开始日期" align="center" min-width="105">
          <template slot-scope="scope">
            <div>{{ scope.row.beginDate | dateMonth }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="endDate" label="结束日期" align="center" min-width="105">
          <template slot-scope="scope">
            <div>{{ scope.row.endDate | dateMonth }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="suitableObject" label="适用对象" align="center" min-width="100">
          <template slot-scope="scope">
            <span class="text-green" v-show="scope.row.suitableObject == 0">全部会员</span>
            <span v-show="scope.row.suitableObject == 1">生日会员</span>
            <span class="text-cyan" v-show="scope.row.suitableObject == 2" @click.stop="openSuitMember(scope.row)">指定会员</span>
          </template>
        </el-table-column>
        <el-table-column prop="suitableStore" label="适用门店" align="center" min-width="100">
          <template slot-scope="scope">
            <span class="text-green" v-show="scope.row.suitableStore == 0">全部门店</span>
            <span class="text-cyan" v-show="scope.row.suitableStore == 1" @click.stop="openSuitStore(scope.row)">指定门店</span>
          </template>
        </el-table-column>
        <el-table-column prop="limitCount" label="限购" align="center" min-width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.limitBuy == 0">不限购</div>
            <div v-else>限购{{ scope.row.limitCount }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="pushCount" label="推送次数" align="center" min-width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.pushCount == 0">未发布</div>
            <div v-else>推送 {{ scope.row.pushCount }} 次</div>
          </template>
        </el-table-column>
        <el-table-column prop="createdBy" label="操作人" align="center" min-width="100">
        </el-table-column>        
      </el-table>
      <div class="block" style="margin-top:15px;">
        <!-- 分页组件 -->
        <el-pagination align="left" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[10, 20, 30, 40, 50]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageInfo.total"></el-pagination>
      </div>
    </div>
    <el-dialog :close-on-click-modal="false" v-dialogDrag title="创建新方案" :visible.sync="listDialogFormVisible" width="1000px">
      <div style="min-width:950px;width:950px;margin:0 auto;height:50vh;overflow: auto;">
        <el-form :model="packingForm" inline ref="packingForm" :label-width="labelWidth">
          <el-form-item label="方案名称:" prop="promotionName" :rules="{
              required: true,
              message: '请输入方案名称',
              trigger: 'blur'
            }">
            <div class="form-width-m">
              <el-input v-model="packingForm.promotionName" placeholder="方案名称"></el-input>
            </div>
          </el-form-item>
          <el-form-item label="打包价:">
            <!-- <input type="number"   v-model="packingForm.saleMoney" style="border:none;width:140px;background:#eee;height:35px;font-size:14px;padding-left:10px;font-weight: 500;"> -->
            <div class="form-width-m">{{ packingForm.saleMoney }}</div>
          </el-form-item>
          <el-form-item label="方案总价:">
            <div class="form-width-m">{{ packingForm.totalMoney }}</div>
          </el-form-item>
          <br />
          <el-form-item label="开始日期:" prop="beginDate" :rules="{
              required: true,
              message: '请选择开始日期',
              trigger: 'blur'
            }">
            <div class="block form-width-m">
              <el-date-picker v-model="packingForm.beginDate" :picker-options="pickerOptionsStart" value-format="yyyy-MM-dd 00:00:00" format="yyyy-MM-dd" type="date" default-time="00:00:00" placeholder="开始日期"></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="结束日期:" prop="endDate" :rules="{
              required: true,
              message: '请选择结束日期',
              trigger: 'blur'
            }">
            <div class="block form-width-m">
              <el-date-picker v-model="packingForm.endDate" :picker-options="pickerOptionsEnd" value-format="yyyy-MM-dd 23:59:59" format="yyyy-MM-dd" default-time="23:59:59" type="date" placeholder="结束日期"></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="现付提成:" prop="salesCommission" :rules="{
              required: true,
              message: '请输入现付提成',
              trigger: 'blur'
            }">
            <input type="text" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,3})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,3}" v-model="packingForm.salesCommission" style="border:none;width:50px;background:#eee;height:35px;font-size:14px;padding-left:10px;" />
          </el-form-item>
          <el-form-item label="卡付提成:" prop="cardSalesCommission" :rules="{
              required: true,
              message: '请输入卡付提成',
              trigger: 'blur'
            }">
            <input type="text" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,3})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,3}" v-model="packingForm.cardSalesCommission" style="border:none;width:50px;background:#eee;height:35px;font-size:14px;padding-left:10px;" />
          </el-form-item>
          <br />
          <el-form-item label="适用对象:" prop="suitableObject" :rules="{
              required: true,
              message: '请选择适用对象',
              trigger: 'change'
            }">
            <el-radio-group v-model="packingForm.suitableObject" style="font-size:14px">
              <el-radio class="margin-bottom" :label="0">所有会员</el-radio>
              <el-radio class="margin-top" :label="2">指定会员</el-radio>
              <el-button :disabled="!(packingForm.suitableObject === 2)" size="mini" type="text" @click="openSuitMember(packingForm)"><span>会员列表</span></el-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否限购:" prop="limitBuy" :rules="{
              required: true,
              message: '请选择是否限购',
              trigger: 'change'
            }">
            <div style="width:280px;padding-top:5px">
              <el-radio-group v-model="packingForm.limitBuy" style="font-size:14px">
                <el-radio :label="0">不限购</el-radio>
                <el-radio class="margin-bottom" :label="1">限购</el-radio>
                <input oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" v-show="packingForm.limitBuy == 1" type="number" v-model="packingForm.limitCount" class="form-width-xss" style="border:none;border-bottom:1px solid #333;margin-right:10px" /><span v-show="packingForm.limitBuy == 1">包</span>
              </el-radio-group>
            </div>
          </el-form-item>
          <el-form-item label="适用门店:" prop="suitableObject" :rules="{
              required: true,
              message: '请选择适用门店',
              trigger: 'change'
            }">
            <el-radio-group v-model="packingForm.suitableStore" style="font-size:14px">
              <el-radio class="margin-bottom" :label="0">所有门店</el-radio>
              <el-radio class="margin-top" :label="1">指定门店</el-radio>
              <el-button :disabled="!(packingForm.suitableStore === 1)" size="mini" type="text" @click="openSuitStore(packingForm)"><span>门店列表</span></el-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="允许卡付:" prop="limitBuy" :rules="{
              required: true,
              message: '请选择是否允许卡付',
              trigger: 'change'
            }">
            <el-radio-group v-model="packingForm.cardBuy" style="font-size:14px">
              <el-radio :label="1">允许卡付</el-radio>
              <el-radio :label="0">不允许卡付</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <el-form-item label="能否打折:"  v-show="packingForm.cardBuy==1" required>
            <el-radio-group v-model="packingForm.cardLimit" style="font-size:14px">
              <el-radio :label="1">卡付允许打折</el-radio>
              <el-radio :label="0">卡付不允许打折</el-radio>
            </el-radio-group>
          </el-form-item> -->
          <div style="width:840px;margin-left:30px">
            <el-button size="mini" type="primary" @click="editPro(projectText = '添加')">添加</el-button>
            <el-table :data="packingForm.promotionProjectLists" :header-cell-style="{
                background: 'linear-gradient(#6cb3ff, #1873d4)',
                color: '#eeeeee'
              }" style="margin-top:10px">
              <el-table-column prop="projectNum" label="项目编码" align="center" min-width="90">
                <template slot-scope="scope">
                  <div @click="
                      editPro(
                editIndex = scope.$index,
                        (projectText = '修改')
                      )
                    " style="cursor: pointer;">
                    {{ scope.row.projectNum }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="projectName" label="项目名称" :show-overflow-tooltip="true" align="center" min-width="120">
                <template slot-scope="scope">
                  <div @click="
                      editPro(
                    editIndex = scope.$index,
                        (projectText = '修改')
                      )
                    " style="cursor: pointer; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                    {{ scope.row.projectName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="priceMember" label="标准价" align="center" width="80"></el-table-column>
              <el-table-column prop="times" label="次数" align="center" min-width="80">
                <template slot-scope="scope">
                  <div v-if="timesIndex!=scope.$index" style="cursor: pointer;" @click="editRow(scope.row,scope.$index,timesIndex =scope.$index)">
                    {{ scope.row.times }}
                    <i class="el-icon-edit text-cyan"></i>
                  </div>
                  <el-input type="number" class="form-input-wdith-xs" v-focus v-else oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*\.?[0-9]{0,3}" v-model="scope.row.times" @blur="endEditNumber(scope.row)"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="" label="标准金额" align="center" min-width="80">
                <template slot-scope="scope">
                  {{scope.row.times&&scope.row.priceMember?(scope.row.times*scope.row.priceMember).toFixed(2)*1:0}}
                </template>
              </el-table-column>
              <el-table-column prop="" label="活动金额" align="center" min-width="100" fixed="right">
                <template slot-scope="scope">
                  <div v-if="totalMoneyIndex != scope.$index" style="cursor: pointer;" @click="editRow(scope.row,scope.$index,totalMoneyIndex = scope.$index)">
                    {{ scope.row.projectTotalMoney }}
                    <i class="el-icon-edit text-cyan"></i>
                  </div>
                  <el-input type="number" class="form-input-wdith-xs" v-focus v-else oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" v-model="scope.row.projectTotalMoney" @blur="endEditMoney(scope.row)"></el-input>
                </template>
              </el-table-column>
              <el-table-column align="center" fixed="right" label="操作" width="160">
                <template slot-scope="scope">
                  <el-button size="mini" type="primary" @click="editPro(editIndex = scope.$index,projectText = '修改')">修改</el-button>
                  <el-button size="mini" type="primary" plain @click="delProject(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
              <el-table-column prop="typeInfo" label="有效类型" align="center" width="215">
                <template slot-scope="scope">
                      <el-radio v-model="scope.row.typeInfo" label="1" @change="typeChange(scope.row)">有效期(月)</el-radio>
                      <el-radio v-model="scope.row.typeInfo" label="2" @change="typeChange(scope.row)">截止日期</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="日期操作" align="center" width="200">
                <template slot-scope="scope">
                  <div v-if="scope.row.typeInfo == 1">
                    <el-input v-model="scope.row.validTime" placeholder="有效日期(月)" style="width:150px"></el-input>
                  </div>
                  <div v-else>                   
                    <el-date-picker 
                     v-model="scope.row.useEndDate"
                     type="date"
                     format="yyyy-MM-dd"
                     value-format="yyyy-MM-dd" 
                     placeholder="选择日期">
                   </el-date-picker>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div style="width:100%;background:#eee;display: flex;justify-content:space-between;font-size:14px;line-height:40px">
              <span style="margin-left:20px">总价格</span>
              <span style="margin-right:185px">¥{{ projectPriceSum }}</span>
            </div>
          </div>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" plain @click="listDialogFormVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="newProjet()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- /-----------------------------------------------------审核 修改 复制-----------------------------------------------           -->
    <el-dialog :close-on-click-modal="false" v-dialogDrag :title="titles" :visible.sync="formDialog" width="1000px" :before-close="handleClose">
      <div style="min-width:950px;width:950px;margin:0 auto;height:50vh;overflow: auto;">
        <el-form :model="packingForm" inline :label-width="labelWidth">
          <el-form-item label="方案名称:">
            <div v-if="titles == '明细'">{{ packingForm.promotionName }}</div>
            <input v-else type="text" v-model="packingForm.promotionName" style="border:none;width:140px;background:#eee;height:35px;font-size:16px;padding-left:10px;font-weight: 700;" />
          </el-form-item>
          <el-form-item label="打包价:">
            <div v-if="titles == '明细'">{{ packingForm.saleMoney }}</div>
            <!-- <input v-else type="number"  v-model="packingForm.saleMoney" style="border:none;width:140px;background:#eee;height:35px;font-size:14px;padding-left:10px;font-weight: 500;"> -->
            <div v-else style="width:140px">{{ packingForm.saleMoney }}</div>
          </el-form-item>
          <el-form-item label="方案总价:">
            <div style="width:60px">{{ packingForm.totalMoney }}</div>
          </el-form-item>
          <br />
          <el-form-item label="开始日期:">
            <div v-if="titles == '明细'">{{ packingForm.beginDate }}</div>

            <div v-else class="block">
              <el-date-picker v-model="packingForm.beginDate" :picker-options="pickerOptionsStart" value-format="yyyy-MM-dd 00:00:00" format="yyyy-MM-dd" type="date" placeholder="开始日期"></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="结束日期:">
            <div v-if="titles == '明细'">{{ packingForm.endDate }}</div>

            <div v-else class="block">
              <el-date-picker v-model="packingForm.endDate" :picker-options="pickerOptionsEnd" value-format="yyyy-MM-dd 23:59:59" format="yyyy-MM-dd" type="date" placeholder="结束日期"></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="现付提成:">
            <div v-if="titles == '明细'">{{ packingForm.salesCommission }}</div>

            <input v-else type="text" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,3})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,3}" v-model="packingForm.salesCommission" style="border:none;width:50px;background:#eee;height:35px;font-size:14px;padding-left:10px;" />
          </el-form-item>
          <el-form-item label="卡付提成:">
            <div v-if="titles == '明细'">
              {{ packingForm.cardSalesCommission }}
            </div>

            <input v-else type="text" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,3})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,3}" v-model="packingForm.cardSalesCommission" style="border:none;width:50px;background:#eee;height:35px;font-size:14px;padding-left:10px;" />
          </el-form-item><br />
          <el-form-item label="适用对象:">
            <div>
              <div v-if="titles == '明细'" style="width:280px;">
                <span v-show="packingForm.suitableObject == 0">全部会员</span><span v-show="packingForm.suitableObject == 1">生日会员</span><span class="text-cyan" v-show="packingForm.suitableObject == 2" @click="openSuitMember(packingForm)">指定会员</span>
              </div>
              <el-radio-group v-else v-model="packingForm.suitableObject" style="font-size:14px">
                <el-radio :label="0">所有会员</el-radio>
                <!-- <el-radio :label="1">生日会员</el-radio> -->
                <el-radio :label="2">指定会员</el-radio>
                <el-button :disabled="!(packingForm.suitableObject == 2)" size="mini" type="text" @click="openSuitMember(packingForm)"><span>会员列表</span></el-button>
              </el-radio-group>
            </div>
          </el-form-item>
          <el-form-item label="是否限购">
            <div style="width:280px;">
              <div v-if="titles == '明细'">
                <span v-if="packingForm.limitBuy == 1">限购{{ packingForm.limitCount }}</span><span v-else>不限购</span>
              </div>
              <el-radio-group v-else v-model="packingForm.limitBuy" style="font-size:14px">
                <el-radio :label="0">不限购</el-radio>
                <el-radio :label="1">限购</el-radio>
                <input oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" v-show="packingForm.limitBuy == 1" type="number" v-model="packingForm.limitCount" style="border:none;width:50px;border-bottom:1px solid #333;margin-right:10px" /><span v-show="packingForm.limitBuy == 1">包数</span>
              </el-radio-group>
            </div>
          </el-form-item>
          <el-form-item label="适用门店:" rop="suitableObject" :rules="{
              required: true,
              message: '请选择适用门店',
              trigger: 'blur'
            }">
            <div>
              <div v-if="titles=='明细'">
                <span v-show="packingForm.suitableStore==0">全部门店</span><span v-show="packingForm.suitableStore==1" @click="openSuitStore(packingForm)">指定门店</span>
              </div>
              <el-radio-group v-else v-model="packingForm.suitableStore" style="font-size:14px">
                <el-radio :label="0">所有门店</el-radio>
                <el-radio :label="1">指定门店</el-radio>
                <el-button :disabled="!(packingForm.suitableStore === 1)" size="mini" type="text" @click="openSuitStore(packingForm)"><span>门店列表</span></el-button>
              </el-radio-group>
            </div>
          </el-form-item>
          <el-form-item v-if="titles == '明细'" label="允许卡付:">
            <span v-show="packingForm.cardBuy == 1">允许卡付</span><span v-show="packingForm.cardBuy == 0">不允许卡付</span>
          </el-form-item>
          <el-form-item v-else label="允许卡付:">
            <el-radio-group v-model="packingForm.cardBuy" style="font-size:14px">
              <el-radio :label="1">允许卡付</el-radio>
              <el-radio :label="0">不允许卡付</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <el-form-item v-show="titles=='明细'&&packingForm.cardBuy==1" label="能否打折:" >
            <span v-if="packingForm.cardLimit ==1">卡付允许打折</span><span v-else>卡付不允许打折</span>
          </el-form-item>
          <el-form-item v-show="titles!='明细'&&packingForm.cardBuy==1" label="能否打折:" >
            <el-radio-group v-model="packingForm.cardLimit" style="font-size:14px">
              <el-radio :label="1">卡付允许打折</el-radio>
              <el-radio :label="0">卡付不允许打折</el-radio>
            </el-radio-group>
          </el-form-item> -->
          <div style="width:840px;margin-left:30px">
            <el-button v-show="titles != '明细'" size="mini" type="primary" @click="editPro(projectText = '添加')">添加</el-button>
            <el-table :data="packingForm.promotionProjectLists" :header-cell-style="{
                background: 'linear-gradient(#6cb3ff, #1873d4)',
                color: '#eeeeee'
              }" style="margin-top:10px">
              <el-table-column prop="projectNum" label="项目编码" align="center" min-width="90">
                <template slot-scope="scope">
                  <div v-if="titles == '明细'">{{ scope.row.projectNum }}</div>
                  <div v-else @click="
                      editPro(
                       editIndex = scope.$index,
                        (projectText = '修改')
                      )
                    " style="cursor: pointer;">
                    {{ scope.row.projectNum }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="projectName" label="项目名称" :show-overflow-tooltip="true" align="center" min-width="120">
                <template slot-scope="scope">
                  <div v-if="titles == '明细'">{{ scope.row.projectName }}</div>
                  <div v-else @click="
                      editPro(
                        editIndex = scope.$index,
                        (projectText = '修改')
                      )
                    " style="cursor: pointer; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                    {{ scope.row.projectName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="priceMember" label="标准价" align="center" width="80"></el-table-column>
              <el-table-column prop="times" label="次数" align="center" min-width="80">
                <template slot-scope="scope">
                  <div v-if="titles == '明细'">{{ scope.row.times }}</div>
                  <div v-else>
                    <div v-if="timesIndex!=scope.$index" style="cursor: pointer;" @click="editRow(scope.row,scope.$index,timesIndex =scope.$index) ">
                      {{ scope.row.times }}
                    </div>
                    <el-input type="number" class="form-input-wdith-xs" v-focus v-else oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*\.?[0-9]{0,3}" v-model="scope.row.times" @blur="endEditNumber(scope.row)"></el-input>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="" label="标准金额" align="center" min-width="80">
                <template slot-scope="scope">
                  {{scope.row.times&&scope.row.priceMember?(scope.row.times*scope.row.priceMember).toFixed(2)*1:0}}
                </template>
              </el-table-column>
              <el-table-column prop="" label="活动金额" align="center" min-width="80" fixed="right">
                <template slot-scope="scope">
                  <div v-if="totalMoneyIndex != scope.$index" style="cursor: pointer;" @click="editRow(scope.row,scope.$index,totalMoneyIndex = scope.$index)">
                    {{ scope.row.projectTotalMoney }}
                    <i class="el-icon-edit text-cyan"></i>
                  </div>
                  <el-input type="number" class="form-input-wdith-xs" v-focus v-else oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" v-model="scope.row.projectTotalMoney" @blur="endEditMoney(scope.row)"></el-input>
                </template>
              </el-table-column>
              <el-table-column align="center" fixed="right" label="操作" width="160" v-if="titles != '明细'">
                <template slot-scope="scope">
                  <el-button size="mini" type="primary" @click="
                      editPro(
                        scope.$index,
                        (projectText = '修改')
                      )
                    ">修改</el-button>
                  <el-button size="mini" type="primary" plain @click="delProject(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
              <el-table-column prop="typeInfo" label="有效类型" align="center" width="215">
                <template slot-scope="scope">
                      <el-radio v-model="scope.row.typeInfo" label="1" @change="typeChange(scope.row)">有效期(月)</el-radio>
                      <el-radio v-model="scope.row.typeInfo" label="2" @change="typeChange(scope.row)">截止日期</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="日期操作" align="center" width="200">
                <template slot-scope="scope">
                  <div v-if="scope.row.typeInfo == 1">
                    <el-input v-model="scope.row.validTime" placeholder="有效日期(月)" style="width:150px"></el-input>
                  </div>
                  <div v-else>                   
                    <el-date-picker 
                     v-model="scope.row.useEndDate"
                     type="date"
                     format="yyyy-MM-dd"
                     value-format="yyyy-MM-dd" 
                     placeholder="选择截止日期">
                   </el-date-picker>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div style="width:100%;background:#eee;display: flex;justify-content:space-between;font-size:14px;line-height:40px">
              <span style="margin-left:20px">总价格</span>
              <span style="margin-right:185px">¥{{ projectPriceSum }}</span>
            </div>
          </div>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button v-show="editDialog" size="mini" type="primary" plain @click="(editDialog = false), (formDialog = false)">取 消</el-button>
        <el-button v-show="copyDialog" size="mini" type="primary" plain @click="(copyDialog = false), (formDialog = false)">取 消</el-button>
        <el-button v-show="editDialog" size="mini" type="primary" @click="endEditForm((editDialog = false), (formDialog = false))">修改</el-button>
        <el-button v-show="copyDialog" size="mini" type="primary" @click="endCopyForm((copyDialog = false), (formDialog = false))">复制</el-button>
      </div>
    </el-dialog>
    <el-dialog title="搜索" :visible.sync="searchDialog">
      <el-form :model="searchForm">
        <el-form-item label="方案编码搜索:" label-width="120px">
          <div class="searchDiv">
            <el-input size="medium" v-model="searchForm.promotionNum" placeholder="输入要查询的方案编码" clearable></el-input>
          </div>
        </el-form-item>
        <el-form-item label="方案名称搜索:" label-width="120px">
          <div class="searchDiv">
            <el-input size="medium" v-model="searchForm.promotionName" placeholder="输入要查询的方案名称" clearable></el-input>
          </div>
        </el-form-item>
        <el-form-item label="创建日期搜索:" label-width="120px">
          <div class="changeDate">
            <el-date-picker @change="changeDate" size="large" v-model="date" type="daterange" align="center" :default-time="['00:00:01', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
            </el-date-picker>
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" plain @click="searchDialog = false">取 消</el-button>
        <el-button type="primary" size="mini" @click="search((searchDialog = false))">确 定</el-button>
      </span>
    </el-dialog>
    <suit ref="suit" @suitData="suitData"></suit>
    <project ref="project" @projectData="projectData"></project>
    <membersuit ref="membersuit" @membersuitData="membersuitData"></membersuit>
  </div>
</template>

<script>
import {
  addPromotion,
  promotionPage,
  editPromotion,
  promotionAudit,
  promotionRevokeAudit,
  promotionSendAudit,
  promotionUnAudit,
  promotionPush,
  promotionProList,
  promotionShutDown,
} from "@/api/promotion.js";
import { partten } from "../../../../partten/index";
import suit from "../components/suit";
import membersuit from "../components/memberSuit";
import project from "@/components/project/index";
export default {
  components: { suit, project, membersuit },
  data() {
    return {
      pickerOptionsStart: {
        disabledDate: (time) => {
          time.getTime() < new Date().getTime() - 24 * 60 * 60 * 1000;
        },
      },
      pickerOptionsEnd: {
        disabledDate: (time) => {
          let beginDateVal = this.packingForm.beginDate;
          if (beginDateVal) {
            return (
              time.getTime() <
              new Date(beginDateVal).getTime() - 1 * 60 * 60 * 1000
            );
          }
        },
        // selectableRange 用来限制时分秒的选择，这里要求只能选择当前时间之后到0点的时间点 但应该只限今天
        selectableRange: "00:00:00 - 23:59:59",
      },
      listDialogFormVisible: false, //新建方案弹窗开关
      formDialog: false, //审核复制修改弹窗开关
      editDialog: false, //是否修改
      detailDialog: false, //是否明细
      copyDialog: false, //是否复制
      refreshtext: false, //搜索判断字符
      searchDialog: false, //搜索弹窗开关
      pageNum: 1, // 当前页码
      pageSize: 10, // 每页的数据条数,
      titles: "", //次级弹窗标题
      labelWidth: "100px", //表单label宽度
      radioRowValue: "", //列表选择值
      radioRowValueList: {}, //选择列表对象
      packingForm: {
        //方案表单
        promotionName: "",
        saleMoney: 0,
        beginDate: "2020-12-1",
        endDate: "2020-12-30",
        suitableObject: 0,
        limitBuy: 1,
        limitCount: 100,
        salesCommission: 0.15,
        cardSalesCommission: 0.12,
        promotionProjectLists: [],
        cardBuy: 1,
        cardLimit: 0,
      },
      projectPriceSum: 0, //方案总价
      pageInfoPro: {
        total: 0, //分页总条数
        pageNum: 1,
        pageSize: 10,
        projectList: [],
      },
      pageInfo: {
        total: 0, //分页总条数 // 总条数
        schemeList: [],
      },
      editIndex: -1, //编辑行的内容下标
      searchTrue: false, //搜索判断
      searchForm: {
        //搜索表单
        promotionName: "",
        promotionNum: "",
        startTime: "",
        endTime: "",
      },
      sumIndex: -1, //是否重新合计总价
      date: [], //时间组件默认
      totalMoneyIndex: -1, //修改总金额:下标
      timesIndex: -1, //修改次数:下标
      projectText: "添加", //添加修改项目标识
      pickerOptions: {
        //组件限制方法
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  methods: {
    typeChange(row){
      if(row.typeInfo == '1'){
        row.useEndDate = null
      }else{
        row.validTime = null
      }
    },
    //打开项目单选弹窗
    editPro() {
      this.$refs.project.show(0);
    },
    //项目单选返回
    projectData(form) {
      form = {...form,typeInfo:"1"}
      form.projectId = form.id;
      form.times = form.minumumTimes;
      form.projectTotalMoney =
        (form.priceMember * form.minumumTimes).toFixed(2) * 1;
      var info = true;
      if (this.projectText == "添加") {
        if (this.packingForm.promotionProjectLists.length > 0) {
          this.packingForm.promotionProjectLists.forEach((item) => {
            if (form.id == item.id) {
              this.$message.info({
                message: "该项目已在表中存在,无需添加,请直接修改次数!",
              });
              info = false;
            }
          });
          if (info) {
            this.packingForm.promotionProjectLists.push(form);
            this.sumsNUmber(1);
            form = {};
          }
        } else {
          this.packingForm.promotionProjectLists.push(form);
          this.sumsNUmber(1);
          form = {};
        }
      } else {
        this.packingForm.promotionProjectLists.forEach((item) => {
          if (form.id == item.id) {
            this.$message.info({
              message: "该项目已在表中存在,无需添加,请直接修改次数!",
            });
            return (info = false);
          }
        });
        if (info) {
          this.packingForm.promotionProjectLists.splice(
            this.editIndex,
            1,
            form
          );
          this.sumsNUmber(1);
        }
      }
    },
    //删除项目
    delProject(index) {
      if (this.packingForm.promotionProjectLists.length > 1) {
        this.packingForm.promotionProjectLists.splice(index, 1);
        this.sumsNUmber(1);
      } else {
        this.$message.info({ message: "最少要有一个项目!" });
      }
    },
    //打开指定门店弹窗
    openSuitStore(row) {
      this.$refs.suit.show(row);
    },
    //指定门店返回
    suitData(v) {
      let list = [];
      v.forEach((item) => {
        if (item.id) {
          item.storeId = item.id;
          list.push(item);
        }
      });
      this.packingForm.promotionStores = list;
    },
    //打开指定会员弹窗
    openSuitMember(row) {
      this.$refs.membersuit.show(row);
    },
    //指定会员返回
    membersuitData(v) {
      let list = [];
      v.forEach((item) => {
        if (item.id) {
          item.memberId = item.id;
          list.push(item);
        }
      });
      this.packingForm.promotionMemberLists = list;
    },
    //时间改变方法
    //时间改变方法
    changeDate() {
      this.searchForm.startTime = this.date[0];
      this.searchForm.endTime = this.date[1];
    },
    //搜索方法
    search() {
      //条件搜索
      this.searchForm.pageNum = this.pageNum;
      this.searchForm.pageSize = this.pageSize;
      this.searchForm.type = 0;
      promotionPage(this.searchForm).then((res) => {
        if ((res.code = "000000")) {
          this.refreshtext == true;
          res.pageInfo.list.forEach((item) => {
            let date = item.endDate.replace(/\-/g, "/");
            if (partten.dates > date) {
              item.endPromotion = 1;
            } else {
              item.endPromotion = 0;
            }
          });
          res.pageInfo.schemeList = res.pageInfo.list;
          this.pageInfo = res.pageInfo;
          if (res.pageInfo.total == 0) {
            this.$message.warning({ message: "没有找到符合条件的方案" });
          }
        } else {
          this.$message.error({ message: res.message });
        }
      });
    },

    //创建方案
    newProjet() {
      this.$refs["packingForm"].validate(async (valid) => {
        if (valid) {
          let promotionProjectLists = [];
          this.packingForm.cardLimit = 0;
          this.packingForm.promotionProjectLists.forEach((item) => {
            if (item.cardBuy == null || item.cardBuy == undefined) {
              item.cardBuy = 0;
            }
            let items = {
              storeId: item.storeId,
              storeName: item.storeName,
              projectId: item.id,
              projectNum: item.projectNum,
              projectName: item.projectName,
              priceMember: item.priceMember,
              times: item.times,
              projectTotalMoney: item.projectTotalMoney,
              promotionName: this.packingForm.promotionName,
              standardTimes: item.standardTimes,
              type: 0,
              typeInfo:item.typeInfo,
              validTime:item.validTime,
              useEndDate:item.useEndDate
            };
            promotionProjectLists.push(items);
          });

          if (this.packingForm.cardBuy == 0) {
            this.packingForm.cardSalesCommission = 0;
          }
          this.packingForm.promotionProjectLists = [];
          this.packingForm.promotionProjectLists = promotionProjectLists;
          this.packingForm.type = 0;
          // this.packingForm.promotionProjectLists.forEach(item => {
          //   delete item.ids;
          // });
          addPromotion(this.packingForm).then((res) => {
            this.listDialogFormVisible = false;
            if (res.code == "000000") {
              this.$message.success({ message: res.message });
              this.promotionPage();
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });
        }
      });
    },
    //打开修改次数/活动金额
    editRow(row, index) {
      this.sumIndex = index;
      let form = JSON.parse(JSON.stringify(row));
      this.packingForm.promotionProjectLists.splice(index, 1, form);
    },
    //关闭修改次数
    endEditNumber(row) {
      if (!row.times) {
        row.times = 1;
      }
      this.timesIndex = -1;
      this.sumsNUmber();
    },
    //关闭修改总金额
    endEditMoney(row) {
      row.projectTotalMoney = row.projectTotalMoney * 1;
      this.totalMoneyIndex = -1;
      this.sumsNUmber(1);
    },
    //点击选中
    rowClick(row) {
      this.radioRowValue = row.id;
      this.radioRowValueList = row;
      //console.log(row);
    },
    //双击方法
    rowDbClick() {
      this.detail();
    },
    //明细方法
    detail() {
      this.titles = "明细";
      promotionProList({ id: this.radioRowValueList.id }).then((res) => {
        res.rows.forEach(item=>{
          item.typeInfo += ''
        })
        this.packingForm = { promotionProjectLists: [] };
        this.packingForm = { ...this.radioRowValueList };
        this.packingForm.promotionProjectLists = res.rows;
        this.formDialog = true;
        this.detailDialog = true;
      });
      this.sumsNUmber();
    },
    //修改
    editForm() {
      this.titles = "修改";
      promotionProList({ id: this.radioRowValueList.id }).then((res) => {
        res.rows.forEach(item=>{
          item.typeInfo += ''
        })
        this.packingForm = { promotionProjectLists: [] };
        this.packingForm = { ...this.radioRowValueList };
        this.packingForm.promotionProjectLists = res.rows;
        this.formDialog = true;
        this.editDialog = true;
      });
      this.sumsNUmber();
    },
    //保存修改方法
    endEditForm() {
      //console.log(this.promotionMemberLists);
      let promotionProjectLists = [];
      this.packingForm.promotionProjectLists.forEach((item) => {
        let items = {
          storeId: item.storeId,
          storeName: item.storeName,
          projectNum: item.projectNum,
          projectName: item.projectName,
          priceMember: item.priceMember,
          standardTimes: item.standardTimes,
          times: item.times,
          projectTotalMoney: item.projectTotalMoney,
          promotionName: this.packingForm.promotionName,
          type: 0,
          typeInfo:item.typeInfo,
          validTime:item.validTime,
          useEndDate:item.useEndDate
        };
        if (item.projectId != undefined) {
          items.projectId = item.projectId;
        } else {
          items.projectId = item.id;
        }
        promotionProjectLists.push(items);
      });

      if (this.packingForm.cardBuy == 0) {
        this.packingForm.cardSalesCommission = 0;
      }
      this.packingForm.promotionProjectLists = promotionProjectLists;
      //console.log(this.packingForm);
      editPromotion(this.packingForm).then((res) => {
        if (res.code == "000000") {
          this.$message.success({ message: res.message });
          this.radioRowValueList.state = 1;
          this.promotionPage();
          this.radioRowValue = "";
          this.radioRowValueList = {};
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //送审
    sendAndit() {
      promotionSendAudit({
        id: this.radioRowValueList.id,
        state: this.radioRowValueList.state,
      }).then((res) => {
        //console.log(res);
        if (res.code == "000000") {
          this.$message.success({ message: res.message });
          this.radioRowValueList.state = 2;
          this.promotionPage();
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //回收
    recycle() {
      this.$confirm("方案回收后需进行修改才能再次送审, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        cancelButtonClass: "cancelbtnFalses",
        confirmButtonClass: "confirmbtnFalses",
      }).then(() => {
        promotionRevokeAudit({
          id: this.radioRowValueList.id,
          state: this.radioRowValueList.state,
        }).then((res) => {
          //console.log(res);
          if (res.code == "000000") {
            this.$message.success({ message: res.message });
            this.radioRowValueList.state = 3;
            this.promotionPage();
          } else {
            this.$alert(res.message, "提示", {
              confirmButtonText: "确定",
              confirmButtonClass: "confirmbtnFalses",
              type: "warning",
              center: true,
              callback: (action) => {},
            });
          }
        });
      });
    },
    //审核
    audit(index, row) {
      this.$confirm("通过审核, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        cancelButtonClass: "cancelbtnFalses",
        confirmButtonClass: "confirmbtnFalses",
      })
        .then(() => {
          promotionAudit({ id: this.radioRowValueList.id }).then((res) => {
            //console.log(res);
            if (res.code == "000000") {
              this.$message.success({ message: res.message });
              this.radioRowValueList.state = 4;

              this.promotionPage();
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });
        })
        .catch(() => {
          this.$message.info({ message: "已取消操作！" });
        });
    },
    //反审核
    unAudit() {
      this.$confirm("反审核操作, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        cancelButtonClass: "cancelbtnFalses",
        confirmButtonClass: "confirmbtnFalses",
      })
        .then(() => {
          promotionUnAudit({ id: this.radioRowValueList.id }).then((res) => {
            //console.log(res);
            if (res.code == "000000") {
              this.$message.success({ message: res.message });
              this.radioRowValueList.state = 5;

              this.promotionPage();
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });
        })
        .catch(() => {
          this.$message.info({ message: "已取消操作！" });
        });
    },
    copyForm() {
      this.titles = "复制";
      promotionProList({ id: this.radioRowValueList.id }).then((res) => {
        res.rows.forEach(item=>item.typeInfo += '')
        this.packingForm = { promotionProjectLists: [] };
        this.packingForm = { ...this.radioRowValueList };
        this.packingForm.promotionProjectLists = res.rows;
        this.formDialog = true;
        this.copyDialog = true;
      });
    },
    endCopyForm() {
      let promotionProjectLists = [];
      this.packingForm.promotionProjectLists.forEach((item) => {
        //console.log(item);
        let items = {
          storeId: item.storeId,
          storeName: item.storeName,
          projectNum: item.projectNum,
          projectName: item.projectName,
          priceMember: item.priceMember,
          standardTimes: item.standardTimes,
          times: item.times,
          projectTotalMoney: item.projectTotalMoney,
          promotionName: this.packingForm.promotionName,
          type: 0,
          typeInfo:item.typeInfo,
          validTime:item.validTime,
          useEndDate:item.useEndDate
        };
        if (item.projectId != undefined) {
          items.projectId = item.projectId;
        } else {
          items.projectId = item.id;
        }

        promotionProjectLists.push(items);
      });

      this.packingForm.promotionProjectLists = promotionProjectLists;
      this.packingForm.endPromotion = 0;
      this.packingForm.promotionProjectLists.forEach((item) => {
        delete item.ids;
      });
      this.packingForm.cardLimit = 0;
      if (this.packingForm.cardBuy == 0) {
        this.packingForm.cardSalesCommission = 0;
      }
      this.packingForm.type = 0;
      addPromotion(Object.assign(this.packingForm,{pushCount:null,pushState:null})).then((res) => {
        //console.log(res);
        if (res.code == "000000") {
          this.$message.success({ message: res.message });
          this.promotionPage();
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //发布
    issue() {
      if (this.radioRowValueList.pushCount > 0) {
        this.$confirm(
          "信息已推送 " +
            this.radioRowValueList.pushCount +
            " 次 , 是否继续推送",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "info",
            cancelButtonClass: "cancelbtnFalses",
            confirmButtonClass: "confirmbtnFalses",
          }
        )
          .then(() => {
            promotionPush({
              id: this.radioRowValueList.id,
              pushCount: this.radioRowValueList.pushCount,
            }).then((res) => {
              if (res.code == "000000") {
                this.radioRowValueList.pushState = 1;

                this.$message.success({
                  message:
                    "推送成功，该活动信息目前已推送   " +
                    (this.radioRowValueList.pushCount + 1) +
                    " 次",
                });
                this.promotionPage();
                this.radioRowValueList.pushState = 1;
                this.radioRowValueList.pushCount =
                  this.radioRowValueList.pushCount + 1;
              } else {
                this.$alert(res.message, "提示", {
                  confirmButtonText: "确定",
                  confirmButtonClass: "confirmbtnFalses",
                  type: "warning",
                  center: true,
                  callback: (action) => {},
                });
              }
            });
          })
          .catch(() => {});
      } else {
        this.$confirm(
          "信息如发布后将会推送一次，即不可变更，是否继续发布？",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
            cancelButtonClass: "cancelbtnFalses",
            confirmButtonClass: "confirmbtnFalses",
          }
        )
          .then(() => {
            //console.log("发布");
            promotionPush({
              id: this.radioRowValueList.id,
              pushCount: this.radioRowValueList.pushCount,
            }).then((res) => {
              if (res.code == "000000") {
                this.radioRowValueList.pushState = 1;
                this.$message.success({
                  message: res.message + "，" + "信息已发布！",
                });
                this.promotionPage();
              } else {
                this.$alert(res.message, "提示", {
                  confirmButtonText: "确定",
                  confirmButtonClass: "confirmbtnFalses",
                  type: "warning",
                  center: true,
                  callback: (action) => {},
                });
              }
            });
          })
          .catch(() => {});
      }
    },
    //关闭
    close() {
      //console.log(this.radioRowValueList);
      promotionShutDown({
        id: this.radioRowValueList.id,
        pushState: this.radioRowValueList.pushState,
      }).then((res) => {
        if (res.code == "000000") {
          this.$message.success({ message: res.message });
          this.radioRowValueList.state = 6;
          this.promotionPage();
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },

    //合计计算
    sumsNUmber(number) {
      let num = 0;
      let totalMoney = 0;
      if (this.packingForm.promotionProjectLists.length > 0) {
        this.packingForm.promotionProjectLists.forEach((item, index) => {
          num += item.priceMember * 1 * item.times * 1;
          if (!number && this.sumIndex == index) {
            item.projectTotalMoney =
              (item.priceMember * item.times * 1).toFixed(2) * 1;
            this.sumIndex = -1;
          }
          totalMoney += item.projectTotalMoney * 1;
        });
        this.projectPriceSum = totalMoney.toFixed(2) * 1;
        this.packingForm.saleMoney = 0;
        this.packingForm.totalMoney = 0;
        this.packingForm.saleMoney = totalMoney.toFixed(2) * 1;
        this.packingForm.totalMoney = num.toFixed(2) * 1;
      }
    },
    handleClose(done) {
      this.$confirm("确认关闭？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        cancelButtonClass: "cancelbtnFalses",
        confirmButtonClass: "confirmbtnFalses",
      })
        .then(() => {
          done();
          if (this.editDialog == true) {
            this.editDialog = false;
          } else if (this.detailDialog == true) {
            this.detailDialog = false;
          } else {
            this.copyDialog = false;
          }
        })
        .catch(() => {});
    },
    //分页方法
    handleSizeChange(val) {
      //   //console.log(`每页 ${val} 条`);
      this.pageSize = val;
      if (this.searchTrue == true) {
        this.search();
      } else {
        this.promotionPage();
      }
    },
    handleCurrentChange(val) {
      //   //console.log(`当前页: ${val}`);
      this.pageNum = val;
      if (this.searchTrue == true) {
        this.search();
      } else {
        this.promotionPage();
      }
    },

    promotionPage() {
      var page = { type: 0, pageSize: this.pageSize, pageNum: this.pageNum };
      promotionPage(page).then((res) => {
        if ((res.code = "000000")) {
          if (this.refreshtext == true) {
            this.$message.success({ message: "已刷新最新数据" });
            this.refreshtext = false;
            this.searchTrue = false;
          }
          res.pageInfo.list.forEach((item) => {
            let date = item.endDate.replace(/\-/g, "/");
            if (partten.dates > date) {
              item.endPromotion = 1;
            } else {
              item.endPromotion = 0;
            }
          });
          res.pageInfo.schemeList = res.pageInfo.list;
          this.pageInfo = res.pageInfo;
        }
      });
    },
  },
  created() {
    this.sumsNUmber();
    let list = JSON.parse(sessionStorage.getItem("list"));
    list.forEach((item) => {
      if (item.id == 7001001) {
        this.promotionPage();
      }
    });
  },
};
</script>

<style>
.packing .el-date-editor.el-input,
.packing .el-date-editor.el-input__inner {
  width: 150px;
}
.changeDate .el-date-editor.el-input,
.changeDate .el-date-editor.el-input__inner {
  width: 240px;
}
.packing .el-radio-group input {
  height: 100%;
  padding-left: 5px;
}
.packing .el-table th {
  padding: 12px 0;
}
.packingRadioTable .el-radio__label {
  display: none;
}
.schemeListDiv .el-radio__label {
  display: none;
}
</style>
