index.vue 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355
  1. <template>
  2. <div class="app-container">
  3. <el-container>
  4. <!-- 左侧区域 -->
  5. <el-aside width="360px" class="left-aside">
  6. <!-- 顶部区域 -->
  7. <div class="left-header">
  8. <div class="left-header-top">
  9. <el-button type="primary" class="search-btn" @click="handleLeftQuery" v-hasPermi="['course:trainingCamp:list']">搜索</el-button>
  10. <el-button type="primary" style="width: 50%" icon="el-icon-plus" @click="handleAddTrainingCamp" v-hasPermi="['course:trainingCamp:add']">新建训练营</el-button>
  11. </div>
  12. <div class="search-input-wrapper">
  13. <el-input
  14. v-model="leftQueryParams.trainingCampName"
  15. placeholder="请输入训练营名称"
  16. prefix-icon="el-icon-search"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleLeftQuery"
  20. />
  21. </div>
  22. <div class="sort-wrapper">
  23. <span class="sort-label">排序方式</span>
  24. <el-select v-model="leftQueryParams.scs"
  25. placeholder="按序号倒序"
  26. size="small"
  27. class="sort-select"
  28. @change="handleSortChange"
  29. >
  30. <el-option label="按序号倒序" value="order_number(desc),training_camp_id(desc)" />
  31. <el-option label="按序号顺序" value="order_number(asc),training_camp_id(desc)" />
  32. </el-select>
  33. </div>
  34. </div>
  35. <!-- 训练营列表 -->
  36. <div class="camp-list" ref="campList" @scroll="handleScroll" v-loading="leftLoading">
  37. <div
  38. v-for="(item, index) in campList"
  39. :key="index"
  40. class="camp-item"
  41. :class="{ 'active': activeCampIndex === index }"
  42. @click="selectCamp(index)"
  43. >
  44. <div class="camp-content">
  45. <div class="camp-title">
  46. <i class="el-icon-s-flag camp-icon"></i>
  47. {{ item.trainingCampName }}
  48. </div>
  49. <div class="camp-info">
  50. <span>序号:{{ item.orderNumber }}</span>
  51. <span>最新营期开课:{{ item.recentDate || '-' }}</span>
  52. </div>
  53. <div class="camp-stats">
  54. <span class="stat-item">
  55. <i class="el-icon-s-data"></i>
  56. 营期数:{{ item.periodCount || 0 }}
  57. </span>
  58. <span class="stat-item">
  59. <i class="el-icon-user"></i>
  60. 会员总数:{{ item.vipCount || 0 }}
  61. </span>
  62. </div>
  63. </div>
  64. <div class="camp-actions">
  65. <el-button type="text" class="action-btn delete-btn" @click.stop="handleDeleteCamp(item)" v-hasPermi="['course:trainingCamp:remove']">删除</el-button>
  66. <!-- <el-button type="text" class="action-btn copy-btn" @click.stop="handleCopyCamp(item)" v-hasPermi="['course:trainingCamp:copy']">复制</el-button>-->
  67. <el-button type="text" class="action-btn copy-btn" @click.stop="handleEditCamp(item)" v-hasPermi="['course:trainingCamp:edit']">编辑</el-button>
  68. </div>
  69. </div>
  70. <!-- 底部加载更多提示 -->
  71. <div v-if="loadingMore" class="loading-more">
  72. <i class="el-icon-loading"></i>
  73. <span>加载中...</span>
  74. </div>
  75. <!-- 所有数据加载完毕提示 -->
  76. <div v-if="campList.length > 0 && !leftQueryParams.hasNextPage && !loadingMore" class="no-more-data">
  77. <span>—— 已加载全部训练营 ——</span>
  78. </div>
  79. </div>
  80. </el-aside>
  81. <!-- 右侧区域 -->
  82. <el-main>
  83. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  84. <el-form-item label="营期名称" prop="periodName">
  85. <el-input
  86. v-model="queryParams.periodName"
  87. placeholder="请输入营期名称"
  88. clearable
  89. size="small"
  90. @keyup.enter.native="handleQuery"
  91. />
  92. </el-form-item>
  93. <el-form-item label="公司" prop="companyIdList">
  94. <el-select v-model="queryParams.companyIdList" filterable placeholder="请选择公司" clearable size="small" multiple>
  95. <el-option
  96. v-for="item in companyOptions"
  97. :key="item.companyId"
  98. :label="item.companyName"
  99. :value="item.companyId"
  100. />
  101. </el-select>
  102. </el-form-item>
  103. <el-form-item label="开营日期开始" prop="periodStartingTime" label-width="120px">
  104. <el-date-picker clearable size="small" style="width: 200px"
  105. v-model="queryParams.periodStartingTime"
  106. type="date"
  107. value-format="yyyy-MM-dd"
  108. placeholder="请选择开营日期开始时间">
  109. </el-date-picker>
  110. </el-form-item>
  111. <el-form-item label="开营日期结束" prop="periodEndTime" label-width="120px">
  112. <el-date-picker clearable size="small" style="width: 300px"
  113. v-model="queryParams.periodEndTime"
  114. type="date"
  115. value-format="yyyy-MM-dd"
  116. placeholder="请选择开营日期结束时间">
  117. </el-date-picker>
  118. </el-form-item>
  119. <el-form-item>
  120. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['course:period:list']">搜索</el-button>
  121. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  122. </el-form-item>
  123. </el-form>
  124. <el-row :gutter="10" class="mb8">
  125. <el-col :span="1.5">
  126. <el-button
  127. type="primary"
  128. plain
  129. icon="el-icon-plus"
  130. size="mini"
  131. @click="handleAdd"
  132. v-hasPermi="['course:period:add']"
  133. >新增</el-button>
  134. </el-col>
  135. <el-col :span="1.5">
  136. <el-button
  137. type="warning"
  138. plain
  139. icon="el-icon-download"
  140. size="mini"
  141. @click="handleExport"
  142. v-hasPermi="['course:period:export']"
  143. >导出</el-button>
  144. </el-col>
  145. <el-col :span="1.5">
  146. <el-button
  147. type="primary"
  148. plain
  149. icon="el-icon-edit"
  150. size="mini"
  151. @click="handleBatchSetRedPacket"
  152. v-hasPermi="['course:period:setRedPacket']"
  153. :disabled="batchSetRedPacketDisabled"
  154. >批量设置红包</el-button>
  155. </el-col>
  156. <el-col :span="1.5">
  157. <el-button
  158. type="primary"
  159. plain
  160. icon="el-icon-plus"
  161. size="mini"
  162. @click="handleAddExistCampPeriod"
  163. v-hasPermi="['course:period:add']"
  164. >复制现有营期</el-button>
  165. </el-col>
  166. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  167. </el-row>
  168. <el-table v-loading="loading" :data="periodList" @selection-change="handleSelectionChange" border>
  169. <el-table-column type="selection" width="55" align="center" />
  170. <el-table-column label="营期名称" align="center" prop="periodName" />
  171. <el-table-column label="公司名称" align="center" prop="companyName" />
  172. <el-table-column label="营期状态" align="center" prop="periodStatus" width="100" :formatter="periodStatusFormatter" />
  173. <el-table-column label="营期线" align="center" prop="periodLine" width="180" />
  174. <el-table-column label="开营开始时间" align="center" prop="periodStartingTime" width="180" />
  175. <el-table-column label="开营结束时间" align="center" prop="periodEndTime" width="180" />
  176. <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
  177. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  178. <template slot-scope="scope">
  179. <el-button
  180. size="mini"
  181. type="text"
  182. icon="el-icon-edit"
  183. @click="handleUpdate(scope.row)"
  184. v-hasPermi="['course:period:edit']"
  185. >修改</el-button>
  186. <!-- <el-button-->
  187. <!-- size="mini"-->
  188. <!-- type="text"-->
  189. <!-- icon="el-icon-edit"-->
  190. <!-- @click="handleCourse(scope.row)"-->
  191. <!-- v-hasPermi="['course:period:edit']"-->
  192. <!-- >课程管理</el-button>-->
  193. <!-- <el-button-->
  194. <!-- size="mini"-->
  195. <!-- type="text"-->
  196. <!-- icon="el-icon-money"-->
  197. <!-- @click="setRedPacket(scope.row)"-->
  198. <!-- >设置红包</el-button>-->
  199. <el-button
  200. size="mini"
  201. type="text"
  202. icon="el-icon-setting"
  203. @click="handlePeriodSettings(scope.row)"
  204. >营期相关设置</el-button>
  205. <el-button
  206. size="mini"
  207. type="text"
  208. icon="el-icon-circle-close"
  209. @click="handleClosePeriod(scope.row)"
  210. v-hasPermi="['course:period:close']"
  211. >结束营期</el-button>
  212. <el-button
  213. size="mini"
  214. type="text"
  215. icon="el-icon-delete"
  216. @click="handleDelete(scope.row)"
  217. v-hasPermi="['course:period:remove']"
  218. >删除</el-button>
  219. </template>
  220. </el-table-column>
  221. </el-table>
  222. <pagination
  223. v-show="total>0"
  224. :total="total"
  225. :page.sync="queryParams.pageNum"
  226. :limit.sync="queryParams.pageSize"
  227. @pagination="getList"
  228. />
  229. </el-main>
  230. </el-container>
  231. <!-- 添加或修改会员营期对话框-->
  232. <el-drawer :title="title" :visible.sync="open" size="700px" append-to-body>
  233. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  234. <el-form-item label="营期名称" prop="periodName">
  235. <el-input v-model="form.periodName" placeholder="请输入营期名称" />
  236. </el-form-item>
  237. <el-form-item label="公司" prop="companyId">
  238. <el-select v-model="form.companyId" placeholder="请选择公司" filterable clearable multiple>
  239. <el-option
  240. v-for="item in companyOptions"
  241. :key="item.companyId"
  242. :label="item.companyName"
  243. :value="item.companyId"
  244. />
  245. </el-select>
  246. </el-form-item>
  247. <el-form-item label="课程风格" prop="courseStyle">
  248. <image-upload v-model="form.courseStyle" :limit="1" />
  249. </el-form-item>
  250. <el-form-item label="直播间风格" prop="liveRoomStyle">
  251. <image-upload v-model="form.liveRoomStyle" :limit="1" />
  252. </el-form-item>
  253. <el-form-item label="课程LOGO" prop="courseLogo">
  254. <image-upload v-model="form.courseLogo" :limit="1" />
  255. </el-form-item>
  256. <!-- <el-form-item label="红包发放方式" prop="redPacketGrantMethod">-->
  257. <!-- <el-radio-group v-model="form.redPacketGrantMethod">-->
  258. <!-- <el-radio :label="1" >按课程</el-radio>-->
  259. <!-- <el-radio :label="2" >按营期</el-radio>-->
  260. <!-- </el-radio-group>-->
  261. <!-- </el-form-item>-->
  262. <el-form-item label="营期类型" prop="periodType">
  263. <el-radio-group v-model="form.periodType">
  264. <el-radio :label="1" >多课程</el-radio>
  265. <el-radio :label="2" >单课程</el-radio>
  266. </el-radio-group>
  267. </el-form-item>
  268. <el-form-item label="销售提前查看天数" prop="maxViewNum">
  269. <el-input-number :min="0" v-model="form.maxViewNum" style="width: 200px" />
  270. </el-form-item>
  271. <el-form-item label="开营日期" prop="periodStartingTime">
  272. <el-date-picker
  273. :style="{display: form.periodType == 1 ? '' : 'none !important'}"
  274. v-model="form.dateRange"
  275. @change="timeChange(1)"
  276. type="daterange"
  277. range-separator="至"
  278. start-placeholder="开始日期"
  279. end-placeholder="结束日期"
  280. value-format="yyyy-MM-dd"
  281. :picker-options="{}"
  282. :clearable="false"
  283. >
  284. </el-date-picker>
  285. <el-date-picker
  286. :disabled = "isDisabledDateRange"
  287. :style="{display: form.periodType == 2 ? '' : 'none !important'}"
  288. @change="timeChange(2)"
  289. v-model="form.date"
  290. type="date"
  291. value-format="yyyy-MM-dd"
  292. placeholder="选择日期"
  293. :picker-options="{}"
  294. :clearable="false"
  295. >
  296. </el-date-picker>
  297. </el-form-item>
  298. <el-form-item prop="periodLine">
  299. <span slot="label">
  300. 营期线
  301. <el-tooltip content="营期首次播放课程的日期" placement="top">
  302. <i class="el-icon-question" style="margin-left: 5px; color: #909399; cursor: help;"></i>
  303. </el-tooltip>
  304. </span>
  305. <el-date-picker
  306. v-model="form.periodLine"
  307. type="date"
  308. placeholder="请选择营期线"
  309. value-format="yyyy-MM-dd"
  310. :clearable="true">
  311. </el-date-picker>
  312. </el-form-item>
  313. </el-form>
  314. <div class="drawer-footer">
  315. <el-button type="primary" @click="submitForm">确 定</el-button>
  316. <el-button @click="cancel">取 消</el-button>
  317. </div>
  318. </el-drawer>
  319. <!-- 添加训练营对话框 -->
  320. <el-dialog :title="campForm.trainingCampId ? '修改训练营' : '新建训练营'" :visible.sync="campDialogVisible" width="500px" append-to-body>
  321. <el-form ref="campForm" :model="campForm" :rules="campRules" label-width="100px">
  322. <el-form-item label="训练营名称" prop="trainingCampName">
  323. <el-input v-model="campForm.trainingCampName" placeholder="请输入训练营名称" />
  324. </el-form-item>
  325. </el-form>
  326. <div slot="footer" class="dialog-footer">
  327. <el-button type="primary" @click="submitCampForm">确 定</el-button>
  328. <el-button @click="cancelCampForm">取 消</el-button>
  329. </div>
  330. </el-dialog>
  331. <!-- &lt;!&ndash; 添加或修改会员营期对话框&ndash;&gt;-->
  332. <!-- <el-dialog title="课程管理" :visible.sync="course.open" width="75%" top="10px" append-to-body style="padding-bottom: 10px">-->
  333. <!-- <el-row :gutter="10" class="mb8">-->
  334. <!-- <el-col :span="1.5">-->
  335. <!-- <el-button-->
  336. <!-- v-if="(getDiff(course.row.periodStartingTime, course.row.periodEndTime) - course.total) > 0"-->
  337. <!-- type="primary"-->
  338. <!-- icon="el-icon-plus"-->
  339. <!-- size="mini"-->
  340. <!-- @click="handleAddCourse"-->
  341. <!-- v-hasPermi="['course:period:add']"-->
  342. <!-- >添加课程</el-button>-->
  343. <!-- </el-col>-->
  344. <!-- </el-row>-->
  345. <!-- <el-table v-loading="course.loading" :data="course.list">-->
  346. <!-- <el-table-column label="课程" align="center" prop="courseName" width="180" />-->
  347. <!-- <el-table-column label="小节" align="center" prop="videoName" />-->
  348. <!-- <el-table-column label="营期时间" align="center" prop="dayDate" width="150" />-->
  349. <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="150" />-->
  350. <!-- </el-table>-->
  351. <!-- <div slot="footer" class="dialog-footer">-->
  352. <!--&lt;!&ndash; <el-button type="primary" @click="saveCourseData">保存</el-button>&ndash;&gt;-->
  353. <!-- </div>-->
  354. <!-- </el-dialog>-->
  355. <!-- 添加课程对话框-->
  356. <el-dialog title="添加课程" :visible.sync="course.addOpen" width="500px" append-to-body>
  357. <el-form ref="courseAddForm" :model="course.form" :rules="courseAddRules" label-width="100px">
  358. <el-form-item label="课程" prop="courseId">
  359. <el-select filterable v-model="course.form.courseId" placeholder="请选择课程" clearable size="small" @change="courseChange(course.form.courseId)" style="width: 100%" :value-key="'dictValue'">
  360. <el-option
  361. v-for="dict in courseList"
  362. :key="dict.dictValue"
  363. :label="dict.dictLabel"
  364. :value="parseInt(dict.dictValue)"
  365. />
  366. </el-select>
  367. </el-form-item>
  368. <el-form-item label="小节" prop="videoIds">
  369. <el-select filterable v-model="course.form.videoIds" placeholder="请选择小节" :multiple-limit="getDiff(course.row.periodStartingTime, course.row.periodEndTime) - course.total" multiple clearable size="small" style="width: 100%" :value-key="'dictValue'">
  370. <el-option
  371. v-for="dict in videoList"
  372. :key="dict.dictValue"
  373. :label="dict.dictLabel"
  374. :value="parseInt(dict.dictValue)"
  375. />
  376. </el-select>
  377. </el-form-item>
  378. <el-form-item label="看课时间" prop="timeRange">
  379. <el-time-picker
  380. is-range
  381. v-model="course.form.timeRange"
  382. :picker-options="{
  383. selectableRange: '00:00:00 - 23:59:59'
  384. }"
  385. range-separator="至"
  386. start-placeholder="开始时间"
  387. value-format="HH:mm:ss"
  388. end-placeholder="结束时间">
  389. </el-time-picker>
  390. </el-form-item>
  391. <el-form-item v-if="joinTimeSwitch" label="领取红包时间" prop="lastJoinTime">
  392. <el-time-picker
  393. v-model="course.form.joinTime"
  394. value-format="HH:mm:ss"
  395. placeholder="选择时间范围">
  396. </el-time-picker>
  397. <p style="color: red;margin: 0;font-size: 12px">超过领取红包时间,只允许看课,不允许领取红包</p>
  398. </el-form-item>
  399. </el-form>
  400. <div slot="footer" class="dialog-footer">
  401. <el-button type="primary" @click="submitCourseForm">确 定</el-button>
  402. <el-button @click="closeAddCourse">取 消</el-button>
  403. </div>
  404. </el-dialog>
  405. <el-dialog title="修改看课时间" :visible.sync="updateCourse.open" width="600px" append-to-body>
  406. <el-form ref="courseUpdateForm" :model="updateCourse.form" :rules="courseUpdateRules" label-width="100px">
  407. <el-form-item label="看课时间" prop="timeRange" label-width="110px">
  408. <el-date-picker
  409. v-model="updateCourse.form.timeRange"
  410. type="datetimerange"
  411. range-separator="至"
  412. start-placeholder="开始时间"
  413. end-placeholder="结束时间"
  414. value-format="yyyy-MM-dd HH:mm:ss"
  415. :default-time="['00:00:00', '23:59:59']"
  416. :picker-options="{
  417. shortcuts: [{
  418. text: '今天',
  419. onClick(picker) {
  420. const end = new Date();
  421. const start = new Date();
  422. picker.$emit('pick', [start, end]);
  423. }
  424. }]
  425. }"
  426. >
  427. </el-date-picker>
  428. </el-form-item>
  429. <el-form-item v-if="joinTimeSwitch" label="领取红包时间" prop="joinTime" label-width="110px">
  430. <el-date-picker
  431. v-model="updateCourse.form.joinTime"
  432. type="datetime"
  433. placeholder="选择时间"
  434. value-format="yyyy-MM-dd HH:mm:ss"
  435. :default-time="'23:59:59'"
  436. >
  437. </el-date-picker>
  438. <p style="color: red;margin: 0;font-size: 12px">超过领取红包时间,只允许看课,不允许领取红包</p>
  439. </el-form-item>
  440. </el-form>
  441. <div slot="footer" class="dialog-footer">
  442. <el-button type="primary" @click="submitUpdateCourseForm">确 定</el-button>
  443. <el-button @click="closeUpdateCourse">取 消</el-button>
  444. </div>
  445. </el-dialog>
  446. <el-dialog title="修改营期时间" :visible.sync="updatePeriodDate.open" width="500px" append-to-body>
  447. <el-form ref="courseUpdateForm" :model="updatePeriodDate.form" label-width="100px">
  448. <el-form-item label="营期时间" prop="dayDate">
  449. <el-date-picker
  450. v-model="updatePeriodDate.form.dayDate"
  451. :selectableRange="updatePeriodDate.form.dayDate"
  452. value-format="yyyy-MM-dd"
  453. type="date"
  454. placeholder="选择日期">
  455. </el-date-picker>
  456. </el-form-item>
  457. </el-form>
  458. <div slot="footer" class="dialog-footer">
  459. <el-button type="primary" @click="updatePeriodDateSubmit">确 定</el-button>
  460. <el-button @click="updatePeriodDate.open = false">取 消</el-button>
  461. </div>
  462. </el-dialog>
  463. <!-- <red-packet-->
  464. <!-- :visible.sync="redPacketVisible"-->
  465. <!-- :periodId="currentRedPacketData.periodId"-->
  466. <!-- :videoId="currentRedPacketData.videoId"-->
  467. <!-- @success="handleRedPacketSuccess"-->
  468. <!-- />-->
  469. <!-- 营期相关设置抽屉 -->
  470. <el-drawer
  471. title="营期相关设置"
  472. :visible.sync="periodSettingsVisible"
  473. direction="rtl"
  474. size="74%"
  475. :destroy-on-close="true"
  476. append-to-body
  477. custom-class="period-settings-drawer"
  478. >
  479. <div class="drawer-content" style="margin-left: 25px">
  480. <el-tabs v-model="activeTab" @tab-click="handleTabClick">
  481. <el-tab-pane label="课程管理" name="course">
  482. <el-row :gutter="10" class="mb8">
  483. <el-col :span="1.5">
  484. <el-button
  485. v-if="(getDiff(periodSettingsData.periodStartingTime, periodSettingsData.periodEndTime) - course.total) > 0"
  486. type="primary"
  487. icon="el-icon-plus"
  488. size="mini"
  489. @click="handleAddCourse"
  490. v-hasPermi="['course:period:addCourse']"
  491. >添加课程</el-button>
  492. </el-col>
  493. <!-- <el-col :span="1.5">-->
  494. <!-- <el-button-->
  495. <!-- type="primary"-->
  496. <!-- size="mini"-->
  497. <!-- :disabled="updateCourse.ids.length <= 0"-->
  498. <!-- @click="handleUpdatePeriodDate"-->
  499. <!-- >修改营期时间</el-button>-->
  500. <!-- </el-col>-->
  501. <el-col :span="1.5">
  502. <el-button
  503. type="primary"
  504. size="mini"
  505. :disabled="updateCourse.ids.length <= 0"
  506. @click="handleUpdateCourse"
  507. v-hasPermi="['course:period:updateCourseTime']"
  508. >修改看课时间</el-button>
  509. </el-col>
  510. <el-col :span="1.5">
  511. <el-button
  512. type="warning"
  513. size="mini"
  514. icon="el-icon-delete"
  515. :disabled="updateCourse.ids.length <= 0"
  516. @click="handleDeleteCourse"
  517. v-hasPermi="['course:period:dayRemove']"
  518. >删除课程</el-button>
  519. </el-col>
  520. </el-row>
  521. <el-table ref="courseTable" v-loading="course.loading" :data="course.list" @selection-change="handleSelectionCourseChange" border>
  522. <el-table-column type="selection" width="55" align="center" />
  523. <el-table-column label="课程" align="center" prop="courseName" width="180" />
  524. <el-table-column label="小节" align="center" prop="videoName" />
  525. <el-table-column label="开课状态" align="center" prop="status" width="100" :formatter="courseStatusFormatter" />
  526. <el-table-column label="营期时间" align="center" prop="dayDate" width="100"/>
  527. <el-table-column label="开始时间" align="center" prop="startDateTime" width="100">
  528. <!-- <template slot-scope="scope">-->
  529. <!-- <el-tag>{{scope.row.startDateTime}}</el-tag>-->
  530. <!-- </template>-->
  531. </el-table-column>
  532. <el-table-column label="结束时间" align="center" prop="endDateTime" width="100">
  533. <!-- <template slot-scope="scope">-->
  534. <!-- <el-tag type="success">{{parseTime(scope.row.endDateTime, '{h}:{i}:{s}')}}</el-tag>-->
  535. <!-- </template>-->
  536. </el-table-column>
  537. <el-table-column label="领取红包时间" align="center" prop="lastJoinTime" width="160">
  538. <template slot-scope="scope">
  539. <el-tag type="danger">{{scope.row.lastJoinTime}}</el-tag>
  540. </template>
  541. </el-table-column>
  542. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  543. <template slot-scope="scope">
  544. <el-button
  545. size="mini"
  546. type="text"
  547. icon="el-icon-top"
  548. @click="handleTop(scope.row)"
  549. v-hasPermi="['course:period:courseMove']"
  550. >上移</el-button>
  551. <el-button
  552. size="mini"
  553. type="text"
  554. icon="el-icon-bottom"
  555. @click="handleBottom(scope.row)"
  556. v-hasPermi="['course:period:courseMove']"
  557. >下移</el-button>
  558. <el-button
  559. size="mini"
  560. type="text"
  561. icon="el-icon-edit"
  562. @click="handleUpdateDate(scope.row)"
  563. >修改营期时间</el-button>
  564. <el-button
  565. size="mini"
  566. type="text"
  567. icon="el-icon-delete"
  568. @click="handleDeleteCourse(scope.row)"
  569. v-hasPermi="['course:period:dayRemove']"
  570. >删除课程</el-button>
  571. </template>
  572. </el-table-column>
  573. </el-table>
  574. <pagination
  575. v-show="course.total > 0"
  576. :total="course.total"
  577. :page.sync="course.queryParams.pageNum"
  578. :limit.sync="course.queryParams.pageSize"
  579. @pagination="getCourseList"
  580. style="height: 40px"
  581. />
  582. </el-tab-pane>
  583. <el-tab-pane label="公司列表" name="company">
  584. <red-packet
  585. :visible.sync="redPacketVisible"
  586. :activeTab="activeTab"
  587. :periodId="periodSettingsData.periodId"
  588. @success="handleRedPacketSuccess"
  589. />
  590. </el-tab-pane>
  591. <el-tab-pane label="课程统计" name="statistics">
  592. <course-statistics
  593. :periodId="periodSettingsData.periodId"
  594. :active="activeTab === 'statistics'"
  595. />
  596. </el-tab-pane>
  597. </el-tabs>
  598. </div>
  599. </el-drawer>
  600. <batch-red-packet
  601. :visible.sync="batchRedPacketVisible"
  602. :selected-data="selectedPeriods"
  603. @success="handleBatchRedPacketSuccess"
  604. />
  605. <el-dialog
  606. :title="addExistCampPeriodName"
  607. :visible.sync="addExistCampPeriod"
  608. width="1000px"
  609. append-to-body
  610. @close="handleDialogClose"
  611. >
  612. <el-form ref="createCampPeriodForm" :model="createCampPeriodForm" :rules="campRules" label-width="500px">
  613. <el-form-item label="营期创建方式" prop="campPeriodType">
  614. <el-radio-group v-model="createCampPeriodForm.campPeriodType" @change="handlePeriodTypeChange">
  615. <el-radio :label="1">从当前训练营复制</el-radio>
  616. <el-radio :label="2">从其他训练营复制</el-radio>
  617. <el-radio :label="3">我要新建一个训练营</el-radio>
  618. </el-radio-group>
  619. </el-form-item>
  620. <!-- 从当前训练营复制 -->
  621. <el-form-item
  622. v-if="createCampPeriodForm.campPeriodType === 1"
  623. label="选择当前营期"
  624. prop="periodId"
  625. >
  626. <el-select
  627. v-model="createCampPeriodForm.periodId"
  628. placeholder="请选择当前营期"
  629. clearable
  630. >
  631. <el-option
  632. v-for="item in currentCampPeriods"
  633. :key="item.periodId"
  634. :label="item.periodName"
  635. :value="item.periodId"
  636. />
  637. </el-select>
  638. </el-form-item>
  639. <!-- 从其他训练营复制 -->
  640. <el-form-item
  641. v-if="createCampPeriodForm.campPeriodType === 2"
  642. label="选择其他营期"
  643. prop="periodId"
  644. >
  645. <el-select
  646. v-model="createCampPeriodForm.trainingCampId"
  647. placeholder="请选择训练营"
  648. :loading="loadingNew"
  649. clearable
  650. filterable
  651. @change="handleTrainingCampChange"
  652. >
  653. <el-option
  654. v-for="item in trainingCampList"
  655. :key="item.trainingCampId"
  656. :label="item.trainingCampName"
  657. :value="item.trainingCampId"
  658. />
  659. </el-select>
  660. <el-select
  661. v-model="createCampPeriodForm.periodId"
  662. placeholder="请选择营期"
  663. :loading="loadingNew"
  664. clearable
  665. filterable
  666. >
  667. <el-option
  668. v-for="item in otherCampPeriods"
  669. :key="item.periodId"
  670. :label="item.periodName"
  671. :value="item.periodId"
  672. />
  673. </el-select>
  674. <div v-if="loadingNew" class="loading-text">
  675. <i class="el-icon-loading"></i> 加载中...
  676. </div>
  677. </el-form-item>
  678. <!-- 新建营期 -->
  679. <el-form-item
  680. v-if="createCampPeriodForm.campPeriodType === 3"
  681. label="新建营期名称"
  682. prop="trainingCampName"
  683. >
  684. <el-input
  685. v-model="createCampPeriodForm.trainingCampName"
  686. placeholder="请输入新训练营名称"
  687. style="width: 300px"
  688. maxlength="50"
  689. show-word-limit
  690. />
  691. </el-form-item>
  692. </el-form>
  693. <div slot="footer" class="dialog-footer">
  694. <el-button type="primary" @click="copySubmitCampForm" :loading="submitLoading">确 定</el-button>
  695. <el-button @click="cancelExistCampPeriod" :disabled="submitLoading">取 消</el-button>
  696. </div>
  697. </el-dialog>
  698. </div>
  699. </template>
  700. <script>
  701. import {addPeriod, delPeriod, exportPeriod, getPeriod, pagePeriod, updatePeriod, getDays, addCourse,delPeriodDay, updateCourseTime, updateCourseDate, updateListCourseData, periodCourseMove, closePeriod, batchAddCourseSections,copyExistCampPeriod, updateOrderNumber} from "@/api/course/userCoursePeriod";
  702. import {getCompanyList} from "@/api/company/company";
  703. import { listCamp, addCamp, editCamp, delCamp, copyCamp, getScreeningCampPeriod, updateCampOrderNumber} from "@/api/course/userCourseCamp";
  704. import { courseList,videoList } from '@/api/course/courseRedPacketLog'
  705. import RedPacket from './redPacket.vue'
  706. import BatchRedPacket from './batchRedPacket.vue'
  707. import CourseStatistics from './statistics.vue'
  708. import Da from "element-ui/src/locale/lang/da";
  709. import { getConfigByKey } from '@/api/system/config'
  710. import {listUserCourse} from "@/api/course/userCourse";
  711. export default {
  712. name: "Period",
  713. components: {
  714. RedPacket,
  715. BatchRedPacket,
  716. CourseStatistics
  717. },
  718. data() {
  719. return {
  720. // 遮罩层
  721. loading: true,
  722. updateDateOpen: false,
  723. // 左侧遮罩层
  724. leftLoading: true,
  725. // 选中数组
  726. ids: [],
  727. // 非单个禁用
  728. single: true,
  729. // 非多个禁用
  730. multiple: true,
  731. // 显示搜索条件
  732. showSearch: true,
  733. // 总条数
  734. total: 0,
  735. // 左侧总条数
  736. leftTotal: 0,
  737. // 会员营期表格数据
  738. periodList: [],
  739. // 左侧列表数据
  740. leftList: [],
  741. videoList: [],
  742. // 弹出层标题
  743. title: "",
  744. isDisabledDateRange: false, //是否禁用开营日期
  745. // 是否显示弹出层
  746. open: false,
  747. // 查询参数
  748. queryParams: {
  749. pageNum: 1,
  750. pageSize: 10,
  751. periodName: null,
  752. periodStartingTime: null,
  753. periodEndTime: null,
  754. companyIdList: []
  755. },
  756. // 左侧查询参数
  757. leftQueryParams: {
  758. pageNum: 1,
  759. pageSize: 10,
  760. hasNextPage: false,
  761. scs: 'order_number(desc),training_camp_id(desc)',
  762. trainingCampName: null
  763. },
  764. // 表单参数
  765. form: {},
  766. // 课程相关数据
  767. course: {
  768. open: false,
  769. row:{},
  770. list:[],
  771. queryParams: {
  772. pageNum: 1,
  773. pageSize: 10,
  774. },
  775. loading: true,
  776. total: 0,
  777. addOpen: false,
  778. form: {},
  779. },
  780. //修改营期时间参数
  781. updatePeriodDate: {
  782. open: false,
  783. loading: true,
  784. ids: [],
  785. form: {},
  786. },
  787. joinTimeSwitch:true,
  788. updateCourse: {
  789. open: false,
  790. loading: true,
  791. ids: [],
  792. form: {
  793. timeRange: null,
  794. joinTime: null
  795. },
  796. },
  797. // 表单校验
  798. rules: {
  799. periodName: [
  800. { required: true, message: '营期名称不能为空', trigger: 'blur' }
  801. ],
  802. companyId: [
  803. { required: true, message: '公司不能为空', trigger: 'change' }
  804. ],
  805. courseStyle: [
  806. { required: true, message: '课程风格不能为空', trigger: 'change' }
  807. ],
  808. // redPacketGrantMethod: [
  809. // { required: true, message: '红包发放方式不能为空', trigger: 'change' }
  810. // ],
  811. periodType: [
  812. { required: true, message: '营期类型不能为空', trigger: 'change' }
  813. ],
  814. maxViewNum: [
  815. { required: true, message: '销售可查看天数不能为空', trigger: 'blur' }
  816. ],
  817. periodStartingTime: [
  818. { required: true, message: '开营日期不能为空', trigger: 'change' }
  819. ]
  820. },
  821. // 公司选项
  822. companyOptions: [],
  823. // 训练营列表
  824. campList: [],
  825. // 激活的训练营索引
  826. activeCampIndex: null,
  827. // 训练营对话框是否显示
  828. campDialogVisible: false,
  829. courseList: false,
  830. // 训练营表单
  831. campForm: {
  832. trainingCampId: null,
  833. trainingCampName: ''
  834. },
  835. // 训练营表单校验
  836. campRules: {
  837. trainingCampName: [
  838. { required: true, message: '训练营名称不能为空', trigger: 'blur' },
  839. { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
  840. ]
  841. },
  842. // 添加课程表单校验
  843. courseAddRules: {
  844. courseId: [
  845. { required: true, message: '请选择课程', trigger: 'change' }
  846. ],
  847. videoIds: [
  848. { required: true, message: '请选择小节', trigger: 'change' },
  849. { type: 'array', min: 1, message: '请至少选择一个小节', trigger: 'change' }
  850. ]
  851. },
  852. // 修改看课时间表单校验
  853. courseUpdateRules: {
  854. timeRange: [
  855. {
  856. required: true,
  857. validator: (rule, value, callback) => {
  858. if (!value || !Array.isArray(value) || value.length !== 2) {
  859. callback(new Error('请选择完整的看课时间范围'));
  860. } else {
  861. // 检查时间格式是否正确(yyyy-MM-dd HH:mm:ss)
  862. const timeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
  863. if (!timeRegex.test(value[0]) || !timeRegex.test(value[1])) {
  864. callback(new Error('时间格式不正确'));
  865. } else if (value[0] >= value[1]) {
  866. callback(new Error('结束时间必须大于开始时间'));
  867. } else {
  868. callback();
  869. }
  870. }
  871. },
  872. trigger: 'change'
  873. }
  874. ],
  875. joinTime: [
  876. {
  877. required: true,
  878. validator: (rule, value, callback) => {
  879. if (!value) {
  880. callback(new Error('请选择领取红包时间'));
  881. } else {
  882. // 检查时间格式是否正确(yyyy-MM-dd HH:mm:ss)
  883. const timeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
  884. if (!timeRegex.test(value)) {
  885. callback(new Error('时间格式不正确'));
  886. } else {
  887. // 检查领取红包时间是否在看课时间范围内
  888. const timeRange = this.updateCourse.form.timeRange;
  889. if (timeRange && Array.isArray(timeRange) && timeRange.length === 2) {
  890. if (value < timeRange[0] || value > timeRange[1]) {
  891. callback(new Error('领取红包时间必须在看课时间范围内'));
  892. } else {
  893. callback();
  894. }
  895. } else {
  896. callback();
  897. }
  898. }
  899. }
  900. },
  901. trigger: 'change'
  902. }
  903. ]
  904. },
  905. // 滚动节流标志
  906. scrollThrottle: false,
  907. // 加载更多状态
  908. loadingMore: false,
  909. // 设置红包对话框
  910. redPacketVisible: false,
  911. periodCompanyList: [],
  912. currentRedPacketData: {
  913. periodId: '',
  914. videoId: ''
  915. },
  916. // 营期相关设置抽屉
  917. periodSettingsVisible: false,
  918. activeTab: 'course',
  919. periodSettingsData: {},
  920. companyList: [],
  921. courseDialogVisible: false,
  922. redPacketList: [],
  923. currentCompany: null,
  924. // 选中的营期数据
  925. selectedPeriods: [],
  926. // 批量设置红包按钮是否禁用
  927. batchSetRedPacketDisabled: true,
  928. // 批量设置红包弹出框
  929. batchRedPacketVisible: false,
  930. //课程选择
  931. courseSelection: [],
  932. courseSelectionIsAdd: true, // 默认新增状态,编辑时会设为false
  933. // 训练营对话框是否显示
  934. addExistCampPeriod: false,
  935. addExistCampPeriodName: "新增已存在营期",
  936. loadingNew: false,
  937. submitLoading: false,
  938. // 表单数据
  939. createCampPeriodForm: {
  940. campPeriodType: 1,
  941. periodId: null,
  942. trainingCampName: null,
  943. },
  944. // 数据列表
  945. currentCampPeriods: [], // 当前训练营的期数列表
  946. otherCampPeriods: [], // 其他训练营的期数列表
  947. // 缓存数据避免重复请求
  948. periodDataCache: new Map(),
  949. trainingCampList:[],
  950. };
  951. },
  952. created() {
  953. courseList().then(response => {
  954. this.courseList = response.list;
  955. });
  956. // this.getList();
  957. this.getLeftList();
  958. this.getCompanyList();
  959. /** 获取课程下拉框*/
  960. listUserCourse().then(response => {
  961. this.courseSelection = response.rows;
  962. });
  963. },
  964. methods: {
  965. /** 删除按钮操作 */
  966. async handleDeleteCourse(row) {
  967. const periodDayIds = row.id || this.updateCourse.ids;
  968. try {
  969. await this.$confirm('是否确认删除该课程?', "提示", {
  970. confirmButtonText: "确定",
  971. cancelButtonText: "取消",
  972. type: "warning"
  973. });
  974. const res = await delPeriodDay(periodDayIds);
  975. if (res && res.code === 200) {
  976. this.getCourseList();// 刷新列表
  977. this.$message.success('删除成功');
  978. } else {
  979. this.$message.error(res.msg);
  980. }
  981. } catch (error) {
  982. }
  983. },
  984. /** 查询会员营期列表 */
  985. getList() {
  986. this.loading = true;
  987. const params = { ...this.queryParams };
  988. pagePeriod(params).then(response => {
  989. this.periodList = response.rows;
  990. this.total = response.total;
  991. this.loading = false;
  992. });
  993. },
  994. /** 查询左侧列表 */
  995. getLeftList() {
  996. this.leftLoading = true;
  997. // 重置页码和加载更多状态
  998. this.leftQueryParams.pageNum = 1;
  999. this.loadingMore = false;
  1000. // 训练营数据
  1001. listCamp(this.leftQueryParams).then(response => {
  1002. if (response && response.code === 200) {
  1003. this.campList = response.data.list || [];
  1004. this.leftQueryParams.hasNextPage = response.data.hasNextPage;
  1005. this.activeCampIndex = this.campList.length > 0 ? 0 : null;
  1006. this.selectCamp(this.activeCampIndex);
  1007. // 如果当前显示的列表高度不足以触发滚动,但还有更多数据,自动加载下一页
  1008. this.$nextTick(() => {
  1009. const scrollEl = this.$refs.campList;
  1010. if (scrollEl && this.leftQueryParams.hasNextPage && scrollEl.scrollHeight <= scrollEl.clientHeight) {
  1011. this.loadMoreCamps();
  1012. }
  1013. });
  1014. } else {
  1015. this.$message.error(response.msg || '获取训练营列表失败');
  1016. this.campList = [];
  1017. this.leftQueryParams.hasNextPage = false;
  1018. }
  1019. this.leftLoading = false;
  1020. }).catch(error => {
  1021. console.error('获取训练营列表失败:', error);
  1022. this.$message.error('获取训练营列表失败');
  1023. this.campList = [];
  1024. this.leftQueryParams.hasNextPage = false;
  1025. this.leftLoading = false;
  1026. });
  1027. },
  1028. /** 搜索按钮操作 */
  1029. handleQuery() {
  1030. this.queryParams.pageNum = 1;
  1031. this.getList();
  1032. },
  1033. /** 左侧搜索按钮操作 */
  1034. handleLeftQuery() {
  1035. // 重置页码和列表
  1036. this.leftQueryParams.pageNum = 1;
  1037. this.campList = [];
  1038. this.getLeftList();
  1039. },
  1040. /** 重置按钮操作 */
  1041. resetQuery() {
  1042. this.resetForm("queryForm");
  1043. this.queryParams.companyIdList = [];
  1044. this.handleQuery();
  1045. },
  1046. /** 多选框选中数据 */
  1047. handleSelectionChange(selection) {
  1048. this.ids = selection.map(item => item.periodId)
  1049. this.single = selection.length!==1
  1050. this.multiple = !selection.length
  1051. // 更新批量设置红包相关数据
  1052. this.selectedPeriods = selection;
  1053. this.batchSetRedPacketDisabled = selection.length === 0;
  1054. },
  1055. handleSelectionCourseChange(selection) {
  1056. this.updateCourse.ids = selection.map(item => item.id)
  1057. },
  1058. /** 新增按钮操作 */
  1059. handleAdd() {
  1060. this.reset();
  1061. this.open = true;
  1062. this.title = "添加会员营期";
  1063. this.isDisabledDateRange = false;
  1064. },
  1065. /** 修改按钮操作 */
  1066. handleUpdate(row) {
  1067. this.reset();
  1068. const periodId = row.periodId || this.ids
  1069. getPeriod(periodId).then(response => {
  1070. this.form = response.data;
  1071. if (this.form.companyId) {
  1072. this.form.companyId = this.form.companyId.split(',').map(id => Number(id));
  1073. }
  1074. // 设置看课时间范围(回显)
  1075. if (this.form.viewStartTime && this.form.viewEndTime) {
  1076. this.form.timeRange = [this.form.viewStartTime, this.form.viewEndTime];
  1077. }
  1078. if(this.form.periodType == 1){
  1079. this.$set(this.form,'dateRange',[this.form.periodStartingTime, this.form.periodEndTime])
  1080. }
  1081. if(this.form.periodType == 2){
  1082. this.$set(this.form,'date',this.form.periodStartingTime)
  1083. }
  1084. this.open = true;
  1085. this.title = "修改会员营期";
  1086. this.isDisabledDateRange = true;
  1087. });
  1088. },
  1089. /** 提交按钮 */
  1090. submitForm() {
  1091. this.$refs["form"].validate(valid => {
  1092. if (valid) {
  1093. let data = JSON.parse(JSON.stringify(this.form));
  1094. // 处理看课时间范围
  1095. if (data.timeRange && data.timeRange.length === 2) {
  1096. data.viewStartTime = data.timeRange[0];
  1097. data.viewEndTime = data.timeRange[1];
  1098. }
  1099. data.companyId = data.companyId.join()
  1100. data.trainingCampId = this.queryParams.trainingCampId
  1101. if (data.periodId != null) {
  1102. updatePeriod(data).then(response => {
  1103. if (response.code === 200) {
  1104. this.msgSuccess("修改成功");
  1105. this.open = false;
  1106. this.getList();
  1107. }
  1108. });
  1109. } else {
  1110. addPeriod(data).then(response => {
  1111. if (response.code === 200) {
  1112. this.msgSuccess("新增成功");
  1113. this.open = false;
  1114. this.getList();
  1115. }
  1116. });
  1117. }
  1118. }
  1119. });
  1120. },
  1121. /** 删除按钮操作 */
  1122. async handleDelete(row) {
  1123. const periodIds = row.periodId || this.ids;
  1124. try {
  1125. await this.$confirm('是否确认删除该营期?', "提示", {
  1126. confirmButtonText: "确定",
  1127. cancelButtonText: "取消",
  1128. type: "warning"
  1129. });
  1130. const res = await delPeriod(periodIds);
  1131. if (res && res.code === 200) {
  1132. this.getList(); // 刷新列表
  1133. this.$message.success('删除成功');
  1134. } else {
  1135. this.$message.error(res.msg);
  1136. }
  1137. } catch (error) {
  1138. }
  1139. },
  1140. /** 导出按钮操作 */
  1141. handleExport() {
  1142. const queryParams = this.queryParams;
  1143. this.$confirm('是否确认导出所有会员营期数据项?', "警告", {
  1144. confirmButtonText: "确定",
  1145. cancelButtonText: "取消",
  1146. type: "warning"
  1147. }).then(function() {
  1148. return exportPeriod(queryParams);
  1149. }).then(response => {
  1150. this.download(response.msg);
  1151. }).catch(function() {});
  1152. },
  1153. /** 批量设置红包 */
  1154. handleBatchSetRedPacket() {
  1155. if (this.selectedPeriods.length === 0) {
  1156. this.$message.warning('请至少选择一个营期');
  1157. return;
  1158. }
  1159. this.batchRedPacketVisible = true;
  1160. },
  1161. /** 处理批量设置红包保存 */
  1162. // handleBatchRedPacketSave(data) {
  1163. // // 这里等待接口提供后补充具体实现
  1164. // // 示例代码:
  1165. // // batchSetRedPacket(data).then(response => {
  1166. // // if (response.code === 200) {
  1167. // // this.$message.success('批量设置成功');
  1168. // // this.getList();
  1169. // // }
  1170. // // });
  1171. // this.batchRedPacketVisible = false;
  1172. // },
  1173. /** 获取公司下拉列表*/
  1174. getCompanyList() {
  1175. this.loading = true;
  1176. getCompanyList().then(response => {
  1177. this.companyOptions = response.data;
  1178. this.loading = false;
  1179. });
  1180. },
  1181. // 取消按钮
  1182. cancel() {
  1183. this.open = false;
  1184. this.reset();
  1185. },
  1186. // 表单重置
  1187. reset() {
  1188. this.form = {
  1189. periodId: null,
  1190. periodName: null,
  1191. companyId: null,
  1192. courseId: null,
  1193. videoId: null,
  1194. trainingCampId: null,
  1195. createTime: null,
  1196. updateTime: null,
  1197. courseStyle: null,
  1198. liveRoomStyle: null,
  1199. redPacketGrantMethod: 1,
  1200. periodType: 1,
  1201. periodStartingTime: null,
  1202. dateRange: [],
  1203. date: null,
  1204. days: [],
  1205. maxViewNum: 0,
  1206. periodEndTime: null,
  1207. timeRange: [], // 看课时间范围
  1208. viewStartTime: null, // 看课开始时间
  1209. viewEndTime: null, // 看课结束时间
  1210. lastJoinTime: null // 领取红包时间
  1211. };
  1212. this.resetForm("form");
  1213. },
  1214. // 处理训练营列表的逻辑
  1215. handleDeleteCamp(item) {
  1216. this.$confirm(`确定要删除训练营"${item.trainingCampName}"吗?`, '提示', {
  1217. confirmButtonText: '删除',
  1218. cancelButtonText: '取消',
  1219. type: 'warning'
  1220. }).then(() => {
  1221. // 调用删除训练营API
  1222. const trainingCampId = item.trainingCampId;
  1223. this.leftLoading = true;
  1224. delCamp(trainingCampId).then(response => {
  1225. if (response.code === 200) {
  1226. this.$message.success('删除成功');
  1227. // 从列表中移除
  1228. const index = this.campList.findIndex(camp => camp.trainingCampId === trainingCampId);
  1229. if (index !== -1) {
  1230. this.campList.splice(index, 1);
  1231. }
  1232. // 如果删除的是当前选中的训练营,则重置选中状态
  1233. if (this.activeCampIndex === index) {
  1234. this.activeCampIndex = this.campList.length > 0 ? 0 : null;
  1235. if (this.activeCampIndex !== null) {
  1236. // 更新右侧列表
  1237. this.selectCamp(this.activeCampIndex);
  1238. } else {
  1239. // 没有训练营了,清空右侧列表
  1240. this.periodList = [];
  1241. }
  1242. }
  1243. } else {
  1244. this.$message.error(response.msg || '删除失败');
  1245. }
  1246. this.leftLoading = false;
  1247. }).catch(error => {
  1248. // this.$message.error('删除失败: ' + error.message);
  1249. this.leftLoading = false;
  1250. });
  1251. }).catch(() => {
  1252. this.$message.info('已取消删除');
  1253. });
  1254. },
  1255. /** 复制训练营 */
  1256. handleCopyCamp(item) {
  1257. // 调用添加训练营API
  1258. copyCamp(item.trainingCampId).then(response => {
  1259. if (response.code === 200) {
  1260. this.$message.success('复制成功');
  1261. // 重新加载训练营列表
  1262. this.getLeftList();
  1263. } else {
  1264. this.$message.error(response.msg || '复制训练营失败');
  1265. }
  1266. }).catch(error => {
  1267. this.$message.error('复制训练营失败: ' + error.message);
  1268. });
  1269. },
  1270. /** 修改训练营按钮操作 */
  1271. handleEditCamp(item) {
  1272. this.resetCampForm();
  1273. this.leftLoading = true;
  1274. // 获取最新的训练营数据
  1275. const trainingCampId = item.trainingCampId;
  1276. // 应该调用获取训练营详情的API
  1277. setTimeout(() => {
  1278. // 填充表单数据
  1279. this.campForm = {
  1280. trainingCampId: item.trainingCampId,
  1281. trainingCampName: item.trainingCampName,
  1282. orderNumber: item.orderNumber || 1,
  1283. status: item.status !== undefined ? item.status : 1
  1284. };
  1285. this.campDialogVisible = true;
  1286. this.leftLoading = false;
  1287. }, 300);
  1288. },
  1289. /** 新建训练营按钮操作 */
  1290. handleAddTrainingCamp() {
  1291. this.resetCampForm();
  1292. this.campDialogVisible = true;
  1293. },
  1294. /** 重置训练营表单 */
  1295. resetCampForm() {
  1296. this.campForm = {
  1297. trainingCampId: null,
  1298. trainingCampName: ''
  1299. };
  1300. // 如果表单已经创建,则重置校验结果
  1301. if (this.$refs.campForm) {
  1302. this.$refs.campForm.resetFields();
  1303. }
  1304. },
  1305. /** 取消训练营表单 */
  1306. cancelCampForm() {
  1307. this.campDialogVisible = false;
  1308. this.resetCampForm();
  1309. },
  1310. /** 提交训练营表单 */
  1311. submitCampForm() {
  1312. this.$refs.campForm.validate(valid => {
  1313. if (valid) {
  1314. // 显示加载中
  1315. this.leftLoading = true;
  1316. // 准备提交的数据
  1317. const submitData = JSON.parse(JSON.stringify(this.campForm));
  1318. // 判断是新增还是修改
  1319. if (submitData.trainingCampId) {
  1320. // 修改训练营
  1321. editCamp(submitData).then(response => {
  1322. if (response.code === 200) {
  1323. this.$message.success('修改训练营成功');
  1324. this.campDialogVisible = false;
  1325. // 更新列表中的数据
  1326. const index = this.campList.findIndex(camp => camp.trainingCampId === submitData.trainingCampId);
  1327. if (index !== -1) {
  1328. this.campList[index] = { ...this.campList[index], ...submitData };
  1329. // 如果修改的是当前选中的训练营,更新右侧列表
  1330. if (this.activeCampIndex === index) {
  1331. this.selectCamp(index);
  1332. }
  1333. }
  1334. // 重新加载训练营列表
  1335. this.getLeftList();
  1336. } else {
  1337. this.$message.error(response.msg || '修改训练营失败');
  1338. this.leftLoading = false;
  1339. }
  1340. }).catch(error => {
  1341. this.$message.error('修改训练营失败: ' + (error.message || '未知错误'));
  1342. this.leftLoading = false;
  1343. });
  1344. } else {
  1345. // 新增训练营
  1346. addCamp(submitData).then(response => {
  1347. if (response.code === 200) {
  1348. this.$message.success('新建训练营成功');
  1349. this.campDialogVisible = false;
  1350. // 重新加载训练营列表
  1351. this.getLeftList();
  1352. } else {
  1353. this.$message.error(response.msg || '新建训练营失败');
  1354. this.leftLoading = false;
  1355. }
  1356. }).catch(error => {
  1357. this.$message.error('新建训练营失败: ' + (error.message || '未知错误'));
  1358. this.leftLoading = false;
  1359. });
  1360. }
  1361. }
  1362. });
  1363. },
  1364. /** 排序方式改变 */
  1365. handleSortChange(value) {
  1366. this.leftQueryParams.scs = value;
  1367. // 重置页码和列表
  1368. this.leftQueryParams.pageNum = 1;
  1369. this.campList = [];
  1370. this.getLeftList();
  1371. },
  1372. /** 选中训练营 */
  1373. selectCamp(index) {
  1374. if(index == null || index == undefined) return;
  1375. this.activeCampIndex = index;
  1376. // 加载对应的训练营营期数据
  1377. const selectedCamp = this.campList[index];
  1378. this.queryParams.trainingCampId = selectedCamp.trainingCampId;
  1379. this.trainingCampIdValue=selectedCamp.trainingCampId;
  1380. this.getList();
  1381. },
  1382. /** 处理滚动事件,实现滚动到底部加载更多 */
  1383. handleScroll() {
  1384. // 如果正在节流中或者正在加载中,则不处理
  1385. if (this.scrollThrottle || this.loadingMore) return;
  1386. // 设置节流,200ms内不再处理滚动事件
  1387. this.scrollThrottle = true;
  1388. setTimeout(() => {
  1389. this.scrollThrottle = false;
  1390. }, 200);
  1391. const scrollEl = this.$refs.campList;
  1392. if (!scrollEl) return;
  1393. // 判断是否滚动到底部:滚动高度 + 可视高度 >= 总高度 - 30(添加30px的容差,提前触发加载)
  1394. const isBottom = scrollEl.scrollTop + scrollEl.clientHeight >= scrollEl.scrollHeight - 30;
  1395. // 如果滚动到底部,且有下一页数据,且当前不在加载中,则加载更多
  1396. if (isBottom && this.leftQueryParams.hasNextPage && !this.leftLoading && !this.loadingMore) {
  1397. this.loadMoreCamps();
  1398. }
  1399. },
  1400. /** 加载更多训练营数据 */
  1401. loadMoreCamps() {
  1402. // 已在加载中,防止重复加载
  1403. if (this.leftLoading || this.loadingMore) return;
  1404. // 设置加载状态
  1405. this.loadingMore = true;
  1406. // 页码加1
  1407. this.leftQueryParams.pageNum += 1;
  1408. // 加载下一页数据
  1409. listCamp(this.leftQueryParams).then(response => {
  1410. if (response && response.code === 200) {
  1411. // 将新数据追加到列表中
  1412. const newList = response.data.list || [];
  1413. if (newList.length > 0) {
  1414. this.campList = [...this.campList, ...newList];
  1415. }
  1416. // 更新是否有下一页的标志
  1417. this.leftQueryParams.hasNextPage = response.data.hasNextPage;
  1418. // 如果当前显示的列表高度不足以触发滚动,但还有更多数据,自动加载下一页
  1419. this.$nextTick(() => {
  1420. const scrollEl = this.$refs.campList;
  1421. if (scrollEl && this.leftQueryParams.hasNextPage && scrollEl.scrollHeight <= scrollEl.clientHeight) {
  1422. // 延迟一点再加载下一页,避免过快加载
  1423. setTimeout(() => {
  1424. this.loadMoreCamps();
  1425. }, 300);
  1426. }
  1427. });
  1428. } else {
  1429. this.$message.error(response.msg || '加载更多训练营失败');
  1430. }
  1431. this.loadingMore = false;
  1432. }).catch(error => {
  1433. console.error('加载更多训练营失败:', error);
  1434. this.$message.error('加载更多训练营失败');
  1435. this.loadingMore = false;
  1436. });
  1437. },
  1438. timeChange(type) {
  1439. if (type == 1) {
  1440. this.form.periodStartingTime = this.form.dateRange[0];
  1441. this.form.periodEndTime = this.form.dateRange[1];
  1442. if (!Array.isArray(this.form.days)) {
  1443. this.form.days = [];
  1444. }
  1445. this.form.days = [];
  1446. let days = this.getDiff(this.form.periodStartingTime, this.form.periodEndTime);
  1447. for (let i = 0; i < days; i++) {
  1448. this.form.days.push({ lesson: i + 1 });
  1449. }
  1450. }
  1451. if (type == 2) {
  1452. this.form.periodStartingTime = this.form.date;
  1453. this.form.periodEndTime = this.form.date;
  1454. this.form.days = [];
  1455. }
  1456. },
  1457. getDiff(start, end) {
  1458. if(start == null || start == undefined || start == '') return 0;
  1459. if(end == null || end == undefined || end == '') return 0;
  1460. if(start == end) 1;
  1461. const startDate = this.getUTCDate(start);
  1462. const endDate = this.getUTCDate(end);
  1463. const timeDiff = endDate - startDate;
  1464. return (Math.floor(timeDiff / (1000 * 3600 * 24))) + 1; // 直接取整
  1465. },
  1466. getUTCDate(dateStr) {
  1467. const [year, month, day] = dateStr.split('-').map(Number);
  1468. return new Date(Date.UTC(year, month - 1, day)); // 月份从0开始
  1469. },
  1470. // handleCourse(row){
  1471. // this.course = {
  1472. // open: false,
  1473. // row:{},
  1474. // list:[],
  1475. // queryParams: {
  1476. // pageNum: 1,
  1477. // pageSize: 3, // 修改为每页显示3条
  1478. // },
  1479. // loading: true,
  1480. // total: 0,
  1481. // addOpen: false,
  1482. // form: {},
  1483. // };
  1484. // this.course.open = true;
  1485. // this.course.row = row;
  1486. // this.course.queryParams.periodId = row.periodId;
  1487. // this.getCourseList();
  1488. // },
  1489. getCourseList(){
  1490. this.course.loading = true;
  1491. getDays(this.course.queryParams).then(e => {
  1492. this.course.list = e.rows;
  1493. this.course.total = e.total;
  1494. this.course.loading = false;
  1495. });
  1496. },
  1497. handleAddCourse() {
  1498. const key = "joinTime.switch.config"
  1499. getConfigByKey(key).then(response => {
  1500. const {code,data} = response
  1501. if (code === 200) {
  1502. let value = data?.configValue
  1503. console.log(value)
  1504. if (value) {
  1505. this.joinTimeSwitch = value=='0'?true:false;
  1506. }
  1507. }
  1508. });
  1509. this.course.addOpen = true;
  1510. this.course.form = {
  1511. periodId: this.course.queryParams.periodId,
  1512. courseId: null,
  1513. timeRange: ['00:00:00', '23:59:59'],
  1514. joinTime: '23:59:59',
  1515. videoIds: []
  1516. };
  1517. // 重置表单
  1518. this.$nextTick(() => {
  1519. if (this.$refs.courseAddForm) {
  1520. this.$refs.courseAddForm.resetFields();
  1521. }
  1522. });
  1523. },
  1524. handleUpdateCourse() {
  1525. const key = "joinTime.switch.config"
  1526. getConfigByKey(key).then(response => {
  1527. const {code,data} = response
  1528. if (code === 200) {
  1529. let value = data?.configValue
  1530. console.log(value)
  1531. if (value) {
  1532. this.joinTimeSwitch = value=='0'?true:false;
  1533. }
  1534. }
  1535. })
  1536. this.updateCourse.open = true;
  1537. this.updateCourse.form = {
  1538. ids: this.updateCourse.ids,
  1539. timeRange: null,
  1540. joinTime: null
  1541. };
  1542. // 重置表单校验状态(但不清空选中状态)
  1543. this.$nextTick(() => {
  1544. if (this.$refs.courseUpdateForm) {
  1545. this.$refs.courseUpdateForm.resetFields();
  1546. }
  1547. });
  1548. },
  1549. closeAddCourse() {
  1550. this.course.addOpen = false;
  1551. this.course.form = {
  1552. periodId: null,
  1553. courseId: null,
  1554. timeRange: null,
  1555. joinTime: null,
  1556. videoIds: []
  1557. };
  1558. // 重置表单
  1559. if (this.$refs.courseAddForm) {
  1560. this.$refs.courseAddForm.resetFields();
  1561. }
  1562. },
  1563. closeUpdateCourse() {
  1564. this.updateCourse.open = false;
  1565. // 清空选中的课程id,使【修改看课时间】按钮变为禁用状态
  1566. this.updateCourse.ids = [];
  1567. // 清空课程列表的选中状态
  1568. this.$nextTick(() => {
  1569. if (this.$refs.courseTable) {
  1570. this.$refs.courseTable.clearSelection();
  1571. }
  1572. });
  1573. // 重置表单数据
  1574. this.updateCourse.form = {
  1575. ids: [],
  1576. timeRange: null,
  1577. joinTime: null
  1578. };
  1579. // 重置表单校验
  1580. this.$nextTick(() => {
  1581. if (this.$refs.courseUpdateForm) {
  1582. this.$refs.courseUpdateForm.resetFields();
  1583. }
  1584. });
  1585. },
  1586. courseChange(row){
  1587. this.course.form.videoIds = [];
  1588. videoList(row).then(response => {
  1589. this.videoList=response.list
  1590. });
  1591. },
  1592. submitCourseForm(){
  1593. this.$refs.courseAddForm.validate(valid => {
  1594. if (valid) {
  1595. if(this.course.form.timeRange != null && this.course.form.timeRange.length === 2){
  1596. this.course.form.startTime = this.course.form.timeRange[0];
  1597. this.course.form.endTime1 = this.course.form.timeRange[1];
  1598. }
  1599. // 提交数据
  1600. addCourse(this.course.form).then(response => {
  1601. this.$message.success('添加成功');
  1602. this.course.addOpen = false;
  1603. // 重新加载训练营列表
  1604. this.getCourseList();
  1605. });
  1606. }
  1607. });
  1608. },
  1609. submitUpdateCourseForm(){
  1610. this.$refs.courseUpdateForm.validate(valid => {
  1611. if (valid) {
  1612. // 检查时间范围是否正确
  1613. if (this.updateCourse.form.timeRange &&
  1614. Array.isArray(this.updateCourse.form.timeRange) &&
  1615. this.updateCourse.form.timeRange.length === 2) {
  1616. this.updateCourse.form.startTime = this.updateCourse.form.timeRange[0];
  1617. this.updateCourse.form.endTime1 = this.updateCourse.form.timeRange[1];
  1618. } else {
  1619. this.$message.error('请先选择正确的看课时间范围');
  1620. return;
  1621. }
  1622. // 检查领取红包时间是否正确
  1623. if (!this.updateCourse.form.joinTime&&this.joinTimeSwitch) {
  1624. this.$message.error('请选择领取红包时间');
  1625. return;
  1626. }
  1627. // 提交数据
  1628. updateCourseTime(this.updateCourse.form).then(response => {
  1629. this.$message.success('修改成功');
  1630. this.updateCourse.open = false;
  1631. // 清空选中的课程ID,使【修改看课时间】按钮变为禁用状态
  1632. this.updateCourse.ids = [];
  1633. // 清空课程列表的选中状态
  1634. this.$nextTick(() => {
  1635. if (this.$refs.courseTable) {
  1636. this.$refs.courseTable.clearSelection();
  1637. }
  1638. });
  1639. // 重新加载训练营列表
  1640. this.getCourseList();
  1641. }).catch(error => {
  1642. this.$message.error('修改失败:' + (error.message || '未知错误'));
  1643. });
  1644. }
  1645. });
  1646. },
  1647. updatePeriodDateSubmit(){
  1648. updateCourseDate(this.updatePeriodDate.form).then(response => {
  1649. this.$message.success('修改成功');
  1650. this.updatePeriodDate.open = false;
  1651. // 重新加载课程列表
  1652. this.getCourseList();
  1653. });
  1654. },
  1655. // saveCourseData(){
  1656. // updateListCourseData(this.course.list).then(response => {
  1657. // this.$message.success('保存成功');
  1658. // this.getCourseList();
  1659. // });
  1660. // },
  1661. // setRedPacket(row) {
  1662. // this.currentRedPacketData = {
  1663. // periodId: row.periodId
  1664. // // videoId: row.videoId
  1665. // };
  1666. // this.redPacketVisible = true;
  1667. // },
  1668. handleRedPacketSuccess() {
  1669. this.getCourseList();
  1670. },
  1671. handlePeriodSettings(row) {
  1672. this.periodSettingsData = row;
  1673. this.periodSettingsVisible = true;
  1674. // 初始化课程列表
  1675. this.course.queryParams.periodId = row.periodId;
  1676. // 根据当前激活的tab加载对应数据
  1677. this.handleTabClick({ name: this.activeTab });
  1678. },
  1679. // 结束营期
  1680. handleClosePeriod(row) {
  1681. const msg = `注: 1.确认结束营期,该营期的开营结束时间改为当天24点。2.当天正在播放中的课程不变。3.第二天如有未开始的课程,统一改为已结束。是否确认结束 ${row.periodName} 营期吗?`
  1682. this.$confirm(msg, "警告", {
  1683. confirmButtonText: "确定",
  1684. cancelButtonText: "取消",
  1685. type: "warning"
  1686. }).then(() => {
  1687. closePeriod({id: row.periodId}).then(response => {
  1688. if (response.code === 200) {
  1689. this.getList()
  1690. } else {
  1691. this.$message.error(response.msg)
  1692. }
  1693. })
  1694. }).catch(() => {})
  1695. },
  1696. handleBatchRedPacketSuccess() {
  1697. this.batchRedPacketVisible = false;
  1698. this.getCourseList();
  1699. },
  1700. /** 处理tab切换 */
  1701. handleTabClick(tab) {
  1702. if (tab.name === 'course') {
  1703. this.getCourseList();
  1704. } else if (tab.name === 'company') {
  1705. this.redPacketVisible = true;
  1706. }
  1707. },
  1708. /** 上移课程 */
  1709. handleTop(row) {
  1710. const currentIndex = this.course.list.findIndex(item => item.id === row.id);
  1711. if (currentIndex <= 0) {
  1712. this.$message.warning('已经是第一条数据');
  1713. return;
  1714. }
  1715. // 获取上一条数据
  1716. const prevRow = this.course.list[currentIndex - 1];
  1717. console.log({
  1718. id: row.id,
  1719. targetId: prevRow.id,
  1720. type: 1 //上移
  1721. })
  1722. periodCourseMove({
  1723. id: row.id,
  1724. targetId: prevRow.id,
  1725. type: 1 //上移
  1726. }).then(response => {
  1727. if (response.code === 200) {
  1728. this.$message.success('上移成功');
  1729. this.getCourseList();
  1730. } else {
  1731. this.$message.error(response.msg || '上移失败');
  1732. }
  1733. }).catch(() => {
  1734. this.$message.error('上移失败');
  1735. });
  1736. },
  1737. /** 下移课程 */
  1738. handleBottom(row) {
  1739. const currentIndex = this.course.list.findIndex(item => item.id === row.id);
  1740. if (currentIndex === -1 || currentIndex >= this.course.list.length - 1) {
  1741. this.$message.warning('已经是最后一条数据');
  1742. return;
  1743. }
  1744. // 获取下一条数据
  1745. const nextRow = this.course.list[currentIndex + 1];
  1746. periodCourseMove({
  1747. id: row.id,
  1748. targetId: nextRow.id,
  1749. type: 2 //下移
  1750. }).then(response => {
  1751. if (response.code === 200) {
  1752. this.$message.success('下移成功');
  1753. this.getCourseList(); // 重新加载列表
  1754. } else {
  1755. this.$message.error(response.msg || '下移失败');
  1756. }
  1757. }).catch(() => {
  1758. this.$message.error('下移失败');
  1759. });
  1760. },
  1761. /** 营期状态格式化 */
  1762. periodStatusFormatter(row) {
  1763. const statusMap = {
  1764. 1: '未开始',
  1765. 2: '进行中',
  1766. 3: '已结束'
  1767. };
  1768. return statusMap[row.periodStatus] || '未知状态';
  1769. },
  1770. /** 开课状态格式化 */
  1771. courseStatusFormatter(row) {
  1772. const statusMap = {
  1773. 0: '未开始',
  1774. 1: '进行中',
  1775. 2: '已结束'
  1776. };
  1777. return statusMap[row.status] || '未知状态';
  1778. },
  1779. /** 营期状态格式化 */
  1780. handleUpdateDate(row) {
  1781. this.updatePeriodDate.form = {id: row.id, dayDate: row.dayDate};
  1782. this.updatePeriodDate.open = true;
  1783. },
  1784. // disabledDate(time) {
  1785. // return time.getTime() < new Date(new Date().setHours(0,0,0,0));
  1786. // },
  1787. getPickerOptions() {
  1788. // 如果已选择看课时间范围,则领取红包时间应在看课时间范围内
  1789. if (this.updateCourse.form.timeRange &&
  1790. Array.isArray(this.updateCourse.form.timeRange) &&
  1791. this.updateCourse.form.timeRange.length === 2) {
  1792. return {
  1793. selectableRange: `${this.updateCourse.form.timeRange[0]} - ${this.updateCourse.form.timeRange[1]}`
  1794. };
  1795. }
  1796. // 默认全天可选
  1797. return {
  1798. selectableRange: '00:00:00 - 23:59:59'
  1799. };
  1800. },
  1801. onTimeRangeChange() {
  1802. // 当看课时间范围改变时,清空领取红包时间
  1803. this.updateCourse.form.joinTime = null;
  1804. // 强制更新组件以刷新领取红包时间的可选范围
  1805. this.$forceUpdate();
  1806. },
  1807. /** 新建存在训练营按钮操作 */
  1808. handleAddExistCampPeriod() {
  1809. this.resetForm();
  1810. this.addExistCampPeriod = true;
  1811. // 初始化当前训练营的期数列表
  1812. this.initCurrentCampPeriods();
  1813. },
  1814. /** 初始化当前训练营期数列表 */
  1815. initCurrentCampPeriods() {
  1816. // 对当前营期列表按照创建时间倒序排序(最新的在前面)
  1817. this.currentCampPeriods = [...(this.periodList || [])].sort((a, b) => {
  1818. // 如果没有创建时间,按原始顺序
  1819. if (!a.createTime || !b.createTime) return 0;
  1820. // 将时间字符串转换为时间戳进行比较
  1821. const timeA = new Date(a.createTime).getTime();
  1822. const timeB = new Date(b.createTime).getTime();
  1823. // 按创建时间倒序排列(最新的在前面)
  1824. return timeB - timeA;
  1825. });
  1826. },
  1827. /** 处理创建方式变更 */
  1828. async handlePeriodTypeChange(value) {
  1829. this.createCampPeriodForm.periodId = null;
  1830. this.createCampPeriodForm.trainingCampName = null;
  1831. if (value === 1) {
  1832. // 从当前训练营复制 - 使用本地数据
  1833. this.initCurrentCampPeriods();
  1834. } else if (value === 2) {
  1835. // 从其他训练营复制 - 需要请求接口
  1836. await this.loadOtherCampPeriods();
  1837. }
  1838. },
  1839. /** 加载其他训练营期数列表 */
  1840. async loadOtherCampPeriods() {
  1841. // 清空营期数据和选中项,避免显示旧数据
  1842. this.otherCampPeriods = [];
  1843. this.createCampPeriodForm.periodId = ''; // 清空已选营期
  1844. this.createCampPeriodForm.trainingCampId = ''; // 清空已选训练营
  1845. // 检查缓存 - 使用固定键名,因为训练营列表不依赖当前训练营ID
  1846. // const cacheKey = 'trainingCampList';
  1847. // if (this.periodDataCache.has(cacheKey)) {
  1848. // this.trainingCampList = this.periodDataCache.get(cacheKey);
  1849. // return;
  1850. // }
  1851. this.loadingNew = true;
  1852. try {
  1853. const requestParams = {
  1854. periodId: this.trainingCampIdValue,
  1855. campPeriodType: this.createCampPeriodForm.campPeriodType
  1856. };
  1857. const response = await getScreeningCampPeriod(requestParams);
  1858. if (response && Array.isArray(response.resultList)) {
  1859. this.trainingCampList = response.resultList;
  1860. // 缓存数据 - 使用固定键名
  1861. //this.periodDataCache.set(cacheKey, response.resultList);
  1862. } else {
  1863. console.warn('接口返回格式异常:', response);
  1864. this.trainingCampList = [];
  1865. }
  1866. } catch (error) {
  1867. console.error('接口请求失败:', error);
  1868. this.$message.error('查询失败,请重试');
  1869. this.trainingCampList = [];
  1870. } finally {
  1871. this.loadingNew = false;
  1872. }
  1873. },
  1874. /** 对话框关闭事件 */
  1875. handleDialogClose() {
  1876. this.resetForm();
  1877. },
  1878. /** 重置表单 */
  1879. resetForm() {
  1880. this.createCampPeriodForm = {
  1881. campPeriodType: 1,
  1882. periodId: null,
  1883. trainingCampName: null,
  1884. };
  1885. this.currentCampPeriods = [];
  1886. this.otherCampPeriods = [];
  1887. this.trainingCampList=[]
  1888. this.loading = false;
  1889. this.submitLoading = false;
  1890. // 清除表单验证
  1891. if (this.$refs.createCampPeriodForm) {
  1892. this.$refs.createCampPeriodForm.clearValidate();
  1893. }
  1894. },
  1895. handleTrainingCampChange(trainingCampId){
  1896. this.otherCampPeriods = [];
  1897. this.createCampPeriodForm.periodId = '';
  1898. const params = {
  1899. ...this.queryParams,
  1900. trainingCampId: trainingCampId // 更新训练营ID
  1901. };
  1902. pagePeriod(params).then(response => {
  1903. if (response.code === 200) {
  1904. this.otherCampPeriods = response.rows;
  1905. } else {
  1906. this.$message.error(response.msg || '查询营期失败');
  1907. }
  1908. }).catch(error => {
  1909. this.$message.error('查询营期失败: ' + (error.message || '查询营期失败'));
  1910. });
  1911. },
  1912. /** 提交表单 */
  1913. copySubmitCampForm() {
  1914. try {
  1915. // 表单验证
  1916. const valid = this.$refs.createCampPeriodForm.validate();
  1917. if (!valid) return ;
  1918. this.submitLoading = true;
  1919. const submitData = this.buildSubmitData();
  1920. if (submitData.campPeriodType===3){
  1921. // 新增训练营
  1922. addCamp(submitData).then(response => {
  1923. if (response.code === 200) {
  1924. this.$message.success('新建训练营成功');
  1925. this.addExistCampPeriod = false;
  1926. // 重新加载训练营列表
  1927. this.getLeftList();
  1928. } else {
  1929. this.$message.error(response.msg || '新建训练营失败');
  1930. }
  1931. }).catch(error => {
  1932. this.$message.error('新建训练营失败: ' + (error.message || '未知错误'));
  1933. });
  1934. }else {
  1935. // 显示全屏加载圈和遮蔽层
  1936. const loadingInstance = this.$loading({
  1937. lock: true,
  1938. text: '复制营期中,请耐心等待...',
  1939. spinner: 'el-icon-loading',
  1940. background: 'rgba(0, 0, 0, 0.7)'
  1941. });
  1942. // 调用批量添加小节接口
  1943. copyExistCampPeriod(submitData).then(response => {
  1944. if (response.code === 200) {
  1945. this.$message.success('复制营期成功');
  1946. this.course.addOpen = false;
  1947. this.addExistCampPeriod = false;
  1948. // 重新加载训练营列表
  1949. this.getList();
  1950. } else {
  1951. this.$message.error(response.msg || '复制营期失败');
  1952. }
  1953. }).catch(error => {
  1954. this.$message.error('复制营期失败:' + (error.message || '未知错误'));
  1955. }).finally(() => {
  1956. loadingInstance.close(); // 关闭加载圈
  1957. });
  1958. }
  1959. } catch (error) {
  1960. this.$message.error('提交失败:' + (error.message || '未知错误'));
  1961. } finally {
  1962. this.submitLoading = false;
  1963. }
  1964. },
  1965. /** 组装提交数据 */
  1966. buildSubmitData() {
  1967. const { campPeriodType, periodId, trainingCampName } = this.createCampPeriodForm;
  1968. const baseData = {
  1969. campPeriodType,
  1970. trainingCampId: this.trainingCampIdValue // 这里已经正确添加了 trainingCampId
  1971. };
  1972. switch (campPeriodType) {
  1973. case 1: // 从当前训练营复制
  1974. case 2: // 从其他训练营复制
  1975. if (!periodId) {
  1976. throw new Error('请选择要复制的营期');
  1977. }
  1978. return { ...baseData, periodId };
  1979. case 3: // 新建营期
  1980. if (!trainingCampName?.trim()) {
  1981. throw new Error('请输入营期名称');
  1982. }
  1983. return { ...baseData, trainingCampName: trainingCampName.trim() };
  1984. default:
  1985. throw new Error('未知的创建方式');
  1986. }
  1987. },
  1988. /** 取消新建存在训练营 */
  1989. cancelExistCampPeriod() {
  1990. this.addExistCampPeriod = false;
  1991. this.resetForm();
  1992. },
  1993. /** 更新训练营序号 */
  1994. updateCampOrderNumber(item) {
  1995. // 校验序号值
  1996. if (!item.orderNumber || item.orderNumber < 1 || item.orderNumber > 9999) {
  1997. this.$message.warning('请输入有效的序号(1-9999)');
  1998. return;
  1999. }
  2000. // 调用接口更新序号,使用params传参
  2001. const params = {
  2002. trainingCampId: item.trainingCampId,
  2003. orderNumber: item.orderNumber
  2004. };
  2005. updateCampOrderNumber(params).then(response => {
  2006. if (response.code === 200) {
  2007. this.$message.success('训练营序号更新成功');
  2008. // 刷新训练营列表以保持排序一致(序号越大排在越前面)
  2009. this.getLeftList();
  2010. } else {
  2011. this.$message.error(response.msg || '训练营序号更新失败');
  2012. // 更新失败时刷新列表,恢复原值
  2013. this.getLeftList();
  2014. }
  2015. }).catch(error => {
  2016. this.$message.error('训练营序号更新失败:' + (error.message || '未知错误'));
  2017. // 更新失败时刷新列表,恢复原值
  2018. this.getLeftList();
  2019. });
  2020. },
  2021. },
  2022. };
  2023. </script>
  2024. <style scoped>
  2025. .left-aside {
  2026. background-color: #fff;
  2027. border-right: 1px solid #EBEEF5;
  2028. padding: 0;
  2029. display: flex;
  2030. flex-direction: column;
  2031. height: 800px;
  2032. }
  2033. .left-header {
  2034. padding: 10px;
  2035. border-bottom: 1px solid #EBEEF5;
  2036. }
  2037. .left-header-top {
  2038. display: flex;
  2039. justify-content: space-between;
  2040. align-items: center;
  2041. margin-bottom: 10px;
  2042. }
  2043. .search-btn {
  2044. width: 50%;
  2045. height: 36px;
  2046. background-color: #409EFF;
  2047. color: white;
  2048. border: none;
  2049. }
  2050. .search-input-wrapper {
  2051. margin-bottom: 10px;
  2052. }
  2053. .sort-wrapper {
  2054. display: flex;
  2055. align-items: center;
  2056. margin-bottom: 10px;
  2057. }
  2058. .sort-label {
  2059. width: 70px;
  2060. font-size: 14px;
  2061. font-weight: 600;
  2062. color: #909399;
  2063. }
  2064. .sort-select {
  2065. margin-left: 10px;
  2066. width: 280px;
  2067. }
  2068. .color-wrapper {
  2069. display: flex;
  2070. align-items: center;
  2071. margin-bottom: 10px;
  2072. }
  2073. .color-label {
  2074. width: 70px;
  2075. color: #606266;
  2076. }
  2077. .color-hint {
  2078. margin-left: 10px;
  2079. color: #606266;
  2080. font-size: 12px;
  2081. }
  2082. .color-help {
  2083. margin-left: 5px;
  2084. color: #909399;
  2085. cursor: pointer;
  2086. }
  2087. .hint-text {
  2088. color: #606266;
  2089. font-size: 12px;
  2090. margin-top: 5px;
  2091. }
  2092. .camp-list {
  2093. flex: 1;
  2094. overflow-y: auto;
  2095. padding: 3px;
  2096. }
  2097. .camp-item {
  2098. margin-bottom: 5px;
  2099. padding: 15px;
  2100. background-color: #ffffff;
  2101. position: relative;
  2102. cursor: pointer;
  2103. display: flex;
  2104. justify-content: space-between;
  2105. border: 1px solid #eaedf2;
  2106. }
  2107. .camp-item:last-child {
  2108. margin-bottom: 0;
  2109. }
  2110. .camp-item:hover {
  2111. background-color: #f5f9ff;
  2112. }
  2113. .camp-item.active {
  2114. background-color: #eaf4ff;
  2115. border-left: 1px solid #75b8fc;
  2116. }
  2117. .camp-content {
  2118. flex: 1;
  2119. padding-right: 10px;
  2120. }
  2121. .camp-title {
  2122. font-weight: bold;
  2123. font-size: 16px;
  2124. margin-bottom: 8px;
  2125. color: #333;
  2126. display: flex;
  2127. align-items: center;
  2128. }
  2129. .camp-icon {
  2130. font-size: 16px;
  2131. margin-right: 6px;
  2132. color: #409EFF;
  2133. }
  2134. .camp-info {
  2135. display: flex;
  2136. justify-content: space-between;
  2137. margin-bottom: 8px;
  2138. font-size: 12px;
  2139. color: #c4c1c1;
  2140. line-height: 1.5;
  2141. }
  2142. .camp-stats {
  2143. display: flex;
  2144. justify-content: space-between;
  2145. font-size: 12px;
  2146. color: #666;
  2147. background-color: #f5f9ff;
  2148. padding: 6px 10px;
  2149. border-radius: 4px;
  2150. line-height: 1.5;
  2151. }
  2152. .stat-item {
  2153. display: flex;
  2154. align-items: center;
  2155. }
  2156. .stat-item i {
  2157. margin-right: 4px;
  2158. font-size: 14px;
  2159. color: #409EFF;
  2160. }
  2161. .camp-actions {
  2162. display: flex;
  2163. flex-direction: column;
  2164. justify-content: center;
  2165. align-items: flex-end;
  2166. gap: 8px;
  2167. border-left: 1px dashed #eaedf2;
  2168. padding-left: 12px;
  2169. min-width: 50px;
  2170. }
  2171. .action-btn {
  2172. padding: 2px 5px;
  2173. font-size: 12px;
  2174. border-radius: 4px;
  2175. transition: all 0.2s;
  2176. }
  2177. .action-btn:hover {
  2178. background-color: rgba(255, 255, 255, 0.8);
  2179. }
  2180. .delete-btn {
  2181. color: #f56c6c;
  2182. }
  2183. .delete-btn:hover {
  2184. background-color: rgba(245, 108, 108, 0.1);
  2185. }
  2186. .copy-btn {
  2187. color: #409EFF;
  2188. }
  2189. .copy-btn:hover {
  2190. background-color: rgba(64, 158, 255, 0.1);
  2191. }
  2192. .warning-icon {
  2193. color: #E6A23C;
  2194. font-size: 16px;
  2195. margin-left: 5px;
  2196. }
  2197. .el-main {
  2198. padding: 10px;
  2199. }
  2200. /* 添加训练营表单样式 */
  2201. .drawer-footer {
  2202. /* position: absolute; */
  2203. bottom: 0;
  2204. left: 0;
  2205. right: 0;
  2206. padding: 20px;
  2207. background: #fff;
  2208. text-align: right;
  2209. border-top: 1px solid #e8e8e8;
  2210. }
  2211. .el-input-number {
  2212. width: 100%;
  2213. }
  2214. /* 加载更多样式 */
  2215. .loading-more {
  2216. display: flex;
  2217. align-items: center;
  2218. justify-content: center;
  2219. padding: 12px 0;
  2220. color: #909399;
  2221. font-size: 14px;
  2222. }
  2223. .loading-more i {
  2224. margin-right: 5px;
  2225. font-size: 16px;
  2226. }
  2227. /* 无更多数据提示 */
  2228. .no-more-data {
  2229. display: flex;
  2230. align-items: center;
  2231. justify-content: center;
  2232. padding: 12px 0;
  2233. color: #c0c4cc;
  2234. font-size: 13px;
  2235. }
  2236. .no-more-data span {
  2237. position: relative;
  2238. display: flex;
  2239. align-items: center;
  2240. }
  2241. </style>