EquitiesItem.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <!-- 模板区域 -->
  2. <template>
  3. <div>
  4. <el-drawer :model-value="show" @update:model-value="$emit('update:show', $event)" title="权益选择"
  5. :direction="direction" size="900px">
  6. <el-form :model="form" label-width="120px" label-position="left">
  7. <el-row :gutter="20">
  8. <el-col :span="10">
  9. <el-form-item label="接收人所在地区">
  10. <el-cascader v-model="provinceoptions" style="width: 100%;" filterable clearable :options="regionOptions"
  11. :props="areaProps" @change="provinceChange" />
  12. </el-form-item>
  13. </el-col>
  14. </el-row>
  15. </el-form>
  16. <!-- 出单费用信息 -->
  17. <div class="orderIssueFee">
  18. <div class="expenseInfo flex a-c j-s">
  19. <div>
  20. <span>出单费用</span>
  21. <span>¥{{ props.EquitiesInfo.insFeeOrders.totalExportPremium }}</span>
  22. </div>
  23. <div>
  24. <span>可用金额</span>
  25. <span>¥{{ props.EquitiesInfo.insFeeOrders.availableAmount }}</span>
  26. </div>
  27. <div>
  28. <span>已使用金额</span>
  29. <span>¥{{ calcUsedAndRemaining.usedAmount }}</span>
  30. </div>
  31. <div style="font-weight: bold;">
  32. <span>剩余金额</span>
  33. <span style="color: #FF8C21;"> ¥{{ calcUsedAndRemaining.remainingAmount }}</span>
  34. </div>
  35. <div style="font-weight: bold;">
  36. <span>已选权益价值</span>
  37. <span style="color: #FF8C21;"> ¥{{ totalPriceCount }}</span>
  38. </div>
  39. </div>
  40. <!-- 备注信息 -->
  41. <div class="commentText flex a-c ">
  42. <el-icon color="#0083FF">
  43. <InfoFilled />
  44. </el-icon>
  45. <span>出单后,计算出可使用金额,录入本次使用金额,可使用该金额为用户购买权益,剩余金额会返回到业务员的钱包,业务员可提现。</span>
  46. </div>
  47. </div>
  48. <div class="mt-[24px]">
  49. <el-form label-width="60px">
  50. <el-row :gutter="20">
  51. <el-col :span="6" v-for="(item, index) in filterConditions" :key="index">
  52. <el-form-item :label="item.name">
  53. <el-select v-model="filterConditions[index].list" placeholder="请选择" multiple collapse-tags
  54. collapse-tags-tooltip>
  55. <el-option v-for="childrenitem in item.children" :key="childrenitem.id" :label="childrenitem.name"
  56. :value="childrenitem.id" />
  57. </el-select>
  58. </el-form-item>
  59. </el-col>
  60. </el-row>
  61. </el-form>
  62. </div>
  63. <div class="flex mt-4 tab-btn">
  64. <div class="content flex f-c ">
  65. <div class="RightselectedList">
  66. <el-table class="details" :data="privilegeItem" max-height="300px" style="flex: 1;" :header-cell-style="{ color: '#333333' }" border>
  67. <template #empty>
  68. <div class="flex f-c a-c ">
  69. <img src="@/assets/images/empty.png" alt="" >
  70. <span style="font-size: 14px;color: #909399;">暂无数据</span>
  71. </div>
  72. </template>
  73. <el-table-column prop="rightsName" label="权益名称" align="center">
  74. <template #default="scope">
  75. <el-popover placement="right" trigger="hover" :width="324">
  76. <div class="iframe-container" v-show="!iframeLoading">
  77. <iframe :src="iframeUrl" frameborder="0" class="external-iframe"></iframe>
  78. </div>
  79. <div class="iframe-loading" v-show="iframeLoading">加载中...</div>
  80. <template #reference>
  81. <span class="rights-name-link" @mouseenter="benefitDetail(scope.row)">
  82. {{ scope.row.rightsName }}
  83. </span>
  84. </template>
  85. </el-popover>
  86. </template>
  87. </el-table-column>
  88. <el-table-column prop="contractRate" label="价格" align="center"></el-table-column>
  89. <el-table-column prop="marketPrice" label="价值" align="center"></el-table-column>
  90. <el-table-column prop="shareableStoreNum" label="适用门店" align="center">
  91. <template #default="scope">
  92. {{ scope.row.shareableStoreNum || 0 }}家门店可用
  93. </template>
  94. </el-table-column>
  95. <el-table-column prop="number" label="数量" align="center">
  96. <template #default="scope">
  97. <el-input-number class="rights-count-input" size="small" :model-value="scope.row.rightsCount"
  98. style="width: 80px;"
  99. @update:model-value="val => onRightsCountChange(val, scope.$index, 'privilegeItem', 'contractRate')"
  100. :min="0" />
  101. </template>
  102. </el-table-column>
  103. <el-table-column prop="total" label="总价" align="center">
  104. <template #default="scope">
  105. {{ new Decimal(scope.row.contractRate || 0).times(scope.row.rightsCount || 0).toFixed(2) }}
  106. </template>
  107. </el-table-column>
  108. </el-table>
  109. </div>
  110. </div>
  111. </div>
  112. <template #footer>
  113. <div class="dialog-footer flex a-c j-c ">
  114. <el-button class="border-[#0083FF] color-[#0083FF]" plain @click="cancel">取消</el-button>
  115. <el-button type="primary" @click="save">
  116. 确定
  117. </el-button>
  118. </div>
  119. </template>
  120. </el-drawer>
  121. </div>
  122. </template>
  123. <!-- 行为区域 -->
  124. <script lang='ts' setup>
  125. import { ref, reactive, computed, onBeforeMount, watch } from 'vue'
  126. import api from '@/api'
  127. import { ElMessage, DrawerProps } from 'element-plus'
  128. import Decimal from 'decimal.js'
  129. import { useRouter, useRoute } from 'vue-router'
  130. const route = useRoute()
  131. const router = useRouter()
  132. const direction = ref<DrawerProps['direction']>('rtl')
  133. const props = defineProps<{
  134. show: boolean,
  135. recipientInfo: Array<any>,//接收人信息
  136. EquitiesInfo: any,//权益信息参数
  137. }>();
  138. console.log(props.EquitiesInfo)
  139. const emits = defineEmits(['update:show', 'cancel', 'save']);
  140. watch(() => props.recipientInfo, (newVal) => {
  141. recipientOptions.value = newVal;
  142. });
  143. // 组件挂载时获取地区数据
  144. onBeforeMount(async () => {
  145. await queryTreeQuery();
  146. await getRightsCategory();
  147. await getPrivilegeItem();
  148. provinceoptions.value = []
  149. });
  150. const queryInfo = ref({
  151. countryAll: '', //山西省太原太原市 //省市区
  152. minPrice: 0,
  153. maxPrice: 1000,
  154. sortType: 0, //排序 0 默认 1低价 2高价
  155. pageNo: 1,
  156. pageSize: 20,
  157. });
  158. const benefitPackageList = ref([]); //权益套餐列表
  159. const privilegeItem = ref([]); //权益单品列表
  160. const totalPriceCount = computed(() => {
  161. // 计算权益单品的总价
  162. const itemTotal = privilegeItem.value?.reduce((sum: Decimal, item: any) => {
  163. if (item.rightsCount > 0) {
  164. const itemTotal = new Decimal(item.contractRate || 0).times(new Decimal(item.rightsCount || 0));
  165. return sum.plus(itemTotal);
  166. }
  167. return sum;
  168. }, new Decimal(0)) || new Decimal(0);
  169. // 合并所有总价
  170. const sum = new Decimal(itemTotal);
  171. return sum.toString(); // 返回字符串
  172. });
  173. // 根据可用金额与已选权益价值,高精度计算已使用/剩余金额
  174. // 已使用金额 = 已选权益价值;剩余金额 = 可用金额 - 已使用金额
  175. const calcUsedAndRemaining = computed(() => {
  176. const available = new Decimal(props.EquitiesInfo.insFeeOrders.availableAmount || 0)
  177. const selectedValue = new Decimal(totalPriceCount.value || 0)
  178. const usedAmount = selectedValue
  179. const remainingAmount = available.minus(usedAmount)
  180. return {
  181. usedAmount: usedAmount.toFixed(2),
  182. remainingAmount: remainingAmount.toFixed(2),
  183. }
  184. });
  185. const onRightsCountChange = (e: any, index: any, name: any, field: string) => {
  186. // 根据数组名称获取对应的数组
  187. let targetArray: any[] = [];
  188. if (name === 'benefitPackageList') {
  189. targetArray = benefitPackageList.value || [];
  190. } else if (name === 'privilegeItem') {
  191. targetArray = privilegeItem.value || [];
  192. }
  193. // 获取当前项
  194. const item = targetArray[index];
  195. if (!item) {
  196. console.error('无法找到对应数据,数组:', name, '索引:', index)
  197. return
  198. }
  199. // 获取当前数量和新数量
  200. const currentCount = item.rightsCount || 0;
  201. const newCount = e;
  202. // 计算价格
  203. const price = parseFloat(item[field] || 0);
  204. // 计算当前总价
  205. const currentTotalPrice = parseFloat(totalPriceCount.value || 0);
  206. // 计算数量变化和价格变化
  207. const countChange = newCount - currentCount;
  208. const priceChange = countChange * price;
  209. // 计算新总价
  210. const newTotalPrice = currentTotalPrice + priceChange;
  211. console.log(countChange)
  212. // 如果是增加数量,检查是否超过可用金额
  213. if (countChange > 0 && newTotalPrice > props.EquitiesInfo.insFeeOrders.availableAmount) {
  214. ElMessage({
  215. type: 'success',
  216. message: `权益总价不能超过可用金额${props.EquitiesInfo.insFeeOrders.availableAmount}元`,
  217. plain: true,
  218. })
  219. } else {
  220. // 无论是减少数量还是增加数量且未超过限制,都允许更新
  221. item.rightsCount = newCount;
  222. }
  223. }
  224. // 表单数据
  225. const form = reactive({
  226. recipient: '',
  227. otherRecipient: '',//其它接收人名称
  228. region: []
  229. });
  230. const areaProps = {
  231. expandTrigger: 'hover' as const,
  232. value: 'areaCode',
  233. label: 'areaCname',
  234. children: 'child'
  235. }
  236. // 接收人选项
  237. const recipientOptions = ref()
  238. // 获取权益单品列表
  239. const getPrivilegeItem = async () => {
  240. queryInfo.value.maxPrice = props.EquitiesInfo.insFeeOrders.availableAmount;
  241. try {
  242. const response = await api.additionalApi.rightsList(queryInfo.value);
  243. privilegeItem.value = response.data.records || [];
  244. } catch (error) {
  245. console.error('获取权益单品列表失败:', error);
  246. }
  247. }
  248. // 获取权益分类
  249. const filterConditions = ref([]);
  250. const getRightsCategory = async () => {
  251. try {
  252. const response = await api.additionalApi.rightsCategory();
  253. filterConditions.value = response.data || [];
  254. console.log(filterConditions.value)
  255. filterConditions.value.forEach((item: any) => {
  256. item.list = [];
  257. })
  258. console.log(filterConditions.value)
  259. } catch (error) {
  260. console.error('获取权益分类失败:', error);
  261. }
  262. }
  263. // 地区选项
  264. const regionOptions = ref();
  265. const provinceoptions = ref();
  266. // 获取地区数据
  267. const queryTreeQuery = () => {
  268. api.areaApi.areaList({}).then((res: any) => {
  269. if (res.code == '200') {
  270. regionOptions.value = res.data;
  271. } else {
  272. ElMessage({
  273. type: 'success',
  274. message: res.msg,
  275. plain: true,
  276. })
  277. }
  278. });
  279. }
  280. const provinceChange = (value: any) => {
  281. if (value && value[0] != null && value[1] != null && value[2] != null) {
  282. queryInfo.value.countryAll = value[0] + value[1] + value[2];
  283. getPrivilegeItem()
  284. } else {
  285. queryInfo.value.countryAll = '';
  286. getPrivilegeItem()
  287. }
  288. }
  289. const cancel = () => {
  290. // 重置表单
  291. form.recipient = '';
  292. form.region = [];
  293. emits('update:show', false);
  294. }
  295. const iframeUrl = ref('');//权益单品详情
  296. const iframeLoading = ref(false); // 详情加载中,显示加载占位
  297. const rightsUrlCache = new Map<string | number, string>(); // 权益详情地址缓存
  298. let latestRequestId = 0; // 竞态标记:只让最后一次移入的请求生效
  299. const benefitDetail = (item: any) => {
  300. // 缓存命中:直接显示,不发请求,不闪
  301. const cachedUrl = rightsUrlCache.get(item.id);
  302. if (cachedUrl) {
  303. iframeUrl.value = cachedUrl;
  304. return;
  305. }
  306. // 未命中:显示加载占位并请求详情(不清空 iframeUrl,保留旧内容直到新内容就绪)
  307. const requestId = ++latestRequestId;
  308. iframeLoading.value = true;
  309. api.additionalApi.rightsProduct({
  310. rightsId: item.id,
  311. }).then((res: any) => {
  312. if (requestId !== latestRequestId) {
  313. return; // 已有更新的移入,丢弃过期响应
  314. }
  315. if (res.code == '200') {
  316. const url = `https://life.baoxianzhanggui.com/custh5/#/packageF/pages/home/details-channel?productId=${res.data[0].productId}`
  317. rightsUrlCache.set(item.id, url);
  318. iframeUrl.value = url;
  319. }
  320. iframeLoading.value = false;
  321. });
  322. console.log(item)
  323. }
  324. const save = () => {
  325. console.log(privilegeItem.value)
  326. const selectedItems = privilegeItem.value?.filter((item: any) => item.rightsCount > 0) || []
  327. if(selectedItems.length == 0){
  328. ElMessage({
  329. type: 'warning',
  330. message: '请选择后再提交,不能直接提交',
  331. plain: true,
  332. })
  333. return
  334. }
  335. // 发送表单数据
  336. emits("save", selectedItems)
  337. emits('update:show', false);
  338. }
  339. </script>
  340. <!-- 样式区域 -->
  341. <style lang='scss' scoped>
  342. .tab-btn {
  343. >.content {
  344. flex: 1;
  345. .tabs {
  346. .item {
  347. cursor: pointer;
  348. padding: 5px 12px;
  349. box-sizing: border-box;
  350. border-radius: 2px 2px 2px 2px;
  351. border: 1px solid #E5E5E5;
  352. font-size: 14px;
  353. color: #333;
  354. }
  355. .item.active {
  356. background: #0083FF;
  357. border: 1px solid #0083FF;
  358. color: #fff;
  359. }
  360. }
  361. }
  362. }
  363. .orderIssueFee {
  364. background: #F5F5F5;
  365. border-radius: 4px 4px 4px 4px;
  366. margin-top: 20px;
  367. padding: 12px 16px;
  368. box-sizing: border-box;
  369. .expenseInfo {
  370. >div span:first-child {
  371. font-size: 12px;
  372. color: #666;
  373. }
  374. >div span:last-child {
  375. font-size: 14px;
  376. color: #333;
  377. margin-left: 4px;
  378. }
  379. }
  380. .commentText {
  381. margin-top: 10px;
  382. span {
  383. font-size: 12px;
  384. color: #333;
  385. margin-left: 2px;
  386. }
  387. }
  388. }
  389. .PackageselectedList {
  390. .view-card {
  391. width: 250px;
  392. .view-item {
  393. cursor: pointer;
  394. background: #F7F7F7;
  395. padding: 10px;
  396. box-sizing: border-box;
  397. border-radius: 4px 4px 4px 4px;
  398. }
  399. .view-item:hover {
  400. background: #dfdfdf;
  401. }
  402. }
  403. .view-card .active {
  404. background: #dfdfdf;
  405. color: #fff;
  406. }
  407. }
  408. // 自定义抽屉样式
  409. :deep(.el-drawer__header) {
  410. padding: 18px 24px;
  411. box-sizing: border-box;
  412. border-bottom: 1px solid #E5E5E5;
  413. font-size: 20px;
  414. color: #333;
  415. font-weight: bold;
  416. margin-bottom: 0;
  417. }
  418. :deep(.el-drawer) {
  419. border-radius: 8px 0 0 8px;
  420. }
  421. :deep(.el-drawer__body) {
  422. padding: 24px;
  423. box-sizing: border-box;
  424. }
  425. :deep(.el-drawer__footer) {
  426. box-shadow: 0px -1px 1px 0px rgba(0, 0, 0, 0.05);
  427. }
  428. .iframe-container {
  429. width: 100%;
  430. height: 600px;
  431. /* 固定高度 */
  432. }
  433. .external-iframe {
  434. width: 100%;
  435. height: 100%;
  436. border: none;
  437. }
  438. // 权益详情加载占位
  439. .iframe-loading {
  440. width: 100%;
  441. height: 600px;
  442. display: flex;
  443. align-items: center;
  444. justify-content: center;
  445. color: #909399;
  446. font-size: 14px;
  447. }
  448. // 移入权益名称变色效果
  449. .rights-name-link {
  450. cursor: pointer;
  451. &:hover {
  452. color: #409EFF;
  453. }
  454. }
  455. // 移入权益名称时当前单元格背景色(!important 压过 el-table 行 hover 背景)
  456. :deep(.el-table__body td.el-table__cell:has(.rights-name-link:hover)) {
  457. background-color: #F6FBFF !important;
  458. }
  459. // 权益数量步进器:加减号背景白色、图标固定蓝色(默认和悬停均为蓝色)
  460. .rights-count-input {
  461. :deep(.el-input-number__increase),
  462. :deep(.el-input-number__decrease) {
  463. background-color: #fff !important;
  464. color: #0083FF !important;
  465. .el-icon {
  466. color: #0083FF !important;
  467. }
  468. &:hover {
  469. background-color: #fff !important;
  470. color: #0083FF !important;
  471. .el-icon {
  472. color: #0083FF !important;
  473. }
  474. }
  475. }
  476. // 去掉鼠标移入时的蓝色边框,保持原灰色边框
  477. :deep(.el-input__wrapper) {
  478. &:hover {
  479. box-shadow: 0 0 0 1px var(--el-input-border-color, #dcdfe6) inset;
  480. }
  481. }
  482. }
  483. </style>