technician-roster.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. v-bind="bindVal"
  5. v-on="onEvent"
  6. v-model="form"
  7. :page.sync="page"
  8. :before-open="handleBeforeOpen"
  9. :permission="permissionList"
  10. >
  11. <template slot="menuLeft">
  12. <!-- <el-button
  13. v-if="!isSelAnnual"
  14. type="danger"
  15. size="small"
  16. icon="el-icon-delete"
  17. plain
  18. @click="handleDelete"
  19. >
  20. 删 除
  21. </el-button> -->
  22. <el-button
  23. v-if="!isSelAnnual"
  24. type="success"
  25. size="small"
  26. plain
  27. icon="el-icon-upload2"
  28. @click="handleImport"
  29. >
  30. 导入
  31. </el-button>
  32. <el-button
  33. type="warning"
  34. size="small"
  35. plain
  36. icon="el-icon-download"
  37. @click="handleExport"
  38. >
  39. 导出
  40. </el-button>
  41. <el-button
  42. v-if="!isSelAnnual"
  43. type="primary"
  44. size="small"
  45. plain
  46. @click="handleReadyLastMonData"
  47. >
  48. 读取上个月人员名单
  49. </el-button>
  50. <print-table-btn @click="printTable" />
  51. </template>
  52. <template slot="departmentIdForm">
  53. <second-unit-cascader v-model="form.departmentId" :yearAndMonth="currYear" @change="handleSecondUnitChange" />
  54. </template>
  55. <template slot="hireDateSearch">
  56. <span>入职时间:</span>
  57. <el-date-picker
  58. v-model="extraParams.hireDateRange"
  59. type="daterange"
  60. range-separator="至"
  61. start-placeholder="开始日期"
  62. end-placeholder="结束日期"
  63. value-format="yyyy-MM-dd"
  64. style="width: 240px !important;"
  65. >
  66. </el-date-picker>
  67. </template>
  68. <template slot="body">
  69. <h3 class="page-title">{{ pageTitle }}</h3>
  70. <year-month-select v-model="params.yearAndMonth"></year-month-select>
  71. </template>
  72. </avue-crud>
  73. <upload-excel-dialog ref="uploadExcelDialog" :showTempBtn="false" templateKey="技术人员花名册-导入模板" templateName="技术人员花名册-导入模板" :uploadAfter="uploadAfter"/>
  74. <WideTablePrinter
  75. ref="printWideTable"
  76. :columns="wideTableColumns"
  77. :data="wideTableData"
  78. :print-title="pageTitle"
  79. :rows-per-page="30"
  80. :default-landscape="true"
  81. :zoom="60"
  82. />
  83. </basic-container>
  84. </template>
  85. <script>
  86. import { getLastMonthData } from "@/api/basicResource/technicianRoster";
  87. import {exportBloByPost} from "@/api/common";
  88. import YearMonthSelect from "@/components/year-month-select";
  89. import UploadExcelDialog from "@/components/upload-excel-dialog";
  90. import moment from "moment";
  91. import {getToken} from "@/util/auth";
  92. import {downloadXls} from "@/util/util";
  93. import { isAlphanumericCombination } from "@/util/regex";
  94. import secondUnitCascader from "@/components/second-unit-cascader";
  95. import { mapGetters } from "vuex";
  96. export default window.$crudCommon({
  97. components: {
  98. YearMonthSelect,
  99. UploadExcelDialog,
  100. secondUnitCascader
  101. },
  102. data() {
  103. return {
  104. params: {
  105. yearAndMonth: "",
  106. },
  107. isSelAnnual: false, // 是否选择全年
  108. wideTableColumns: [],
  109. wideTableData: [],
  110. printTitle: "",
  111. secondUnitNameArr: [],
  112. };
  113. },
  114. watch: {
  115. 'params.yearAndMonth'(newVal) {
  116. if (newVal.length > 4) {
  117. // 是否勾选未全年
  118. this.isSelAnnual = false;
  119. } else {
  120. this.isSelAnnual = true;
  121. }
  122. this.page.currentPage = 1;
  123. this.getList(this.page);
  124. this.option.column.forEach(item => {
  125. if (item.prop == 'hireDate') {
  126. let lastMonthEndDate = moment(newVal).subtract(1, 'months').endOf('months').format('YYYY-MM-DD'); // 上个月最后一天
  127. let monthEndDate = moment(newVal).endOf('months').format('YYYY-MM-DD'); // 当前月最后一天
  128. item.defaultValue = monthEndDate;
  129. item.pickerOptions = {
  130. disabledDate(time) {
  131. // return time.getTime() < new Date(lastMonthEndDate).getTime() || time.getTime() > new Date(monthEndDate).getTime();
  132. return time.getTime() > new Date(monthEndDate).getTime();
  133. }
  134. };
  135. }
  136. });
  137. },
  138. },
  139. computed: {
  140. ...mapGetters(['tag']),
  141. currYear() {
  142. return moment(this.params.yearAndMonth).format('YYYY')
  143. },
  144. permissionList() {
  145. return {
  146. addBtn: !this.isSelAnnual,
  147. editBtn: !this.isSelAnnual,
  148. delBtn: !this.isSelAnnual,
  149. };
  150. },
  151. pageTitle() {
  152. let yearAndMonthCN = '';
  153. if (this.params.yearAndMonth) {
  154. let formatTemp = this.isSelAnnual ? "yyyy年" : "yyyy年MM月";
  155. yearAndMonthCN = moment(this.params.yearAndMonth).format(formatTemp);
  156. }
  157. return `${yearAndMonthCN}${this.tag.label}`;
  158. }
  159. },
  160. methods: {
  161. getSearchParams() {
  162. let searchParams = { ...this.params, ...this.extraParams };
  163. if (!!searchParams.hireDateRange) {
  164. searchParams.hireDateMin = searchParams.hireDateRange[0];
  165. searchParams.hireDateMax = searchParams.hireDateRange[1];
  166. }
  167. delete searchParams.hireDateRange;
  168. return searchParams;
  169. },
  170. handleSecondUnitChange(val, nameArr) {
  171. this.secondUnitNameArr = nameArr;
  172. },
  173. validCustom() {
  174. if (!this.form.number && !this.form.idCard) {
  175. this.$message.warning("工号和身份证号必须填写一项!");
  176. return false;
  177. }
  178. // else if (this.form.number && !isAlphanumericCombination(this.form.number)) {
  179. // this.$message.warning("工号必须是英文字母加数字组合!");
  180. // return false;
  181. // }
  182. return true;
  183. },
  184. getFormData() {
  185. let _deptId;
  186. if (this.form.departmentId && this.form.departmentId instanceof Array) {
  187. _deptId = this.form.departmentId[this.form.departmentId.length - 1];
  188. }
  189. return { ...this.form, departmentId: _deptId, department: this.secondUnitNameArr.join('/'), yearAndMonth: this.params.yearAndMonth };
  190. },
  191. addBefore(loading, callback) {
  192. if (!this.validCustom()) {
  193. loading();
  194. return;
  195. }
  196. callback && callback();
  197. },
  198. updateBefore(loading, callback) {
  199. if (!this.validCustom()) {
  200. loading();
  201. return false;
  202. }
  203. callback && callback();
  204. },
  205. getDelParams(row) {
  206. return [{ id: row.id, yearAndMonth: this.params.yearAndMonth }];
  207. },
  208. getBatchDelParams() {
  209. let delArr = [];
  210. this.data.forEach(item => {
  211. if (this.ids.indexOf(item.id) > -1) {
  212. delArr.push({ yearAndMonth: this.params.yearAndMonth, id: item.id });
  213. }
  214. });
  215. return delArr;
  216. },
  217. handleImport() {
  218. let excelParams = { yearAndMonth: this.params.yearAndMonth };
  219. this.$refs.uploadExcelDialog.open('/api/kd-scientific/technician/import', excelParams);
  220. },
  221. uploadAfter() {
  222. this.page.currentPage = 1;
  223. this.getList(this.page);
  224. },
  225. handleExport() {
  226. exportBloByPost(`/api/kd-scientific/technician/export?${this.website.tokenHeader}=${getToken()}`, this.params).then(res => {
  227. downloadXls(res.data, `${this.pageTitle}.xlsx`);
  228. });
  229. },
  230. handleReadyLastMonData() {
  231. this.$confirm("确认要读取上个月的数据吗?", "提示", {
  232. confirmButtonText: "确定",
  233. cancelButtonText: "取消",
  234. type: "warning"
  235. }).then(() => {
  236. getLastMonthData({ yearAndMonth: this.params.yearAndMonth}).then(res => {
  237. let data = res.data;
  238. if (data.success) {
  239. this.$message.success('读取成功!');
  240. this.page.currentPage = 1;
  241. this.getList(this.page);
  242. }
  243. });
  244. });
  245. },
  246. /**
  247. * 打印表格
  248. * @param isLandscape 是否横向打印
  249. */
  250. printTable(isLandscape) {
  251. this.wideTableColumns = this.printOption.column;
  252. this.wideTableData = [...this.$refs.crud.list]
  253. this.$nextTick(() => {
  254. this.$refs.printWideTable.printTable(isLandscape);
  255. })
  256. },
  257. },
  258. }, {
  259. // 模块路径
  260. name: 'basicResource/technicianRoster',
  261. res: ({ data }) => {
  262. data.records = data.records.map(item => {
  263. item.gender = item.gender ? String(item.gender) : '';
  264. item.birthday = item.birthday ? moment(item.birthday).format('yyyy-MM-DD') : '';
  265. item.hireDate = item.hireDate ? moment(item.hireDate).format('yyyy-MM-DD') : '';
  266. return item;
  267. });
  268. return data;
  269. },
  270. });
  271. </script>