clock-user.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <!-- @desc:工位打卡 @auth:周兴 @time:2023/3/15 17:03 -->
  2. <template>
  3. <div class="main-div" ref="mainDiv">
  4. <!--加载中-->
  5. <loading :loading="loading" v-if="!modalVisible"></loading>
  6. <DkCollapse ref="collapse" @on-change="changeCollapse">
  7. <DkPanel prop="wsClockInformation">
  8. <!-- 下拉区域 -->
  9. <DkForm slot="content" ref="formInline" v-model="formData" style="width: 95%">
  10. <!-- 工位编码-->
  11. <DkFormItem prop="stationCode">
  12. <SelectPop v-model="formData.stationId" :multiple="false" :options="stationList" ref="roleName"
  13. @on-select="chooseStation"
  14. labelKey="stationCode"
  15. valueKey=stationId>
  16. </SelectPop>
  17. </DkFormItem>
  18. <!-- 工位名称-->
  19. <DkFormItem prop="stationName">
  20. <InputPop ref="stationName" :readonly="true" v-model="formData.stationName"/>
  21. </DkFormItem>
  22. </DkForm>
  23. </DkPanel>
  24. <!-- 打卡明细-->
  25. <DkPanel prop="wsClockItemInformation">
  26. <EditTable slot="content" ref="editTableWsClockItem" name="table"
  27. :height="tableHeight"
  28. major-field="staffId"
  29. :enabledRepeat=false
  30. controlId="jobId"
  31. :operate-flag="false"
  32. :auto-next-flag="false"
  33. :id="'table-'+$options.name"
  34. :columns="editTableColumn"
  35. :data="formData.wsClockItemList"
  36. @current-change="currentChange"
  37. @chooseData="chooseData"
  38. ></EditTable>
  39. </DkPanel>
  40. </DkCollapse>
  41. <!-- 下部分按钮区域-->
  42. <DkSaveButton ref="saveButton" :loading="loading" :viewFlag="true" @save="save" @close="closeForm">
  43. <DkButton ref="saveWork" type="primary"
  44. @click="save(true)" style="margin-right: 10px;" :loading="loading">{{ $t('saveWork') }}
  45. </DkButton>
  46. <DkButton ref="saveOffWork" type="primary"
  47. @click="save(false)" style="margin-right: 10px;" :loading="loading">{{ $t('saveOffWork') }}
  48. </DkButton>
  49. </DkSaveButton>
  50. </div>
  51. </template>
  52. <script>
  53. import {formMixin} from "@/mixins/form";
  54. import {getTagNavListFromLocalstorage} from "@/libs/base/util";
  55. export default {
  56. name: "ws-clock-user",
  57. mixins: [formMixin],
  58. data() {
  59. let self = this
  60. return {
  61. formData: {
  62. userId: this.$store.state.user.id,//工号id
  63. stationId: '',//工位id
  64. stationName: '',//工位名称
  65. wsClockItemList: [], //打卡明细
  66. },
  67. stationList: [],//工位数据
  68. jobList: [],//工种数据
  69. rowIndex: 0,//打卡明细选中行
  70. editTableColumn: [
  71. // 工种名称
  72. {field: 'jobName', type: 'disabled', width: '255'},
  73. // 业务员
  74. {
  75. field: 'staffName',
  76. width: 255,
  77. sortBoolean: false,
  78. multiple: false,
  79. type: 'tableSelect',
  80. param: () => {
  81. return {
  82. jobId: (self.formData.wsClockItemList && self.formData.wsClockItemList[self.rowIndex])
  83. ? parseInt(self.formData.wsClockItemList[self.rowIndex].jobId) : null,
  84. staffUserId: this.$store.state.user.id
  85. }
  86. },
  87. dataType: self.$config.tableSelectType.staff,
  88. fieldUpdate: self.$updateColumns.userChooseStaff,
  89. searchDetailFlag: false
  90. },
  91. // 替班员工
  92. {
  93. field: 'replaceStaffName',
  94. width: 255,
  95. sortBoolean: false,
  96. multiple: false,
  97. type: 'tableSelect',
  98. dataType: self.$config.tableSelectType.staff,
  99. fieldUpdate: self.$updateColumns.userChooseReplaceStaff,
  100. searchDetailFlag: false
  101. },
  102. ],
  103. }
  104. },
  105. methods: {
  106. //region 获取数据源
  107. /**
  108. * @desc : 获取工位
  109. * @author : 夏常明
  110. * @date : 2023/3/1 15:37
  111. */
  112. getStationList() {
  113. let params = {
  114. ftyId: this.$store.state.user.ftyId,
  115. userId: this.$store.state.user.id,//工号id
  116. }
  117. this.excute(this.$service.commonService, this.$service.commonService.getWsStationByUser, params).then(res => {
  118. if (res.code === this.$config.SUCCESS_CODE) {
  119. this.stationList = res.data;
  120. //工位数量为1 默认选中
  121. if (this.stationList.length == 1) {
  122. this.formData.stationId = this.stationList[0].stationId;
  123. this.formData.stationName = this.stationList[0].stationName;
  124. }
  125. }
  126. })
  127. },
  128. /**
  129. * @desc : 获取工种
  130. * @author : 夏常明
  131. * @date : 2023/3/1 15:40
  132. */
  133. getJobList() {
  134. let params = {
  135. ftyId: this.$store.state.user.ftyId,
  136. userId: this.$store.state.user.id,//工号id
  137. }
  138. this.excute(this.$service.commonService, this.$service.commonService.getWorkTeamByUserId, params).then(res => {
  139. if (res.code === this.$config.SUCCESS_CODE) {
  140. this.formData.wsClockItemList = res.data;
  141. }
  142. })
  143. },
  144. /**
  145. * @desc : 工位选中改变事件
  146. * @author : 夏常明
  147. * @date : 2023/3/1 16:14
  148. */
  149. chooseStation(val) {
  150. if (val) {
  151. let row = this.stationList.find(item => item.stationId == val);
  152. this.formData.stationName = row.stationName
  153. } else {
  154. this.formData.stationName = '';
  155. }
  156. },
  157. //endregion
  158. //region 触发事件
  159. /**
  160. * @desc : 打卡明细行切换时间
  161. * @author : 夏常明
  162. * @date : 2023/2/27 17:14
  163. */
  164. currentChange(e) {
  165. this.rowIndex = 0
  166. this.rowIndex = e.rowIndex
  167. },
  168. /**
  169. * @desc : 选择数据
  170. * @author : 周兴
  171. * @date : 2023/3/1 15:34
  172. */
  173. chooseData(row, rowIndex, colItem) {
  174. // 如果选择员工需要清空替班,选择替班需要清空员工
  175. if (colItem.field === 'staffName') {
  176. this.$set(this.formData.wsClockItemList[rowIndex], 'replaceStaffId', null);
  177. this.$set(this.formData.wsClockItemList[rowIndex], 'replaceStaffName', null)
  178. } else if (colItem.field === 'replaceStaffName') {
  179. this.$set(this.formData.wsClockItemList[rowIndex], 'staffId', null);
  180. this.$set(this.formData.wsClockItemList[rowIndex], 'staffName', null)
  181. }
  182. },
  183. /**
  184. * @desc : 校验数据是否全
  185. * @author : 周兴
  186. * @date : 2023/2/2 15:57
  187. */
  188. validData(flag) {
  189. if (flag) {
  190. let table = this.$refs.editTableWsClockItem.getTableData();
  191. // 判断是否有打卡明细信息
  192. if (!table || table.length === 0) {
  193. this.$Message.warning(this.$t('W_103'))
  194. return false;
  195. }
  196. for (let i = 0; i < table.length; i++) {
  197. // 员工和替班员工需要 二选一
  198. if (!table[i].staffId && !table[i].replaceStaffId) {
  199. this.$Message.warning(this.$t('W_107', {'param1': (i + 1)}))
  200. this.setErrToRow(table[i], this.$t('W_108'));// 给行增加错误提示信息
  201. return false;
  202. }
  203. }
  204. }
  205. return true;
  206. },
  207. /**
  208. * @desc : 保存数据
  209. * @author : 夏常明
  210. * @date : 2023/3/2 8:35
  211. */
  212. saveData(flag) {
  213. if (flag) {
  214. return this.excute(this.$service.wsClockService, this.$service.wsClockService.insert, this.params)
  215. } else {
  216. let params = {
  217. userId: this.$store.state.user.id,
  218. }
  219. return this.excute(this.$service.wsClockService, this.$service.wsClockService.saveOffWork, params)
  220. }
  221. },
  222. /**
  223. * @desc : 给参数赋值
  224. * @author : 姜宁
  225. * @date : 2023/2/1 15:28
  226. */
  227. setParams() {
  228. this.params = {...this.formData}
  229. //装载区域
  230. this.params.wsClockItemList = this.$refs.editTableWsClockItem.getTableData();
  231. this.params.wsClockItemList.forEach(it => {
  232. if (!it.staffId) {
  233. it.staffId = it.replaceStaffId;
  234. it.userId = this.$store.state.user.id;
  235. it.stationId = this.formData.stationId;
  236. }
  237. })
  238. },
  239. /**
  240. * @desc : 关闭窗体
  241. * @author : 周兴
  242. * @date : 2023/3/15 17:11
  243. */
  244. closeForm() {
  245. this.close();
  246. this.$nextTick(() => {
  247. // 跳转到首页
  248. if (!this.$store.state.app.tagNavList || this.$store.state.app.tagNavList.length === 0) {
  249. this.$router.push({name: this.$config.homeName})
  250. }
  251. })
  252. },
  253. //endregion
  254. },
  255. /**
  256. * @desc : 在实例创建完成后被立即同步调用
  257. * @author : 周兴
  258. * @date : 2022/3/3 10:32
  259. */
  260. created() {
  261. this.getStationList();//获取工位
  262. this.getJobList();//获取工位
  263. this.resizeTableFlag = true; // 计算表格高度
  264. },
  265. }
  266. </script>
  267. <style scoped>
  268. </style>