add.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <!-- 模板区域 -->
  2. <template>
  3. <div class="body">
  4. <div class="card">
  5. <a-form ref="formRef" :model="distributionRecordForm" layout="vertical" labelAlign="right" :label-col="labelCol"
  6. :rules="distributionRecordFormRules">
  7. <div class="card-header dis a-c mb-2">
  8. <div class="link"></div>
  9. <span>基本信息</span>
  10. </div>
  11. <div class="horizontal-section">
  12. <a-row :gutter="30">
  13. <a-col :span="6">
  14. <a-form-item label="发放渠道" name="institutionId">
  15. <a-tree-select v-model:value="distributionRecordForm.institutionId" @change="institutionChange"
  16. show-search style="width: 100%" :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
  17. placeholder="Please select" allow-clear tree-default-expand-all :tree-data="treeData" :field-names="{
  18. children: 'node',
  19. label: 'institutionName',
  20. value: 'id',
  21. }" tree-node-filter-prop="institutionName">
  22. </a-tree-select>
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="6">
  26. <a-form-item label="发放人" name="grantUserName">
  27. <a-input v-model:value="distributionRecordForm.grantUserName" showCount maxlength="20"
  28. placeholder="请输入发放人" />
  29. </a-form-item>
  30. </a-col>
  31. <a-col :span="6">
  32. <a-form-item label="发放人手机号" name="grantUserPhone">
  33. <a-input v-model:value="distributionRecordForm.grantUserPhone" showCount maxlength="11"
  34. placeholder="请输入发放人手机号" allowClear />
  35. </a-form-item>
  36. </a-col>
  37. <a-col :span="12">
  38. <a-form-item label="备注">
  39. <a-textarea v-model:value="distributionRecordForm.remark" show-count :maxlength="500"
  40. placeholder="请输入内容...." />
  41. </a-form-item>
  42. </a-col>
  43. </a-row>
  44. <a-row :gutter="30">
  45. <a-col :span="8">
  46. <a-form-item label="接收人" name="fileUrl">
  47. <a-upload-dragger v-model:fileList="fileList" name="file" :action="UploadUrl" @change="fileChange"
  48. accept=".xls,.xlsx">
  49. <p class="ant-upload-drag-icon">
  50. <inbox-outlined></inbox-outlined>
  51. </p>
  52. <template v-if="distributionRecordForm.fileUrl">
  53. <span class="fontsize14">{{ distributionRecordForm.fileUrl }}</span>
  54. </template>
  55. <template v-else>
  56. <p class="fontsize14">点击或将文件拖拽到这里上传,或者 <span style="color: #018FFB;">点击上传</span> </p>
  57. </template>
  58. </a-upload-dragger>
  59. <div class="dis a-c">
  60. <a-button type="link" @click="downloadTemplate">下载模版</a-button>
  61. <span class="fontsize14">仅允许导入“xls”或“xlsx”格式文件!最多导入1500人 </span>
  62. </div>
  63. <!-- 导入提示 -->
  64. <div class="importPrompt" v-if="fileresult.failRows">
  65. <div class="dis a-c">
  66. <InfoCircleOutlined style="font-size: 18px;color: #FAA21E;" />
  67. <span class="fontsize14 ml-1">您将导入 <span style="color: #018FFB;">{{ fileresult.totalRows }}</span>
  68. 条数据,其中 <span style="color: #018FFB;">{{ fileresult.successRows }}</span> 条正常导入;<span
  69. style="color: #FF4545;">{{
  70. fileresult.failRows }}</span>
  71. 条不符合要求无法导入</span>
  72. </div>
  73. <a-button type="link" @click="downloadFailedFile">下载导入失败文件</a-button>
  74. </div>
  75. </a-form-item>
  76. </a-col>
  77. </a-row>
  78. </div>
  79. <div class="card-header dis a-c mb-2">
  80. <div class="link"></div>
  81. <span>权益礼包</span>
  82. </div>
  83. <a-table :dataSource="distributionRecordForm.rightsList" size="small" :columns="Columns" :pagination="false"
  84. rowClassName="rowClassName">
  85. <template #bodyCell="{ column, record, index }">
  86. <template v-if="column.dataIndex === 'operation'">
  87. <a-button type="link" @click="rightsListAdd(column, record)">添加</a-button>
  88. <a-button type="link" @click="rightsListDel(column, record, index)" :disabled="index === 0">删除</a-button>
  89. </template>
  90. <template v-if="column.dataIndex === 'rightsContentName'">
  91. <a-select v-model:value="record.rightsContentId" placeholder="权益搜索" style="width: 300px"
  92. :options="entitlementPackages" :field-names="{ label: 'rightsContentName', value: 'rightsContentId' }">
  93. <template #dropdownRender>
  94. <div class="benefit">
  95. <div class="header dis a-c j-s">
  96. <span style="width: 50%;">权益名称</span>
  97. <span style="width: 25%;">类型</span>
  98. <span style="width: 25%;">采购价</span>
  99. </div>
  100. <div class="custom-options">
  101. <div v-for="item in entitlementPackages" :key="item.rightsContentId"
  102. class="option-item dis a-c j-s" @click="handleSelect(item, index)">
  103. <span style="width: 50%;">{{ item.rightsContentName }}</span>
  104. <span style="width: 25%;">{{ item.rightsContentType == 1 ? '单独权益' : '权益包' }}</span>
  105. <span style="width: 25%;">{{ item.settlePrice || 0 }}元</span>
  106. </div>
  107. </div>
  108. </div>
  109. </template>
  110. </a-select>
  111. </template>
  112. <template v-if="column.dataIndex === 'rightsType'">
  113. <span v-if="record.rightsType == '1'">单独权益</span>
  114. <span v-else-if="record.rightsType == '2'">权益包</span>
  115. <span v-else></span>
  116. </template>
  117. <template v-if="column.dataIndex === 'rightsCount'">
  118. <a-input-number v-model:value="record.rightsCount" style="width: 100%" allowClear placeholder="请输入权益数量" />
  119. </template>
  120. <template v-if="column.dataIndex === 'totalPrice'">
  121. <span>{{ Decimal(record.settlePrice || 0).times(record.rightsCount || 0) }}元</span>
  122. </template>
  123. </template>
  124. </a-table>
  125. </a-form>
  126. </div>
  127. <!-- 操作栏 -->
  128. <div class="footer flex a-c j-c">
  129. <a-button @click="onCancel">取消</a-button>
  130. <a-button @click="onSubmit" style="margin-left: 40px" type="primary">保存</a-button>
  131. </div>
  132. </div>
  133. </template>
  134. <!-- 行为区域 -->
  135. <script lang='ts' setup>
  136. import { reactive, ref, onMounted } from 'vue';
  137. import type { UnwrapRef } from 'vue';
  138. import { useRouter, useRoute } from 'vue-router';
  139. import { InboxOutlined, InfoCircleOutlined, ExclamationCircleFilled } from '@ant-design/icons-vue';
  140. import type { Rule, } from 'ant-design-vue/es/form';
  141. import * as businessConfigAPI from '/@/api/channel/businessConfig';
  142. import { type TreeSelectProps } from 'ant-design-vue';
  143. import * as distributionRecordAPI from '/@/api/channel/distributionRecord';
  144. import { message, Modal } from 'ant-design-vue';
  145. import { Decimal } from "decimal.js";
  146. import { useGlobSetting } from '/@/hooks/setting';
  147. import { createVNode } from 'vue';
  148. const globSetting = useGlobSetting();
  149. const baseUploadUrl = globSetting.uploadUrl;
  150. const UploadUrl = `${baseUploadUrl}/channel/grantRecord/uploadReceiverFile`; // 上传地址
  151. onMounted(() => {
  152. queryChannelOrg()//获取渠道机构数据
  153. })
  154. // 发放失败弹窗
  155. const failedToIssue = (failedFileUrl: string) => {
  156. Modal.confirm({
  157. title: '发放失败',
  158. okText: '忽略,确认发放',
  159. cancelText: '查看错误数据',
  160. content: '错误信息,本次发放权益的金额大于导入文件内的结算金额,请确认是否继续发放。',
  161. icon: createVNode(ExclamationCircleFilled, { style: 'color: #ff4d4f' }),
  162. onOk: () => {
  163. // 处理发放失败逻辑
  164. console.log(distributionRecordForm)
  165. return;
  166. distributionRecordAPI.addDistributionRecord(distributionRecordForm).then(res => {
  167. if (res.code === 200) {
  168. message.success('发放记录已保存');
  169. } else {
  170. message.error(res.message || '发放失败记录保存失败');
  171. }
  172. });
  173. },
  174. onCancel: () => {
  175. let Url = 'E:/workspace/opt/upFiles' + '/' + failedFileUrl;
  176. // 处理查看错误数据逻辑
  177. window.open(Url);
  178. },
  179. });
  180. }
  181. interface FormState {
  182. [key: string]: any;//默认全类型
  183. }
  184. // 校验规则弹窗
  185. const fileList = ref([]);//
  186. const formRef = ref();
  187. const treeData = ref<TreeSelectProps['treeData']>([]);//渠道机构数据
  188. const fileresult = ref<FormState>({});//文件上传后数据
  189. const labelCol = { style: { width: '150px' } };
  190. const entitlementPackages = ref();//权益礼包列表数据
  191. // 业务配置表单
  192. const distributionRecordForm: UnwrapRef<FormState> = reactive({
  193. institutionId: '',//机构id
  194. grantUserName: '',//联系人
  195. grantUserPhone: '',//联系人电话
  196. remark: '',//备注
  197. fileUrl: '',//接收人文件url
  198. failedFileUrl: '',//发放失败文件url
  199. rightsList: [
  200. {
  201. rightsContentId: "",//权益id
  202. rightsContentName: "",//权益名称
  203. rightsCount: 1,//权益数量
  204. rightsType: null,//权益类型
  205. settlePrice: "",//结算价
  206. totalPrice: "",//总价
  207. }
  208. ],//权益礼包
  209. });
  210. const distributionRecordFormRules: Record<string, Rule[]> = {
  211. institutionId: [
  212. { required: true, message: '请选择合作渠道机构', trigger: 'change' },
  213. ],
  214. grantUserName: [
  215. { required: true, message: '联系人姓名必填', trigger: 'blur' },
  216. ],
  217. grantUserPhone: [
  218. { required: true, message: '联系人手机号必填', trigger: 'blur' },
  219. {
  220. pattern: /^[0-9]+$/,
  221. message: '请输入正确手机号',
  222. },
  223. {
  224. min: 11,
  225. max: 11,
  226. message: '请输入11位手机号',
  227. },
  228. ],
  229. fileUrl: [
  230. { required: true, message: '请上传发放人群', trigger: 'blur' },
  231. ],
  232. };
  233. const Columns = [
  234. {
  235. title: '操作',
  236. dataIndex: 'operation',
  237. key: 'operation',
  238. align: "center",
  239. width: 200,
  240. },
  241. {
  242. title: '权益名称',
  243. dataIndex: 'rightsContentName',
  244. key: 'rightsContentName',
  245. align: "center",
  246. },
  247. {
  248. title: '权益类型',
  249. dataIndex: 'rightsType',
  250. key: 'rightsType',
  251. width: 200,
  252. align: "center"
  253. },
  254. {
  255. title: '结算价',
  256. dataIndex: 'settlePrice',
  257. key: 'settlePrice',
  258. align: "center",
  259. width: 200,
  260. },
  261. {
  262. title: '数量',
  263. dataIndex: 'rightsCount',
  264. key: 'rightsCount',
  265. align: "center",
  266. width: 200,
  267. },
  268. {
  269. title: '总价',
  270. dataIndex: 'totalPrice',
  271. key: 'totalPrice',
  272. align: "center",
  273. width: 200,
  274. },
  275. ]
  276. const onSubmit = () => {
  277. formRef.value.validate().then(() => {
  278. // 校验通过,提交表单数据
  279. console.log('表单数据:', distributionRecordForm);
  280. distributionRecordAPI.validateBeforeSubmit(distributionRecordForm).then(res => {
  281. if (res.code === 200) {
  282. if (res.result.success) {
  283. distributionRecordAPI.addDistributionRecord(distributionRecordForm).then(res => {
  284. if (res.code === 200) {
  285. message.success('发放成功');
  286. } else {
  287. message.error(res.message || '发放失败');
  288. }
  289. })
  290. } else {
  291. let Url = 'E:/workspace/opt/upFiles' + '/' + res.result.failedFileUrl;
  292. distributionRecordForm.failedFileUrl = res.result.failedFileUrl;
  293. failedToIssue(Url)
  294. }
  295. } else {
  296. message.error(res.message || '校验失败');
  297. }
  298. })
  299. }).catch(() => {
  300. // 校验不通过,处理错误逻辑
  301. console.log('校验失败');
  302. });
  303. }
  304. const handleSelect = (val: any, index: number) => {
  305. Object.assign(distributionRecordForm.rightsList[index], val)
  306. distributionRecordForm.rightsList[index].rightsType = val.rightsContentType
  307. };
  308. // 添加权益
  309. const rightsListAdd = (column, record) => {
  310. console.log(record)
  311. if (distributionRecordForm.rightsList.length >= 20) {
  312. message.error('最多添加20个权益')
  313. return
  314. } else {
  315. distributionRecordForm.rightsList.push({
  316. rightsContentId: "",
  317. rightsCount: 1,//权益数量
  318. rightsType: "",//权益类型
  319. })
  320. }
  321. }
  322. // 删除权益
  323. const rightsListDel = (column, record, index) => {
  324. distributionRecordForm.rightsList.splice(index, 1)
  325. }
  326. // 机构改变时查询权益
  327. const institutionChange = (val: string) => {
  328. getEntitlementPackages()
  329. };
  330. const getEntitlementPackages = () => {
  331. distributionRecordAPI.getChannelRightsByInstitution({
  332. institutionId: distributionRecordForm.institutionId,
  333. name: "",
  334. }).then(res => {
  335. if (res.code === 200) {
  336. entitlementPackages.value = res.result
  337. } else {
  338. message.error(res.msg || '权益查询失败');
  339. }
  340. })
  341. }
  342. // 获取业务配置渠道机构
  343. const queryChannelOrg = () => {
  344. businessConfigAPI.getChannelDeptList().then((res) => {
  345. if (res.code == 200) {
  346. treeData.value = res.result
  347. }
  348. });
  349. }
  350. // 文件上传
  351. const fileChange = async (info) => {
  352. if (info.file.status === 'done') {
  353. if (info.file.response.code == '200') {
  354. message.success(info.file.response.message);//文件上传成功
  355. fileresult.value = info.file.response.result;
  356. // let url= import.meta.env.VITE_GLOB_DOMAIN_URL + '/' + info.file.response.result.fileUrl;
  357. let fileUrl = 'E:/workspace/opt/upFiles' + '/' + info.file.response.result.fileUrl;
  358. let failedFileUrl = 'E:/workspace/opt/upFiles' + '/' + info.file.response.result.failedFileUrl;
  359. distributionRecordForm.fileUrl = fileUrl;
  360. distributionRecordForm.failedFileUrl = failedFileUrl;
  361. } else {
  362. message.error(info.file.response.message);//文件上传失败
  363. return
  364. }
  365. }
  366. }
  367. const onCancel = () => {
  368. window.close();
  369. }
  370. // 下载模版
  371. const downloadTemplate = () => {
  372. window.open(
  373. 'https://life.baoxianzhanggui.com/locallive-pro-java/channel/receiver/模板.xlsx',
  374. );
  375. }
  376. const downloadFailedFile = () => {
  377. window.open(
  378. distributionRecordForm.failedFileUrl,
  379. );
  380. }
  381. </script>
  382. <!-- 样式区域 -->
  383. <style lang='less' scoped>
  384. .body {
  385. padding: 10px 0px;
  386. box-sizing: border-box;
  387. height: 100%;
  388. .card {
  389. padding: 0 24px;
  390. box-sizing: border-box;
  391. background-color: #fff;
  392. border-radius: 4px;
  393. overflow-y: auto;
  394. height: calc(100vh - 192px);
  395. }
  396. }
  397. // 底部布局
  398. .footer {
  399. position: fixed;
  400. bottom: 0;
  401. right: 0;
  402. background: #fff;
  403. width: calc(100vw - 210px);
  404. height: 60px;
  405. padding: 10px 30px;
  406. box-sizing: border-box;
  407. >span {
  408. font-size: 16px;
  409. color: #1890FF;
  410. }
  411. }
  412. .card-header {
  413. padding: 20px 0;
  414. box-sizing: border-box;
  415. .link {
  416. width: 3px;
  417. height: 20px;
  418. border-radius: 0 5px 5px 0;
  419. background-color: #018FFB;
  420. margin-right: 7px;
  421. }
  422. font-size: 20px;
  423. color: #333;
  424. font-weight: bold;
  425. border-bottom: 1px solid #E5E5E5;
  426. }
  427. .card-Radio-container {
  428. gap: 0 24px;
  429. .card-Radio {
  430. position: relative;
  431. width: max-content;
  432. padding: 16px;
  433. box-sizing: border-box;
  434. background: #FFFFFF;
  435. border-radius: 4px 4px 4px 4px;
  436. border: 2px solid #E5E5E5;
  437. cursor: pointer;
  438. .Method {
  439. font-size: 14px;
  440. color: #333;
  441. font-weight: bold;
  442. line-height: 1.4;
  443. margin-bottom: 4px;
  444. }
  445. .annotation {
  446. font-size: 14px;
  447. color: #999;
  448. }
  449. .anticon-check-circle {
  450. position: absolute;
  451. top: 7px;
  452. right: 7px;
  453. font-size: 21px;
  454. color: #018FFB;
  455. }
  456. }
  457. .card-Radio-active {
  458. border: 2px solid #80C7FD;
  459. }
  460. }
  461. .color-preview {
  462. width: 120px;
  463. padding: 3px 10px;
  464. box-sizing: border-box;
  465. border-radius: 4px 4px 4px 4px;
  466. border: 1px solid #E5E5E5;
  467. .colorBlock {
  468. width: 16px;
  469. height: 16px;
  470. }
  471. span {
  472. font-size: 14px;
  473. color: #333;
  474. margin-left: 4px;
  475. }
  476. }
  477. .text {
  478. font-size: 14px;
  479. color: #999;
  480. }
  481. .w250 {
  482. width: 250px;
  483. }
  484. .fontsize14 {
  485. font-size: 14px;
  486. color: #333;
  487. }
  488. .table {
  489. width: 800px;
  490. }
  491. .merchantSupplier {
  492. padding: 6px 10px;
  493. box-sizing: border-box;
  494. background: #E9F4FF;
  495. border-radius: 2px 2px 2px 2px;
  496. width: auto;
  497. font-size: 14px;
  498. color: #018FFB;
  499. }
  500. .received {
  501. margin-left: 160px;
  502. }
  503. .importPrompt {
  504. background: #FFFAEF;
  505. border-radius: 4px 4px 4px 4px;
  506. border: 1px solid #FAA21E;
  507. padding: 16px;
  508. box-sizing: border-box;
  509. }
  510. .benefit {
  511. .header {
  512. padding: 4px;
  513. box-sizing: border-box;
  514. background: #F7F7F9;
  515. border-radius: 4px 4px 0px 0px;
  516. font-size: 14px;
  517. color: #333;
  518. font-weight: bold;
  519. border: 1px solid #EEEEEE;
  520. text-align: center;
  521. }
  522. .custom-options {
  523. max-height: 200px;
  524. overflow-y: auto;
  525. }
  526. .option-item {
  527. padding: 8px 6px;
  528. width: 100%;
  529. border-radius: 4px;
  530. span {
  531. text-align: center;
  532. }
  533. }
  534. .option-item:hover {
  535. background-color: #F7F7F9;
  536. }
  537. }
  538. </style>