performance.vue 15 KB

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