performance.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <div class="performance">
  3. <div class="title-box-common">
  4. <h3>员工绩效</h3>
  5. </div>
  6. <div class="padding-box-common">
  7. <div class="search-box" style="padding: 0 10px">
  8. <a-input-search
  9. v-model:value="search.uname"
  10. placeholder="请输入推广员名称"
  11. style="width: 180px"
  12. @keyup.enter="getList"
  13. />
  14. <div class="right-search">
  15. <span v-show="search.type === 'month'">自定义月数:</span>
  16. <span v-show="search.type === 'day'">自定义天数:</span>
  17. <a-input
  18. v-model:value="search.value"
  19. placeholder="请输入"
  20. style="width: 100px"
  21. type="number"
  22. :min="0"
  23. :max="30"
  24. :precision="0"
  25. :onkeyup="(search.value = String(search.value).replace(/\D/g, ''))"
  26. @keyup.enter="getList"
  27. />&nbsp;
  28. <a-select
  29. style="width: 100px"
  30. v-model:value="search.type"
  31. @change="onTypeChange"
  32. >
  33. <a-select-option value="month">按月查询</a-select-option>
  34. <a-select-option value="day">按日查询</a-select-option> </a-select
  35. >&nbsp;
  36. <el-date-picker
  37. v-if="search.type === 'month'"
  38. v-model="search.date_arr"
  39. type="monthrange"
  40. range-separator="-"
  41. start-placeholder="开始月份"
  42. end-placeholder="结束月份"
  43. @change="getList"
  44. size="small"
  45. style="width: 240px"
  46. value-format="YYYY-MM"
  47. >
  48. </el-date-picker>
  49. <el-date-picker
  50. v-else
  51. v-model="search.date_arr"
  52. type="daterange"
  53. range-separator="-"
  54. start-placeholder="开始日期"
  55. end-placeholder="结束日期"
  56. @change="getList"
  57. size="small"
  58. style="width: 240px"
  59. value-format="YYYY-MM-DD"
  60. >
  61. </el-date-picker>
  62. </div>
  63. </div>
  64. <div class="table-box">
  65. <a-radio-group
  66. v-model:value="search.model"
  67. @change="getList"
  68. style="margin: 10px 0"
  69. >
  70. <a-radio-button value="natural">自然日数据</a-radio-button>
  71. <a-radio-button value="precise">顺延24小时数据</a-radio-button>
  72. </a-radio-group>
  73. <a-table
  74. bordered
  75. :scroll="{ x: 1700 }"
  76. :data-source="list"
  77. :columns="columns"
  78. @change="getList"
  79. rowKey="uid"
  80. :loading="loading"
  81. :pagination="tablePageOptions"
  82. >
  83. <template #operation="{ record }">
  84. <a-button type="link" @click="toDetial(record)">查看详情</a-button>
  85. </template>
  86. </a-table>
  87. </div>
  88. </div>
  89. </div>
  90. </template>
  91. <script lang="tsx">
  92. import usePagination from "@/hooks/usePagination";
  93. import { defineComponent, reactive, toRefs, ref } from "vue";
  94. import { Moment } from "moment";
  95. import { TableColumnOfStuffPerformance } from "../_pageOptions/table_data";
  96. //getPromotionList
  97. import { getStuffPerformance } from "@/api";
  98. import { message } from "ant-design-vue";
  99. import { ColumnProps } from 'ant-design-vue/es/table/interface';
  100. const Performance = defineComponent({
  101. components: {},
  102. setup() {
  103. let { meta,tablePageOptions } = usePagination();
  104. const state = reactive({
  105. search: {
  106. uname: "", // 推广员名称
  107. type: "month", // 时间类型 day/month
  108. model: "natural", // 计算方式 自然日:natural/ 顺延24小时:precise
  109. value: ref<any[number | string]>(3), // 自定义月数、天数
  110. date_arr: ref<any[]>([]),
  111. },
  112. loading: false,
  113. list: ref<any[]>([]),
  114. });
  115. const columns: ColumnProps[] = []
  116. return {
  117. ...toRefs(state),
  118. tablePageOptions,
  119. meta,
  120. columns
  121. };
  122. },
  123. mounted() {
  124. this.columnsInit()
  125. // this.getList({ current: 1 });
  126. this.onTypeChange("month");
  127. },
  128. methods: {
  129. // columns初始化
  130. columnsInit() {
  131. this.columns = [{
  132. title: '推广员',
  133. dataIndex: 'uname',
  134. fixed: 'left',
  135. width: 150,
  136. },
  137. {
  138. title: '成本合计(元)',
  139. dataIndex: 'cost_amount',
  140. width:120
  141. },
  142. {
  143. title: '回本(元)',
  144. dataIndex: 'back_amount',
  145. sorter: (a: any, b: any) => a.back_amount - b.back_amount,
  146. width:120
  147. },
  148. {
  149. title: '提现合计(元)',
  150. dataIndex: 'cash_withdrawal_amount',
  151. width:120
  152. },
  153. //
  154. {
  155. title: '用户充值(元)',
  156. dataIndex: 'user_charge_amount_sum',
  157. width:120
  158. },
  159. //
  160. {
  161. title: '操作',
  162. dataIndex: 'operation',
  163. slots: { customRender: 'operation' },
  164. fixed: 'right',
  165. }]
  166. },
  167. // 获取推广链接数据
  168. async getList(page?: any, filters?: any, sorter?: any) {
  169. if(this.search.value > 30) {
  170. message.warning('不能超过30')
  171. this.search.value = 30
  172. }
  173. console.log("SORT", page, filters, sorter);
  174. this.loading = true;
  175. let param: any = {
  176. start_date: this.search.date_arr ? this.search.date_arr[0] : "",
  177. end_date: this.search.date_arr ? this.search.date_arr[1] : "",
  178. ...this.search,
  179. };
  180. delete param.date_arr;
  181. console.log("请求参数", param);
  182. let { data } = await getStuffPerformance({
  183. page: page ? page.current : 1,
  184. ...param,
  185. });
  186. console.log("请求结果", data);
  187. this.list = data.list;
  188. this.meta = data.meta;
  189. this.customColumns();
  190. this.loading = false;
  191. },
  192. // 月、日查询类型改变
  193. onTypeChange(val: string) {
  194. var date = new Date((new Date).getTime()-24*60*60*1000);
  195. console.log(val);
  196. if (val === "month") {
  197. this.search.value = 3;
  198. var list = this.getDateRange(date, 30, true);
  199. console.log(list[0].substring(0, 7));
  200. this.search.date_arr = [
  201. list[0].substring(0, 7),
  202. list[1].substring(0, 7),
  203. ];
  204. } else {
  205. this.search.value = "";
  206. var list = this.getDateRange(date, 7, true);
  207. this.search.date_arr = list;
  208. }
  209. this.getList();
  210. },
  211. // 搜索条件修改后 处理columns
  212. customColumns() {
  213. this.columnsInit()
  214. let withdrawalIndex = 0, chargeIndex = 0;
  215. this.columns.forEach((item,index)=> {
  216. if(item.dataIndex === 'cash_withdrawal_amount') withdrawalIndex = index
  217. if(item.dataIndex === 'user_charge_amount_sum') chargeIndex = index+2
  218. })
  219. // 选择按月查询 1.自然日从0加起-默认展示M+0、M+1、M+2 \ 2.24小时-从1加起-默认展示M+1、M+2
  220. if(this.search.type === 'month') { // 按月查询
  221. if(this.search.model === 'natural') { // 自然日
  222. if(!this.search.value) {// 默认 未输入自定义月数
  223. for(let i = 0; i< 3; i++) {
  224. this.columns.splice(withdrawalIndex+(i+1), 0,{
  225. title: '提现(元)M+'+ i,
  226. dataIndex: 'cash_withdrawal',
  227. width: 150,
  228. customRender: ({ text, record }) => {
  229. return (<div style="color:gray;font-size:13px">
  230. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  231. <p>累计提现: { text[i].accruing_amount }</p>
  232. <p>回本率: { text[i].back_rate }</p>
  233. </div>)
  234. },
  235. })
  236. this.columns.splice(chargeIndex+(i*2), 0,{
  237. title: '用户充值(元)M+'+ i,
  238. dataIndex: 'user_charge',
  239. width: 150,
  240. customRender: ({ text, record }) => {
  241. return (<div style="color:gray;font-size:13px">
  242. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  243. <p>累计提现: { text[i].accruing_amount }</p>
  244. <p>回本率: { text[i].back_rate }</p>
  245. </div>)
  246. },
  247. })
  248. }
  249. } else { // 自定义月数
  250. for(let i = 0; i< this.search.value; i++) {
  251. this.columns.splice(withdrawalIndex+(i+1), 0,{
  252. title: '提现(元)M+'+ i,
  253. dataIndex: 'cash_withdrawal',
  254. width: 150,
  255. customRender: ({ text, record }) => {
  256. return (<div style="color:gray;font-size:13px">
  257. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  258. <p>累计提现: { text[i].accruing_amount }</p>
  259. <p>回本率: { text[i].back_rate }</p>
  260. </div>)
  261. },
  262. })
  263. this.columns.splice(chargeIndex+(i*2), 0,{
  264. title: '用户充值(元)M+'+ i,
  265. dataIndex: 'user_charge',
  266. width: 150,
  267. customRender: ({ text, record }) => {
  268. return (<div style="color:gray;font-size:13px">
  269. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  270. <p>累计提现: { text[i].accruing_amount }</p>
  271. <p>回本率: { text[i].back_rate }</p>
  272. </div>)
  273. },
  274. })
  275. }
  276. }
  277. } else { // 24小时
  278. if(!this.search.value) { // 未输入月数 默认
  279. for(let i =0; i< 3; i++) {
  280. this.columns.splice(withdrawalIndex+(i+1), 0,{
  281. title: '提现(元)M+'+ (i+1),
  282. dataIndex: 'cash_withdrawal',
  283. width: 150,
  284. customRender: ({ text, record }) => {
  285. return (<div style="color:gray;font-size:13px">
  286. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  287. <p>累计提现: { text[i].accruing_amount }</p>
  288. <p>回本率: { text[i].back_rate }</p>
  289. </div>)
  290. },
  291. })
  292. this.columns.splice(chargeIndex+(i*2), 0,{
  293. title: '用户充值(元)M+'+ (i+1),
  294. dataIndex: 'user_charge',
  295. width: 150,
  296. customRender: ({ text, record }) => {
  297. return (<div style="color:gray;font-size:13px">
  298. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  299. <p>累计提现: { text[i].accruing_amount }</p>
  300. <p>回本率: { text[i].back_rate }</p>
  301. </div>)
  302. },
  303. })
  304. }
  305. } else { // 自定义月数
  306. for(let i = 0; i< this.search.value; i++) {
  307. this.columns.splice(withdrawalIndex+(i+1), 0,{
  308. title: '提现(元)M+'+ (i+1),
  309. dataIndex: 'cash_withdrawal',
  310. width: 150,
  311. customRender: ({ text, record }) => {
  312. return (<div style="color:gray;font-size:13px">
  313. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  314. <p>累计提现: { text[i].accruing_amount }</p>
  315. <p>回本率: { text[i].back_rate }</p>
  316. </div>)
  317. },
  318. })
  319. this.columns.splice(chargeIndex+(i*2), 0,{
  320. title: '用户充值(元)M+'+(i+1),
  321. dataIndex: 'user_charge',
  322. width: 150,
  323. customRender: ({ text, record }) => {
  324. return (<div style="color:gray;font-size:13px">
  325. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  326. <p>累计提现: { text[i].accruing_amount }</p>
  327. <p>回本率: { text[i].back_rate }</p>
  328. </div>)
  329. },
  330. })
  331. }
  332. }
  333. }
  334. } else { // 选择按日查询 1.自然日从0加起-默认展示T+0、T+2、T+6、T+14、T+29 \ 2.24小时-从1加起-默认展示T+0、T+2、T+6、T+14、T+29
  335. if(!this.search.value) {// 默认 未输入自定义月数
  336. for(let i = 0; i< 5; i++) {
  337. this.columns.splice(withdrawalIndex+(i+1), 0,{
  338. title: '提现(元)T+'+ [0,2,6,14,29][i],
  339. dataIndex: 'cash_withdrawal',
  340. width: 150,
  341. customRender: ({ text, record }) => {
  342. return (<div style="color:gray;font-size:13px">
  343. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  344. <p>累计提现: { text[i].accruing_amount }</p>
  345. <p>回本率: { text[i].back_rate }</p>
  346. </div>)
  347. },
  348. })
  349. this.columns.splice(chargeIndex+(i*2), 0,{
  350. title: '用户充值(元)M+'+ [0,2,6,14,29][i],
  351. dataIndex: 'user_charge',
  352. width: 150,
  353. customRender: ({ text, record }) => {
  354. return (<div style="color:gray;font-size:13px">
  355. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  356. <p>累计提现: { text[i].accruing_amount }</p>
  357. <p>回本率: { text[i].back_rate }</p>
  358. </div>)
  359. },
  360. })
  361. }
  362. } else { // 自定义月数
  363. for(let i = 0; i< this.search.value; i++) {
  364. this.columns.splice(withdrawalIndex+(i+1), 0,{
  365. title: '提现(元)M+'+ i,
  366. dataIndex: 'cash_withdrawal',
  367. width: 150,
  368. customRender: ({ text, record }) => {
  369. return (<div style="color:gray;font-size:13px">
  370. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  371. <p>累计提现: { text[i].accruing_amount }</p>
  372. <p>回本率: { text[i].back_rate }</p>
  373. </div>)
  374. },
  375. })
  376. this.columns.splice(chargeIndex+(i*2), 0,{
  377. title: '用户充值(元)M+'+ i,
  378. dataIndex: 'user_charge',
  379. width: 150,
  380. customRender: ({ text, record }) => {
  381. return (<div style="color:gray;font-size:13px">
  382. <p style="color:black;font-size:14px">{ text[i].amount }</p>
  383. <p>累计提现: { text[i].accruing_amount }</p>
  384. <p>回本率: { text[i].back_rate }</p>
  385. </div>)
  386. },
  387. })
  388. }
  389. }
  390. }
  391. },
  392. // 返回需要添加的列
  393. // 工具函数:获取最近日期
  394. getDateRange(dateNow: any, intervalDays: any, bolPastTime: any) {
  395. let oneDayTime = 24 * 60 * 60 * 1000;
  396. let list = [];
  397. let lastDay;
  398. if (bolPastTime == true) {
  399. lastDay = new Date(dateNow.getTime() - intervalDays * oneDayTime);
  400. list.push(this.formateDate(lastDay));
  401. list.push(this.formateDate(dateNow));
  402. } else {
  403. lastDay = new Date(dateNow.getTime() + intervalDays * oneDayTime);
  404. list.push(this.formateDate(dateNow));
  405. list.push(this.formateDate(lastDay));
  406. }
  407. return list;
  408. },
  409. formateDate(time: any) {
  410. let year = time.getFullYear();
  411. let month = time.getMonth() + 1;
  412. let day = time.getDate();
  413. if (month < 10) {
  414. month = "0" + month;
  415. }
  416. if (day < 10) {
  417. day = "0" + day;
  418. }
  419. return year + "-" + month + "-" + day + "";
  420. },
  421. // 查看详情
  422. toDetial(item: any) {
  423. console.log("查看详情", item);
  424. this.$router.push(
  425. `/data/performanceDetail?uid=${item.uid}&uname=${item.uname}`
  426. );
  427. },
  428. },
  429. });
  430. export default Performance;
  431. </script>
  432. <style lang="scss" scoped>
  433. @import "@/assets/common-style/frame.scss";
  434. .performance {
  435. .search-box {
  436. display: flex;
  437. justify-content: space-between;
  438. }
  439. .table-box {
  440. padding: 0 10px;
  441. }
  442. .detail-num {
  443. color: gray;
  444. }
  445. .small-font {
  446. font-size: 13px;
  447. }
  448. }
  449. </style>