userCourseCatalogDetails.vue 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. <template>
  2. <div class="app-container">
  3. <div style="padding-bottom: 20px">
  4. <span v-if="courseName != null">{{ courseName }}</span>
  5. </div>
  6. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  7. <el-form-item label="小节名称" prop="title">
  8. <el-input v-model="queryParams.title" placeholder="请输入小节名称" clearable size="small"
  9. @keyup.enter.native="handleQuery"/>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  13. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  14. </el-form-item>
  15. </el-form>
  16. <el-row :gutter="10" class="mb8">
  17. <el-col :span="1.5">
  18. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  19. v-hasPermi="['course:userCourseVideo:add']">新增目录
  20. </el-button>
  21. </el-col>
  22. <el-col :span="1.5">
  23. <el-button type="primary" plain :disabled="!ids || ids.length <= 0" size="mini" @click="openUpdates"
  24. v-hasPermi="['course:userCourseVideo:updateTime']">修改时间
  25. </el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="primary" plain size="mini" @click="openAdds"
  29. v-hasPermi="['course:userCourseVideo:batchAdd']">批量添加
  30. </el-button>
  31. </el-col>
  32. <el-col :span="1.5">
  33. <el-button type="primary" plain size="mini" @click="updateRedPageckeOpen"
  34. v-hasPermi="['course:userCourseVideo:updateRed']">修改红包
  35. </el-button>
  36. </el-col>
  37. <el-col :span="1.5">
  38. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  39. v-hasPermi="['course:userCourseVideo:remove']">删除
  40. </el-button>
  41. </el-col>
  42. <el-col :span="1.5">
  43. <el-button type="warning" plain icon="el-icon-edit" size="mini" @click="handleCourseSort"
  44. v-hasPermi="['course:userCourseVideo:sort']">修改课节排序
  45. </el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button type="primary" plain icon="el-icon-delete" size="mini" @click="handleSync"
  49. v-hasPermi="['course:userCourseVideo:sync']">同步模板数据
  50. </el-button>
  51. </el-col>
  52. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  53. </el-row>
  54. <el-table border v-loading="loading" :data="userCourseVideoList" @selection-change="handleSelectionChange">
  55. <el-table-column type="selection" width="55" align="center"/>
  56. <el-table-column label="视频ID" align="center" prop="videoId"/>
  57. <el-table-column label="小节名称" align="center" show-overflow-tooltip prop="title"/>
  58. <el-table-column label="视频文件名称" align="center" show-overflow-tooltip prop="fileName">
  59. </el-table-column>
  60. <el-table-column label="视频时长" align="center" prop="duration">
  61. <template slot-scope="{ row }">
  62. {{ formatDuration(row.duration) }}
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="看课开始时间" align="center" prop="duration">
  66. <template slot-scope="{ row }">
  67. <el-tag v-if="row.viewStartTime">{{ row.viewStartTime }}</el-tag>
  68. <el-tag type="danger" v-if="!row.viewStartTime">无</el-tag>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="看课结束时间" align="center" prop="duration">
  72. <template slot-scope="{ row }">
  73. <el-tag v-if="row.viewEndTime">{{ row.viewEndTime }}</el-tag>
  74. <el-tag type="danger" v-if="!row.viewEndTime">无</el-tag>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="领取红包时间" align="center" prop="duration">
  78. <template slot-scope="{ row }">
  79. <el-tag v-if="row.lastJoinTime">{{ row.lastJoinTime }}</el-tag>
  80. <el-tag type="danger" v-if="!row.lastJoinTime">无</el-tag>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="红包金额" align="center" prop="redPacketMoney"/>
  84. <el-table-column label="排序" align="center" prop="courseSort"/>
  85. <el-table-column label="上传时间" align="center" prop="createTime"/>
  86. <el-table-column label="是否上架" align="center" prop="isOnPut">
  87. <template slot-scope="{ row }">
  88. <el-tag v-if="row.isOnPut == 0">是</el-tag>
  89. <el-tag type="danger" v-if="row.isOnPut == 1">否</el-tag>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  93. <template slot-scope="scope">
  94. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  95. v-hasPermi="['course:userCourseVideo:edit']">修改
  96. </el-button>
  97. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleComment(scope.row)"
  98. v-hasPermi="['course:courseWatchComment:list']">查看评论
  99. </el-button>
  100. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  101. v-hasPermi="['course:userCourseVideo:remove']">删除
  102. </el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  107. @pagination="getList"/>
  108. <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
  109. <el-form ref="form" :model="form" :rules="rules" label-width="110px" v-loading="uploadLoading">
  110. <el-form-item label="视频标题" prop="title">
  111. <el-input v-model="form.title" placeholder="请输入内容"/>
  112. </el-form-item>
  113. <el-form-item label="视频描述" prop="description">
  114. <el-input v-model="form.description" type="textarea" :rows="2" placeholder="请输入内容"/>
  115. </el-form-item>
  116. <el-form-item label="课程排序" prop="courseSort">
  117. <el-input-number v-model="form.courseSort" :min="1"></el-input-number>
  118. </el-form-item>
  119. <el-form-item label="视频缩略图" prop="thumbnail">
  120. <el-upload v-model="form.thumbnail" class="avatar-uploader" :action="uploadUrl" :show-file-list="false"
  121. :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
  122. <img v-if="form.thumbnail" :src="form.thumbnail" class="avatar" width="300px">
  123. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  124. </el-upload>
  125. </el-form-item>
  126. <video-upload :type="1" :isPrivate="isPrivate" :fileKey.sync="form.fileKey" :fileSize.sync="form.fileSize"
  127. :videoUrl.sync="videoUrl" :fileName.sync="form.fileName" :line_1.sync="form.lineOne"
  128. :line_2.sync="form.lineTwo" :line_3.sync="form.lineThree" :thumbnail.sync="form.thumbnail"
  129. :uploadType.sync="form.uploadType" :isTranscode.sync="form.isTranscode"
  130. :transcodeFileKey.sync="form.transcodeFileKey" @video-duration="handleVideoDuration"
  131. @change="handleVideoChange" @selectProjects="handleSelectProjects" ref="videoUpload"
  132. append-to-body/>
  133. <el-form-item label="课题选择" prop="questionBankId">
  134. <el-button size="small" type="primary" @click="chooseQuestionBank">选取课题</el-button>
  135. <el-table border width="100%" style="margin-top:5px;" :data="form.questionBankList">
  136. <el-table-column label="问题" align="center" prop="title">
  137. <template slot-scope="scope">
  138. <el-tooltip class="item" effect="dark" :content="scope.row.title" placement="top">
  139. <div
  140. style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; text-overflow: ellipsis;">
  141. <span>{{ scope.row.title }}</span>
  142. </div>
  143. </el-tooltip>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="类别" align="center" prop="type">
  147. <template slot-scope="scope">
  148. <dict-tag :options="typeOptions" :value="scope.row.type"/>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="答案" align="center" prop="answer"/>
  152. <el-table-column label="操作" align="center" width="100px" fixed="right">
  153. <template slot-scope="scope">
  154. <el-button size="mini" type="text" icon="el-icon-delete"
  155. @click="handleQuestionBankDelete(scope.row)">删除
  156. </el-button>
  157. </template>
  158. </el-table-column>
  159. </el-table>
  160. </el-form-item>
  161. <el-form-item label="红包金额" prop="redPacketMoney">
  162. <el-input-number v-model="form.redPacketMoney" :min="0.1" :max="200" :step="0.1"></el-input-number>
  163. </el-form-item>
  164. <!-- v-if="!!form.randomRedPacketRulesArr" -->
  165. <el-form-item v-if="!!enableRandomRedPacket" label="随机红包金额" >
  166. <template >
  167. <div v-for="(rule, index) in form.randomRedPacketRulesArr" :key="index" class="form-row">
  168. <el-form-item
  169. label="随机红包金额区间"
  170. :prop="`randomRedPacketRulesArr.${index}.minAmount`"
  171. :rules="[
  172. { required: true, message: '请输入最小金额', trigger: 'blur' },
  173. { validator: validateMinAmount, trigger: 'blur', index: index }
  174. ]"
  175. class="form-item-amount"
  176. >
  177. <el-input
  178. v-model.number="rule.minAmount"
  179. type="number"
  180. :min="0.01"
  181. :precision="2"
  182. :step="0.01"
  183. placeholder="最小金额"
  184. size="small"
  185. class="amount-input"
  186. @input="handleAmountInput(rule, 'minAmount')"
  187. ></el-input>
  188. <span class="separator">-</span>
  189. <el-input
  190. v-model.number="rule.maxAmount"
  191. type="number"
  192. :min="rule.minAmount || 0.01"
  193. :precision="2"
  194. :step="0.01"
  195. placeholder="最大金额"
  196. size="small"
  197. class="amount-input"
  198. @input="handleAmountInput(rule, 'maxAmount')"
  199. ></el-input>
  200. <span class="suffix">元</span>
  201. </el-form-item>
  202. <el-form-item
  203. label="随机权重"
  204. :prop="`randomRedPacketRulesArr.${index}.weight`"
  205. :rules="[
  206. { required: true, message: '请输入权重', trigger: 'blur' },
  207. { type: 'integer', message: '权重必须为整数', trigger: 'blur' },
  208. ]"
  209. class="form-item-weight"
  210. >
  211. <el-input
  212. v-model.number="rule.weight"
  213. type="number"
  214. :min="1"
  215. placeholder="权重"
  216. size="small"
  217. ></el-input>
  218. </el-form-item>
  219. <el-tooltip class="item" effect="dark" content="权重越高,被随机到的概率越大" placement="top">
  220. <i class="el-icon-question"></i>
  221. </el-tooltip>
  222. <div class="action-buttons">
  223. <el-button
  224. icon="el-icon-plus"
  225. size="mini"
  226. type="text"
  227. @click="addRule(index)"
  228. class="add-btn"
  229. >
  230. 新增
  231. </el-button>
  232. <el-button
  233. icon="el-icon-delete"
  234. size="mini"
  235. type="text"
  236. @click="deleteRule(index)"
  237. :disabled="form.randomRedPacketRulesArr.length <= 1"
  238. class="delete-btn"
  239. >
  240. 删除
  241. </el-button>
  242. </div>
  243. </div>
  244. </template>
  245. </el-form-item>
  246. <el-form-item label="是否关联商品">
  247. <el-radio v-model="form.isProduct" :label=0>否</el-radio>
  248. <el-radio v-model="form.isProduct" :label=1>是</el-radio>
  249. </el-form-item>
  250. <el-form-item label="是否先导课" prop="isFirst">
  251. <el-radio-group v-model="form.isFirst">
  252. <el-radio :label="1">是</el-radio>
  253. <el-radio :label="0">否</el-radio>
  254. </el-radio-group>
  255. </el-form-item>
  256. <el-form-item label="是否启用倍速" prop="isSpeed">
  257. <el-radio-group v-model="form.isSpeed">
  258. <el-radio :label="1">是</el-radio>
  259. <el-radio :label="0">否</el-radio>
  260. </el-radio-group>
  261. </el-form-item>
  262. <el-form-item label="是否上架" prop="isOnPut">
  263. <el-radio-group v-model="form.isOnPut">
  264. <el-radio :label="0">上架</el-radio>
  265. <el-radio :label="1">下架</el-radio>
  266. </el-radio-group>
  267. </el-form-item>
  268. <el-form-item label="商品选择" v-if="form.isProduct === 1">
  269. <el-button size="small" type="primary" @click="chooseCourseProduct">选取商品</el-button>
  270. <el-table border width="100%" style="margin-top:5px;" :data="form.courseProducts">
  271. <el-table-column label="商品名称" align="center" prop="productName"/>
  272. <el-table-column label="产品条码" align="center" prop="barCode"/>
  273. <el-table-column label="商品价格" align="center" prop="productPrice"/>
  274. <el-table-column label="库存" align="center" prop="stock"/>
  275. <el-table-column label="操作" align="center" width="100px" fixed="right">
  276. <template slot-scope="scope">
  277. <el-button size="mini" type="text" icon="el-icon-delete"
  278. @click="handleCourseProductDelete(scope.row)">删除
  279. </el-button>
  280. </template>
  281. </el-table-column>
  282. </el-table>
  283. </el-form-item>
  284. <el-row>
  285. <el-col :span="12">
  286. <el-form-item v-if="form.isProduct === 1" label="商品售卖时间" prop="listingStartTime">
  287. <el-input-number v-model="form.listingStartTime" :min="0" label="商品售卖时间"></el-input-number>
  288. </el-form-item>
  289. </el-col>
  290. <el-col :span="12">
  291. <el-form-item v-if="form.isProduct === 1" label="结束售卖时间" prop="listingStartTime">
  292. <el-input-number v-model="form.listingEndTime" :min="0" label="结束售卖时间"></el-input-number>
  293. </el-form-item>
  294. </el-col>
  295. </el-row>
  296. </el-form>
  297. <div slot="footer" class="dialog-footer">
  298. <el-button type="primary" @click="submitForm">确 定</el-button>
  299. <el-button @click="cancel">取 消</el-button>
  300. </div>
  301. </el-dialog>
  302. <el-dialog :title="title" :visible.sync="updateBatchData.open" width="1000px" append-to-body>
  303. <el-form ref="form" :model="updateBatchData.form" label-width="110px">
  304. <el-form-item label="看课时间" prop="timeRange">
  305. <el-time-picker is-range v-model="updateBatchData.form.timeRange" range-separator="至"
  306. start-placeholder="开始时间"
  307. value-format="HH:mm:ss" end-placeholder="结束时间" placeholder="选择时间范围">
  308. </el-time-picker>
  309. </el-form-item>
  310. <el-form-item label="领取红包时间" prop="lastJoinTime">
  311. <el-time-picker v-model="updateBatchData.form.lastJoinTime" :selectableRange="updateBatchData.form.timeRange"
  312. value-format="HH:mm:ss" placeholder="选择时间范围">
  313. </el-time-picker>
  314. <p style="color: red;margin: 0;font-size: 12px">超过领取红包时间,只允许看课,不允许领取红包</p>
  315. </el-form-item>
  316. </el-form>
  317. <div slot="footer" class="dialog-footer">
  318. <el-button type="primary" @click="updateBatch">确 定</el-button>
  319. <el-button @click="updateBatchData.open = false">取 消</el-button>
  320. </div>
  321. </el-dialog>
  322. <el-dialog :title="questionBank.title" :visible.sync="questionBank.open" width="1000px" append-to-body>
  323. <question-bank ref="questionBank" @questionBankResult="questionBankResult"></question-bank>
  324. </el-dialog>
  325. <el-dialog :title="courseProduct.title" :visible.sync="courseProduct.open" width="1000px" append-to-body>
  326. <course-product ref="courseProduct" @courseProductResult="courseProductResult"></course-product>
  327. </el-dialog>
  328. <el-dialog title="视频库选择" :visible.sync="addBatchData.open" width="900px" append-to-body>
  329. <!-- 搜索条件 -->
  330. <el-form :inline="true" :model="addBatchData.queryParams" class="library-search">
  331. <el-form-item label="素材名称">
  332. <el-input v-model="addBatchData.queryParams.resourceName" placeholder="请输入素材名称" clearable size="small"
  333. @keyup.enter.native="resourceList"/>
  334. </el-form-item>
  335. <el-form-item label="类型">
  336. <el-select v-model="addBatchData.queryParams.typeId" @change="changeCateType" placeholder="请选择素材类型"
  337. clearable
  338. size="small">
  339. <el-option v-for="item in addBatchData.typeOptions" :key="item.dictValue" :label="item.dictLabel"
  340. :value="item.dictValue"/>
  341. </el-select>
  342. </el-form-item>
  343. <el-form-item label="子类型">
  344. <el-select v-model="addBatchData.queryParams.typeSubId" placeholder="请选择素材子类型" clearable size="small">
  345. <el-option v-for="item in addBatchData.typeSubOptions" :key="item.dictValue" :label="item.dictLabel"
  346. :value="item.dictValue"/>
  347. </el-select>
  348. </el-form-item>
  349. <el-form-item>
  350. <el-button type="primary" icon="el-icon-search" size="mini" @click="resourceList">搜索</el-button>
  351. </el-form-item>
  352. </el-form>
  353. <!-- 视频列表 -->
  354. <el-table v-loading="addBatchData.loading" :data="addBatchData.list"
  355. @selection-change="handVideoleSelectionChange" height="400px">
  356. <el-table-column type="selection" width="55" align="center"/>
  357. <el-table-column label="素材名称" align="center" prop="resourceName"/>
  358. <el-table-column label="文件名称" align="center" prop="fileName"/>
  359. <el-table-column label="排序" align="center" prop="sort"/>
  360. <el-table-column label="缩略图" align="center">
  361. <template slot-scope="scope">
  362. <el-popover placement="right" title="" trigger="hover">
  363. <img alt="" slot="reference" :src="scope.row.thumbnail" style="width: 80px; height: 50px"/>
  364. <img alt="" :src="scope.row.thumbnail" style="max-width: 150px;"/>
  365. </el-popover>
  366. </template>
  367. </el-table-column>
  368. <el-table-column label="视频时长" align="center">
  369. <template slot-scope="scope">
  370. <span>{{ formatDuration(scope.row.duration) }}</span>
  371. </template>
  372. </el-table-column>
  373. </el-table>
  374. <!-- 分页 -->
  375. <pagination v-show="addBatchData.total > 0" :total="addBatchData.total"
  376. :page.sync="addBatchData.queryParams.pageNum" :limit.sync="addBatchData.queryParams.pageSize"
  377. @pagination="resourceList"/>
  378. <div slot="footer" class="dialog-footer">
  379. <el-button type="primary" @click="batchVideoSave">确 定</el-button>
  380. </div>
  381. </el-dialog>
  382. <el-dialog title="章节红包" :visible.sync="redData.open" width="900px" append-to-body>
  383. <el-table border v-loading="redData.loading" :data="redData.list" height="600px">
  384. <el-table-column label="小节名称" align="center" show-overflow-tooltip prop="title"/>
  385. <el-table-column label="视频文件名称" align="center" show-overflow-tooltip prop="fileName">
  386. </el-table-column>
  387. <el-table-column label="视频时长" align="center" prop="duration">
  388. <template slot-scope="{ row }">
  389. {{ formatDuration(row.duration) }}
  390. </template>
  391. </el-table-column>
  392. <el-table-column label="红包金额" align="center" prop="redPacketMoney">
  393. <template slot-scope="scope">
  394. <el-input class="el-input" v-model="scope.row.redPacketMoney"/>
  395. </template>
  396. </el-table-column>
  397. <el-table-column label="排序" align="center" prop="courseSort"/>
  398. <el-table-column label="上传时间" align="center" prop="createTime"/>
  399. </el-table>
  400. <div slot="footer" class="dialog-footer">
  401. <el-button type="primary" @click="batchRedSave">确 定</el-button>
  402. </div>
  403. </el-dialog>
  404. <el-dialog :title="commentDialog.title" :visible.sync="commentDialog.open" width="1000px" append-to-body
  405. :close-on-click-modal="false">
  406. <course-watch-comment ref="courseWatchComment" :courseId="commentDialog.courseId" :videoId="commentDialog.videoId"
  407. v-if="commentDialog.open">
  408. </course-watch-comment>
  409. </el-dialog>
  410. <el-dialog title="修改课节排序" :visible.sync="openVideoSort" style="width: 1600px;" append-to-body>
  411. <draggable v-model="userCourseVideoSortList" @end="onDragEndDay" style="padding: 10px">
  412. <el-button style="margin: 8px 4px;" v-for="(item, index) in userCourseVideoSortList"
  413. :class="item.newCourseSort != item.courseSort ? 'red':''">第{{
  414. item.newCourseSort
  415. }}序(原排序第{{ item.courseSort }})
  416. </el-button>
  417. </draggable>
  418. <div style="float: right;margin-top: -20px">
  419. <el-button type="primary" @click="saveSorts">保存</el-button>
  420. </div>
  421. </el-dialog>
  422. </div>
  423. </template>
  424. <script>
  425. import {
  426. addUserCourseVideo,
  427. batchSaveVideo,
  428. batchUpdateRed,
  429. delUserCourseVideo,
  430. getSort,
  431. getUserCourseVideo,
  432. getVideoListByCourseId,
  433. getVideoListByCourseIdAll,
  434. sortCourseVideo,
  435. updates,
  436. updateUserCourseVideo,
  437. syncTemplate
  438. } from '@/api/course/userCourseVideo'
  439. // import {syncTemplate} from '@/api/course/userCourse'
  440. import QuestionBank from "@/views/course/courseQuestionBank/QuestionBank.vue";
  441. import CourseProduct from "@/views/course/fsCourseProduct/CourseProduct.vue";
  442. import VideoUpload from "@/components/VideoUpload/index.vue";
  443. import {listVideoResource} from '@/api/course/videoResource';
  444. import {getByIds} from '@/api/course/courseQuestionBank'
  445. import CourseWatchComment from "./courseWatchComment.vue";
  446. import {getCateListByPid, getCatePidList} from '@/api/course/userCourseCategory'
  447. import draggable from 'vuedraggable'
  448. import { getConfigByKey } from '@/api/system/config'
  449. export default {
  450. name: "userCourseCatalog",
  451. components: {VideoUpload, QuestionBank, CourseWatchComment, CourseProduct, draggable},
  452. watch:{
  453. // 深度监听 rules 数组的变化,以更新总权重
  454. "form.randomRedPacketRulesArr": {
  455. handler(val) {
  456. // this.calculateTotalWeight();
  457. this.validateRules();
  458. },
  459. deep: true,
  460. },
  461. },
  462. data() {
  463. return {
  464. duration: null,
  465. packageList: [],
  466. //课题
  467. package: {
  468. title: '',
  469. open: false,
  470. },
  471. //课题
  472. questionBank: {
  473. title: '',
  474. open: false,
  475. },
  476. //拍商品
  477. courseProduct: {
  478. title: '',
  479. open: false,
  480. },
  481. isPrivate: null,
  482. videoUrl: "",
  483. uploadTypeOptions: [
  484. {dictLabel: "线路一", dictValue: 2},
  485. {dictLabel: "线路二", dictValue: 3},
  486. ],
  487. uploadLoading: false,
  488. courseId: null,
  489. videoName: '',
  490. title: "",
  491. // 是否显示弹出层
  492. open: false,
  493. uploadUrl: process.env.VUE_APP_BASE_API + "/common/uploadOSS",
  494. baseUrl: process.env.VUE_APP_BASE_API,
  495. typeOptions: [],
  496. files: [],
  497. fileList: [],
  498. // 上传成功后的地址
  499. videoURL: '',
  500. // 进度条百分比
  501. progress: 0,
  502. // 上传视频获取成功后拿到的fileID【备用】
  503. fileId: '',
  504. courseName: null,
  505. userCourseVideoList: [],
  506. userCourseVideoSortList: [],
  507. total: 0,
  508. redData: {
  509. queryParams: {
  510. pageNum: 1,
  511. pageSize: 99999,
  512. courseId: null,
  513. },
  514. list: [],
  515. open: false,
  516. loading: true,
  517. form: {}
  518. },
  519. queryParams: {
  520. pageNum: 1,
  521. pageSize: 10,
  522. courseId: null,
  523. title: null
  524. },
  525. addBatchData: {
  526. open: false,
  527. loading: true,
  528. form: {},
  529. select: [], // 按用户选择顺序存储视频ID
  530. total: 0,
  531. queryParams: {
  532. pageNum: 1,
  533. pageSize: 10,
  534. resourceName: null,
  535. typeId: null,
  536. typeSubId: null
  537. },
  538. typeOptions: [],
  539. typeSubOptions: []
  540. },
  541. // 显示搜索条件
  542. showSearch: true,
  543. // 遮罩层
  544. loading: true,
  545. // 导出遮罩层
  546. exportLoading: false,
  547. // 选中数组
  548. ids: [],
  549. // 非单个禁用
  550. single: true,
  551. // 非多个禁用
  552. multiple: true,
  553. loading3: false,
  554. openVideoSort: false,
  555. // 表单参数
  556. form: {
  557. isOnPut: 0,
  558. courseProducts: [],
  559. randomRedPacketRules:null,
  560. randomRedPacketRulesArr:[
  561. {
  562. minAmount: 0.01,
  563. maxAmount: 0.01,
  564. weight: 100,
  565. }
  566. ]
  567. },
  568. updateBatchData: {
  569. open: false,
  570. form: {}
  571. },
  572. // 表单校验
  573. rules: {
  574. title: [
  575. {required: true, message: "小节名称不能为空", trigger: "change"}
  576. ],
  577. courseSort: [
  578. {required: true, message: "排序不能为空", trigger: "change"}
  579. ],
  580. },
  581. // 评论弹窗数据
  582. commentDialog: {
  583. open: false,
  584. courseId: null,
  585. videoId: null,
  586. title: ""
  587. },
  588. enableRandomRedPacket:false
  589. }
  590. },
  591. created() {
  592. this.getDicts("sys_course_temp_type").then(response => {
  593. this.typeOptions = response.data;
  594. });
  595. getConfigByKey('randomRedpacket:config').then(res=>{
  596. let configData = res.data;
  597. if(!!configData && !!configData.configValue){
  598. let configValue = JSON.parse(configData.configValue);
  599. if(!!configValue.enableRandomRedpacket){
  600. this.enableRandomRedPacket = configValue.enableRandomRedpacket;
  601. console.log("this.enableRandomRedPacket ::" + this.enableRandomRedPacket)
  602. }
  603. }
  604. }).catch(res=>{
  605. })
  606. },
  607. methods: {
  608. getPickerOptions() {
  609. const durationInMinutes = Math.floor(this.form.duration / 60); // 将秒转换为分钟
  610. const endHour = Math.floor(durationInMinutes / 60); // 起始小时
  611. const endMinute = durationInMinutes % 60; // 起始分钟
  612. return {
  613. start: "00:00", // 固定开始时间
  614. step: "00:01", // 时间间隔
  615. end: `${endHour.toString().padStart(2, "0")}:${endMinute
  616. .toString()
  617. .padStart(2, "0")}`, // 动态结束时间
  618. };
  619. },
  620. handlePackageDelete(row) {
  621. this.packageList.splice(this.packageList.findIndex(item => item.packageId === row.packageId), 1)
  622. },
  623. choosePackage() {
  624. this.package.open = true;
  625. this.package.title = '疗法选择';
  626. },
  627. /**
  628. * 选择课题
  629. */
  630. chooseQuestionBank() {
  631. this.questionBank.open = true;
  632. this.questionBank.title = '课题选择';
  633. },
  634. /**
  635. * 选择拍商品
  636. */
  637. chooseCourseProduct() {
  638. this.courseProduct.open = true;
  639. this.courseProduct.title = '拍商品选择';
  640. },
  641. //选择疗法
  642. selectPackage(row) {
  643. const drug = {};
  644. for (var i = 0; i < this.packageList.length; i++) {
  645. if (this.packageList[i].packageId == row.packageId) {
  646. this.$message.warning("疗法已存在!")
  647. return;
  648. }
  649. }
  650. drug.packageId = row.packageId;
  651. drug.packageName = row.packageName;
  652. drug.secondName = row.secondName;
  653. drug.totalPrice = row.totalPrice;
  654. drug.imgUrl = row.imgUrl;
  655. this.packageList.push(drug);
  656. this.$message({
  657. message: '添加成功',
  658. type: 'success'
  659. });
  660. },
  661. courseProductResult(val) {
  662. this.form.courseProducts = this.form.courseProducts || [];
  663. for (var i = 0; i < this.form.courseProducts.length; i++) {
  664. if (this.form.courseProducts[i].id == val.id) {
  665. return this.$message.error("当前商品已选择")
  666. }
  667. }
  668. //先置空 只选择一件商品
  669. this.form.courseProducts = [];
  670. this.form.courseProducts.push(val);
  671. this.$message({
  672. message: '添加成功',
  673. type: 'success'
  674. });
  675. },
  676. //选择结果
  677. questionBankResult(val) {
  678. // 确保 questionBankList 是数组
  679. this.form.questionBankList = this.form.questionBankList || [];
  680. for (var i = 0; i < this.form.questionBankList.length; i++) {
  681. if (this.form.questionBankList[i].id == val.id) {
  682. return this.$message.error("当前课题已选择")
  683. }
  684. }
  685. this.form.questionBankList.push(val);
  686. this.$message({
  687. message: '添加成功',
  688. type: 'success'
  689. });
  690. },
  691. //删除课题
  692. handleQuestionBankDelete(row) {
  693. this.form.questionBankList.splice(this.form.questionBankList.findIndex(item => item.id === row.id), 1)
  694. },
  695. //删除商品
  696. handleCourseProductDelete(row) {
  697. this.form.courseProducts.splice(this.form.courseProducts.findIndex(item => item.id === row.id), 1)
  698. },
  699. handleVideoChange() {
  700. if (this.form.uploadType == 1) {
  701. this.videoUrl = this.form.lineOne;
  702. } else if (this.form.uploadType == 2) {
  703. this.videoUrl = this.form.lineTwo;
  704. } else if (this.form.uploadType == 3) {
  705. this.videoUrl = this.form.lineThree;
  706. }
  707. },
  708. // 视频库课题
  709. handleSelectProjects(projectIds) {
  710. this.form.questionBankList = []
  711. if (!projectIds || projectIds.length === 0 || this.isPrivate === 0) {
  712. return
  713. }
  714. const params = {ids: projectIds}
  715. getByIds(params).then(response => {
  716. if (response.code === 200) {
  717. response.data.forEach(item => {
  718. let isExist = this.form.questionBankList.some(q => q.id === item.id)
  719. if (!isExist) {
  720. this.form.questionBankList.push(item)
  721. }
  722. });
  723. }
  724. })
  725. },
  726. handleVideoDuration(duration) {
  727. this.form.duration = duration;
  728. },
  729. formatDuration(seconds) {
  730. if (seconds === null || seconds === undefined) {
  731. return '未上传视频';
  732. }
  733. const hours = Math.floor(seconds / 3600);
  734. const minutes = Math.floor((seconds % 3600) / 60);
  735. const remainingSeconds = seconds % 60;
  736. const formattedHours = hours > 0 ? hours.toString() + ':' : '';
  737. const formattedMinutes = minutes.toString().padStart(2, '0');
  738. const formattedSeconds = remainingSeconds.toString().padStart(2, '0');
  739. return `${formattedHours}${formattedMinutes}:${formattedSeconds}`;
  740. },
  741. handleAvatarSuccess(res, file) {
  742. if (res.code == 200) {
  743. this.form.thumbnail = res.url;
  744. this.$forceUpdate()
  745. } else {
  746. this.msgError(res.msg);
  747. }
  748. },
  749. beforeAvatarUpload(file) {
  750. const isLt1M = file.size / 1024 / 1024 < 5;
  751. if (!isLt1M) {
  752. this.$message.error('上传图片大小不能超过 5MB!');
  753. }
  754. return isLt1M;
  755. },
  756. getDetails(courseId, courseName, isPrivate) {
  757. this.isPrivate = isPrivate
  758. this.courseName = courseName
  759. this.courseId = courseId;
  760. this.queryParams.courseId = courseId;
  761. this.getList();
  762. },
  763. getList() {
  764. this.loading = true;
  765. getVideoListByCourseId(this.queryParams).then(response => {
  766. this.userCourseVideoList = response.rows;
  767. this.total = response.total;
  768. this.loading = false;
  769. });
  770. },
  771. // 取消按钮
  772. cancel() {
  773. this.open = false;
  774. this.reset();
  775. },
  776. // 表单重置
  777. reset() {
  778. this.form = {
  779. videoId: null,
  780. title: null,
  781. description: null,
  782. url: null,
  783. thumbnail: null,
  784. duration: null,
  785. createTime: null,
  786. uploadType: null,
  787. lineOne: null,
  788. lineTwo: null,
  789. lineThree: null,
  790. fileName: null,
  791. userId: null,
  792. cateId: null,
  793. courseId: null,
  794. likes: null,
  795. views: null,
  796. comments: null,
  797. status: 0,
  798. courseSort: 1,
  799. isHot: null,
  800. isShow: null,
  801. isAudit: null,
  802. auditBy: null,
  803. auditTime: null,
  804. updateTime: null,
  805. source: null,
  806. isDel: null,
  807. shares: null,
  808. tags: null,
  809. productId: null,
  810. productJson: null,
  811. questionBankId: null,
  812. questionBankList: [],
  813. redPacketMoney: 0,
  814. isTranscode: 0,
  815. transcodeFileKey: null,
  816. isProduct: 0,
  817. isFirst: 0,
  818. isSpeed: 0,
  819. isOnPut: 0,
  820. listingStartTime: null,
  821. listingEndTime: null,
  822. randomRedPacketRules:null,
  823. randomRedPacketRulesArr:[
  824. {
  825. minAmount: 0.01,
  826. maxAmount: 0.01,
  827. weight: 100,
  828. }
  829. ]
  830. };
  831. this.videoURL = '';
  832. this.progress = 0;
  833. this.resetForm("form");
  834. },
  835. /** 搜索按钮操作 */
  836. handleQuery() {
  837. this.queryParams.pageNum = 1;
  838. this.getList();
  839. },
  840. /** 重置按钮操作 */
  841. resetQuery() {
  842. this.resetForm("queryForm");
  843. this.handleQuery();
  844. },
  845. // 多选框选中数据
  846. handleSelectionChange(selection) {
  847. this.ids = selection.map(item => item.videoId)
  848. this.single = selection.length !== 1
  849. this.multiple = !selection.length
  850. },
  851. // 视频库多选框选中数据(按用户点击顺序记录)
  852. handVideoleSelectionChange(selection) {
  853. // 提取当前选中的所有ID
  854. const selectedIds = selection.map(item => item.id);
  855. // 处理新增选中项:保留用户点击顺序
  856. selectedIds.forEach(id => {
  857. if (!this.addBatchData.select.includes(id)) {
  858. this.addBatchData.select.push(id);
  859. }
  860. });
  861. // 处理取消选中项:移除已取消的ID
  862. this.addBatchData.select = this.addBatchData.select.filter(id => selectedIds.includes(id));
  863. },
  864. handleAdd() {
  865. this.reset();
  866. this.form.courseId = this.courseId;
  867. this.open = true;
  868. this.title = "添加课堂视频";
  869. this.videoUrl = '';
  870. this.packageList = [];
  871. getSort(this.courseId).then(response => {
  872. this.form.courseSort = Number(response.data);
  873. })
  874. setTimeout(() => {
  875. this.$refs.videoUpload.resetUpload();
  876. }, 500);
  877. },
  878. /** 修改按钮操作 */
  879. handleUpdate(row) {
  880. this.reset();
  881. this.form.isOnPut=row.isOnPut
  882. this.packageList = [];
  883. const videoId = row.videoId || this.ids
  884. getUserCourseVideo(videoId).then(response => {
  885. console.log(response);
  886. this.form = response.data;
  887. this.$set(this.form, 'isOnPut', response.data.isOnPut !== undefined ? response.data.isOnPut : 0);
  888. if(!!this.form.randomRedPacketRules){
  889. this.$set(this.form, 'randomRedPacketRulesArr', JSON.parse(this.form.randomRedPacketRules)) ;
  890. // this.form.randomRedPacketRulesArr = JSON.parse(this.form.randomRedPacketRules);
  891. }else{
  892. //处理初始值
  893. this.form.randomRedPacketRulesArr = [{
  894. minAmount: 0.01,
  895. maxAmount: 0.01,
  896. weight: 100,
  897. }]
  898. }
  899. if (response.data.videoUrl != null && response.data.videoUrl !== '') {
  900. this.videoUrl = response.data.videoUrl;
  901. }
  902. if (this.form.packageJson != null) {
  903. this.packageList = JSON.parse(this.form.packageJson);
  904. }
  905. if (response.data.viewStartTime != null && response.data.viewEndTime != null) {
  906. this.form.timeRange = [response.data.viewStartTime, response.data.viewEndTime]
  907. }
  908. setTimeout(() => {
  909. this.$refs.videoUpload.resetUpload();
  910. }, 500);
  911. this.open = true;
  912. this.title = "修改课堂视频";
  913. });
  914. },
  915. /** 提交按钮 */
  916. submitForm() {
  917. this.$refs["form"].validate(valid => {
  918. if (valid) {
  919. this.form.videoUrl = this.videoUrl;
  920. if (this.form.videoUrl == null || this.form.videoUrl === '') {
  921. this.$message({
  922. message: '请上传视频!',
  923. type: 'warning'
  924. });
  925. return
  926. }
  927. if (this.form.timeRange && this.form.timeRange.length === 2) {
  928. this.form.viewStartTime = this.form.timeRange[0];
  929. this.form.viewEndTime = this.form.timeRange[1];
  930. }
  931. if (this.form.duration == null) {
  932. this.$message({
  933. message: '未识别到视频时长请稍等。。。',
  934. type: 'warning'
  935. });
  936. return
  937. }
  938. if (this.form.isProduct != null && this.form.isProduct == 1 && (this.form.courseProducts == null || this.form.courseProducts.length < 1)) {
  939. this.$message({
  940. message: '请选择关联商品',
  941. type: 'warning'
  942. });
  943. return
  944. }
  945. if (this.form.questionBankList !== null) {
  946. this.form.questionBankId = this.form.questionBankList.map(item => item.id).join(',');
  947. }
  948. if (this.packageList.length > 0) {
  949. this.form.packageJson = JSON.stringify(this.packageList);
  950. }
  951. if (this.form.courseProducts != null) {
  952. this.form.productId = this.form.courseProducts.map(item => item.id).join(',');
  953. }
  954. if(!!this.form.randomRedPacketRulesArr){
  955. let rulesJson = JSON.stringify(this.form.randomRedPacketRulesArr);
  956. this.form.randomRedPacketRules = rulesJson;
  957. }
  958. if (this.form.videoId != null) {
  959. updateUserCourseVideo(this.form).then(response => {
  960. this.msgSuccess("修改成功");
  961. this.open = false;
  962. this.getList();
  963. });
  964. } else {
  965. addUserCourseVideo(this.form).then(response => {
  966. this.msgSuccess("新增成功");
  967. this.open = false;
  968. this.getList();
  969. });
  970. }
  971. }
  972. });
  973. },
  974. openUpdates() {
  975. this.updateBatchData.form = {};
  976. this.updateBatchData.open = true;
  977. },
  978. /** 提交按钮 */
  979. updateBatch() {
  980. this.updateBatchData.form.ids = this.ids;
  981. if (this.updateBatchData.form.timeRange != null && this.updateBatchData.form.timeRange.length === 2) {
  982. this.updateBatchData.form.viewStartTime = this.updateBatchData.form.timeRange[0];
  983. this.updateBatchData.form.viewEndTime = this.updateBatchData.form.timeRange[1];
  984. }
  985. updates(this.updateBatchData.form).then(response => {
  986. this.msgSuccess("修改成功");
  987. this.updateBatchData.open = false;
  988. this.getList();
  989. });
  990. },
  991. /** 删除按钮操作 */
  992. handleDelete(row) {
  993. const videoIds = row.videoId || this.ids;
  994. this.$confirm('是否确认删除视频编号为"' + videoIds + '"的数据项?', "警告", {
  995. confirmButtonText: "确定",
  996. cancelButtonText: "取消",
  997. type: "warning"
  998. }).then(function () {
  999. return delUserCourseVideo(videoIds);
  1000. }).then(() => {
  1001. this.getList();
  1002. this.msgSuccess("删除成功");
  1003. }).catch(() => {
  1004. });
  1005. },
  1006. /** 同步模板数据*/
  1007. handleSync() {
  1008. const courseId = this.courseId;
  1009. this.$confirm('是否同步课程数据至模板', "确认", {
  1010. confirmButtonText: "确定",
  1011. cancelButtonText: "取消",
  1012. type: "warning"
  1013. }).then(function () {
  1014. return syncTemplate(courseId);
  1015. }).then(() => {
  1016. this.getList();
  1017. this.msgSuccess("正在同步模板中!!请稍后!");
  1018. }).catch(() => {
  1019. });
  1020. },
  1021. handleCourseSort() {
  1022. getVideoListByCourseIdAll(this.queryParams.courseId).then(response => {
  1023. response.rows.forEach((item) => item.newCourseSort = item.courseSort);
  1024. this.userCourseVideoSortList = response.rows.sort((a, b) => a.courseSort - b.courseSort);
  1025. if (this.userCourseVideoSortList == null || this.userCourseVideoSortList.length == 0) {
  1026. this.$message.error("暂无课节天数")
  1027. } else {
  1028. this.openVideoSort = true;
  1029. }
  1030. })
  1031. },
  1032. onDragEndDay() {
  1033. this.userCourseVideoSortList.forEach((item, index) => {
  1034. item.newCourseSort = index + 1;
  1035. })
  1036. this.$forceUpdate()
  1037. },
  1038. saveSorts() {
  1039. let list = this.userCourseVideoSortList.filter(e => e.courseSort != e.newCourseSort).map(e => {
  1040. return {courseSort: e.newCourseSort, videoId: e.videoId}
  1041. })
  1042. this.loading3 = true;
  1043. sortCourseVideo(list).then(e => {
  1044. this.getList();
  1045. }).finally(() => {
  1046. this.userCourseVideoSortList = [];
  1047. this.openVideoSort = false;
  1048. })
  1049. },
  1050. openAdds() {
  1051. this.addBatchData.open = true;
  1052. this.getRootTypeList();
  1053. this.addBatchData.form = {
  1054. courseId: this.courseId,
  1055. };
  1056. // 重置选择顺序数组
  1057. this.addBatchData.select = [];
  1058. this.resourceList();
  1059. },
  1060. getRootTypeList() {
  1061. getCatePidList().then(response => {
  1062. this.addBatchData.typeOptions = response.data
  1063. });
  1064. },
  1065. async changeCateType(val) {
  1066. this.addBatchData.queryParams.typeSubId = null
  1067. this.addBatchData.typeSubOptions = []
  1068. if (!val) {
  1069. return
  1070. }
  1071. await getCateListByPid(val).then(response => {
  1072. this.addBatchData.typeSubOptions = response.data
  1073. })
  1074. },
  1075. resourceList() {
  1076. this.addBatchData.loading = true;
  1077. listVideoResource(this.addBatchData.queryParams).then(response => {
  1078. this.addBatchData.loading = false;
  1079. this.addBatchData.list = response.rows;
  1080. this.addBatchData.total = response.total;
  1081. });
  1082. },
  1083. batchVideoSave() {
  1084. if (this.addBatchData.select.length === 0) {
  1085. this.$message({
  1086. message: '请选择视频!!',
  1087. type: 'warning'
  1088. });
  1089. return
  1090. }
  1091. this.addBatchData.form.ids = this.addBatchData.select; // 按用户选择顺序提交
  1092. batchSaveVideo(this.addBatchData.form).then(response => {
  1093. this.addBatchData.open = false;
  1094. this.getList();
  1095. })
  1096. },
  1097. updateRedPageckeOpen() {
  1098. this.redData.open = true;
  1099. this.redData.loading = true;
  1100. this.redData.queryParams.courseId = this.courseId;
  1101. getVideoListByCourseId(this.redData.queryParams).then(response => {
  1102. if(!!response.rows && response.rows.length >0){
  1103. for(let i = 0; i < response.rows.length; i++){
  1104. if(!!response.rows[i].randomRedPacketRules){
  1105. this.$set(response.rows[i], 'randomRedPacketRulesArr', JSON.parse(response.rows[i].randomRedPacketRules)) ;
  1106. }
  1107. }
  1108. }
  1109. this.redData.list = response.rows;
  1110. console.log(this.redData.list);
  1111. this.redData.loading = false;
  1112. });
  1113. },
  1114. batchRedSave() {
  1115. batchUpdateRed(this.redData.list).then(response => {
  1116. this.redData.open = false;
  1117. this.getList();
  1118. })
  1119. },
  1120. /** 查看评论按钮操作 */
  1121. handleComment(row) {
  1122. this.commentDialog.courseId = row.courseId || this.courseId;
  1123. this.commentDialog.videoId = row.videoId;
  1124. this.commentDialog.title = `查看评论 - ${row.title}`;
  1125. this.commentDialog.open = true;
  1126. },
  1127. // 实时过滤金额输入,只允许两位小数
  1128. handleAmountInput(rule, field) {
  1129. let value = rule[field];
  1130. if (value === null || value === undefined) return;
  1131. // 转换为字符串处理
  1132. let str = value.toString();
  1133. // 移除除数字和小数点外的所有字符
  1134. str = str.replace(/[^0-9.]/g, '');
  1135. // 只保留一个小数点
  1136. const dotIndex = str.indexOf('.');
  1137. if (dotIndex !== -1) {
  1138. str = str.substring(0, dotIndex + 1) + str.substring(dotIndex + 1).replace(/\./g, '');
  1139. }
  1140. // 限制小数点后最多两位
  1141. if (dotIndex !== -1 && str.length > dotIndex + 3) {
  1142. str = str.substring(0, dotIndex + 3);
  1143. }
  1144. // 转换回数字并更新
  1145. rule[field] = parseFloat(str) || 0;
  1146. },
  1147. deleteRule(index) {
  1148. this.$confirm("确定要删除这个区间吗?", "提示", {
  1149. confirmButtonText: "确定",
  1150. cancelButtonText: "取消",
  1151. type: "warning",
  1152. }).then(() => {
  1153. this.form.randomRedPacketRulesArr.splice(index, 1);
  1154. this.$message({
  1155. type: "success",
  1156. message: "删除成功!",
  1157. });
  1158. });
  1159. },
  1160. addRule(index) {
  1161. // 在当前行的后面插入一个新行
  1162. this.form.randomRedPacketRulesArr.splice(index + 1, 0, {
  1163. minAmount: 0.01,
  1164. maxAmount: 0.01,
  1165. weight: 100,
  1166. });
  1167. },
  1168. // 自定义校验规则:确保最大金额大于最小金额
  1169. validateMinAmount(rule, value, callback) {
  1170. // debugger;
  1171. // const maxAmount = this.form29.rules[].maxAmount
  1172. const index = rule.index;
  1173. const maxAmount = this.form.randomRedPacketRulesArr[index].maxAmount;
  1174. if (value > maxAmount) {
  1175. callback(new Error("最小金额不能大于最大金额"));
  1176. } else {
  1177. callback();
  1178. }
  1179. },
  1180. validateRules() {
  1181. this.form.randomRedPacketRulesArr.forEach((rule) => {
  1182. if (rule.minAmount === undefined || rule.minAmount < 0.01) {
  1183. rule.minAmount = 0.01;
  1184. }
  1185. if (rule.maxAmount === undefined || rule.maxAmount < rule.minAmount) {
  1186. rule.maxAmount = rule.minAmount;
  1187. }
  1188. if (rule.weight === undefined || rule.weight < 1) {
  1189. rule.weight = 1;
  1190. }
  1191. });
  1192. },
  1193. }
  1194. }
  1195. </script>
  1196. <style>
  1197. .avatar-uploader .el-upload {
  1198. border: 1px dashed #d9d9d9;
  1199. border-radius: 6px;
  1200. cursor: pointer;
  1201. position: relative;
  1202. overflow: hidden;
  1203. }
  1204. .avatar-uploader .el-upload:hover {
  1205. border-color: #409EFF;
  1206. }
  1207. .avatar-uploader-icon {
  1208. font-size: 28px;
  1209. color: #8c939d;
  1210. width: 150px;
  1211. height: 150px;
  1212. line-height: 150px;
  1213. text-align: center;
  1214. }
  1215. .red:hover {
  1216. color: #dbdbdb !important;
  1217. }
  1218. .red {
  1219. background-color: #F56C6C !important;
  1220. color: #fff !important;
  1221. }
  1222. </style>