dialog-selectEquipment.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <dialog-base ref="baseDialog" title="请选择">
  3. <!-- <view class="equipment-container uni-row ">
  4. <view v-for="(item, index) in equipments" :class="{'item':true,'selected': isSelected(item)}" :key="index"
  5. @click="handleSelection(item)"><text class="label">{{item['equipmentDetailCode']}}</text></view>
  6. </view> -->
  7. <view v-if="showProcessList">
  8. <uni-section title="工序" type="line">
  9. <uni-data-select v-model="selectedProcess" :localdata="processList" :clear="false"
  10. @change="handleProcessChange"></uni-data-select>
  11. </uni-section>
  12. </view>
  13. <view>
  14. <uni-section title="设备" type="line">
  15. <uni-data-select v-model="selectedEquipment" :localdata="equipmentList" :clear="false"
  16. @change="handleEquipmentChange"></uni-data-select>
  17. </uni-section>
  18. </view>
  19. <!-- <view class="switch uni-row">
  20. <text class="label">是否邀请协作者</text>
  21. <view class="uni-row" style="align-items: center;">
  22. <text>否</text>
  23. <switch class="switch" @change="switchChange" />
  24. <text>是</text>
  25. </view>
  26. </view>
  27. <view class="userList" v-if="flag">
  28. <uni-easyinput class="uni-mt-5" v-model="userName" placeholder="请输入协作者编号"
  29. @input="debounce(handleSearchUserName,500)" @blur="handleBlur"></uni-easyinput>
  30. <view class="uni-row showUser">
  31. <view v-for="(item,index) in userList">
  32. <view class="user" @click="handleClickUserName(item)">{{item.nickName}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="uni-row selectedUserList">
  37. <view class="selectedUser uni-row" v-for="(item,index) in selectedUserList">
  38. <view>{{item.nickName}}</view>
  39. <view v-if="selectedUserList.length > 0" @click="handleRemoveUserName(item)">×</view>
  40. </view>
  41. </view> -->
  42. <view class="add-btn-container uni-row">
  43. <button type="primary" class="btn" @click="handleStart">开始</button>
  44. </view>
  45. </dialog-base>
  46. </template>
  47. <script setup>
  48. import {
  49. ref
  50. } from 'vue'
  51. import {
  52. onLoad
  53. } from '@dcloudio/uni-app'
  54. import {
  55. getProcessList
  56. } from '@/api/business/deptProcess.js'
  57. import {
  58. getUserequipmentList
  59. } from '@/api/business/userEquipment/userEquipment.js'
  60. import {
  61. getUserInfo
  62. } from '@/api/login/index.js'
  63. import {
  64. saveDayWorkItem,
  65. getDayWorkItemList
  66. } from '@/api/business/dayWorkItem.js'
  67. import {
  68. store
  69. } from '@/store/index.js'
  70. import {
  71. getEquipmentByUidAndDid
  72. } from '@/api/resourceGroup/resourceGroupDetail.js'
  73. import {
  74. timestampToTime,
  75. debounce
  76. } from '@/utils/common.js'
  77. import {
  78. getUserByLikeUsername
  79. } from '@/api/sys/user.js'
  80. const baseDialog = ref(null)
  81. const equipments = ref([]) // 接收设备列表信息
  82. const equipmentList = ref([])
  83. const emit = defineEmits(['handleAddDayWorkItem'])
  84. const userId = ref(null)
  85. const firstItem = ref(null);
  86. const sendReqParam = ref({})
  87. const processList = ref([])
  88. const selectedProcess = ref(null)
  89. const selectedEquipment = ref(null)
  90. const flag = ref(false)
  91. const userName = ref(null)
  92. const userList = ref([])
  93. const selectedUserList = ref([])
  94. const showProcessList = ref(true)
  95. onLoad(() => {
  96. userId.value = store.userInfo.userId || "";
  97. })
  98. function resetPage() {
  99. flag.value = false;
  100. userName.value = null;
  101. userList.value = [];
  102. equipmentList.value = [];
  103. selectedEquipment.value = null;
  104. selectedUserList.value = [];
  105. selectedProcess.value = null;
  106. processList.value = [];
  107. showProcessList.value = true;
  108. }
  109. function init() {
  110. getProcessList({
  111. // tenantId: store.tenantId,
  112. deptId: store.curDeptDetails.deptId,
  113. dayworkId: store.dayworkInfo.id
  114. }).then(res => {
  115. console.log(res)
  116. if (res.code == 200) {
  117. //过滤出工序交集store.dayworkInfo.processSequence
  118. let filteredData = store.dayworkInfo.processSequence.filter((item1) =>{
  119. return res.data.some(item2 => item2.processCode === item1.processCode) &&
  120. store.dayworkInfo.currentProcess.processStepNumber === item1.processStepNumber;
  121. });
  122. console.log(filteredData)
  123. /* 20240409 修改
  124. for (let i = 0; i < filteredData.length; i++) {
  125. // console.log(processList.value)
  126. processList.value[i] = {
  127. text: filteredData[i].processAlias,
  128. value: filteredData[i].technologicalProcessDetailId,
  129. processId: filterData[i].id
  130. // value: filteredData[i].id
  131. }
  132. // console.log(processList.value)
  133. }
  134. */
  135. console.log(store.dayworkInfo)
  136. processList.value = filteredData.map(v => ({
  137. text: v.processAlias,
  138. value: v.technologicalProcessDetailId,
  139. processId: v.id,
  140. processStepNumber:store.dayworkInfo.currentProcess.processStepNumber
  141. }))
  142. console.log(processList.value)
  143. selectedProcess.value = filteredData[0].technologicalProcessDetailId;
  144. // selectedProcess.value = filteredData[0].processId
  145. // console.log(selectedProcess.value)
  146. isDefaultItem(firstItem.value);
  147. }
  148. })
  149. // Promise.all([getEquipmentByUidAndDid(store.planDetails.id), getDayWorkItemList({
  150. // // userId: store.userInfo.userId,
  151. // // dayworkId: store.dayworkInfo.id,
  152. // status: 1
  153. // })])
  154. // .then(([equipmentRes, response]) => {
  155. // console.log(equipmentRes)
  156. // console.log(response.rows)
  157. // if (equipmentRes.code == 200 && response.code == 200) {
  158. // let equipmentListData = equipmentRes.rows.filter((equipment) => {
  159. // return !response.rows.some((item) => item.equipmentDetailId == equipment.commonId);
  160. // });
  161. // equipmentList.value = equipmentListData.map((equipment) => {
  162. // return {
  163. // text: equipment.commonCode,
  164. // value: equipment
  165. // }
  166. // });
  167. // selectedEquipment.value = equipmentListData.length > 0 ? equipmentListData[0] : null;
  168. // }
  169. // baseDialog.value.open()
  170. // });
  171. getEquipmentByUidAndDid(store.planDetails.id,store.curDeptDetails.deptId,store.dayworkInfo.lotId).then(equipmentRes => {
  172. if(equipmentRes.code == 200){
  173. for (var i = 0; i < equipmentRes.rows.length; i++) {
  174. equipmentList.value[i] = {
  175. text: equipmentRes.rows[i].commonCode,
  176. value: equipmentRes.rows[i]
  177. }
  178. }
  179. selectedEquipment.value = equipmentRes.rows.length > 0 ? equipmentRes.rows[0] : null;
  180. }
  181. baseDialog.value.open()
  182. })
  183. }
  184. function open(data) {
  185. resetPage()
  186. firstItem.value = data;
  187. console.log(store.dayworkInfo)
  188. userName.value = null;
  189. userList.value = [];
  190. init();
  191. }
  192. function isDefaultItem(item){
  193. if(item){
  194. showProcessList.value = false;
  195. selectedProcess.value = null;
  196. }
  197. }
  198. function close() {
  199. baseDialog.value.close()
  200. }
  201. defineExpose({
  202. open
  203. })
  204. function handleProcessChange() {
  205. }
  206. function handleEquipmentChange() {
  207. }
  208. function handleSearchUserName() {
  209. if (userName.value) {
  210. getUserByLikeUsername(userName.value).then(res => {
  211. if (res.code == 200) {
  212. userList.value = res.data;
  213. }
  214. })
  215. }
  216. }
  217. function handleClickUserName(item) {
  218. selectedUserList.value.push(item);
  219. userList.value = [];
  220. }
  221. function handleBlur() {
  222. setTimeout(function() {
  223. userList.value = [];
  224. }, 200)
  225. }
  226. function handleRemoveUserName(item) {
  227. selectedUserList.value.splice(selectedUserList.value.indexOf(item), 1);
  228. }
  229. function switchChange(e) {
  230. flag.value = e.detail.value;
  231. }
  232. function handleStart() {
  233. uni.showModal({
  234. title: "提示",
  235. content: "确认开始新的报工吗",
  236. success: function(res) {
  237. if (res.confirm) {
  238. handleDoStart();
  239. } else if (res.cancel) {
  240. close();
  241. }
  242. }
  243. })
  244. }
  245. function handleDoStart() {
  246. // if (!selectedProcess.value || !selectedEquipment.value) {
  247. // uni.showToast({
  248. // icon: "none",
  249. // title: "未选择工序或设备"
  250. // })
  251. // selectedProcess.value = null;
  252. // selectedEquipment.value = null;
  253. // return;
  254. // }
  255. close();
  256. if (firstItem.value) {
  257. sendReqParam.value = {
  258. ...firstItem.value,
  259. /* 20240408 前版本
  260. processId: selectedProcess.value,
  261. */
  262. technologicalProcessDetailId: selectedProcess.value,
  263. processId: store.dayworkInfo.currentProcess.id,
  264. equipmentDetailId: selectedEquipment.value.commonId,
  265. processStepNumber:store.dayworkInfo.currentProcess.processStepNumber,
  266. equipmentDetailCode: selectedEquipment.value.commonCode,
  267. startTime: timestampToTime(new Date()),
  268. status: 1,
  269. collaborationList: selectedUserList.value
  270. };
  271. console.log(sendReqParam.value)
  272. emit('handleAddDayWorkItem', sendReqParam.value);
  273. } else {
  274. emit('handleAddDayWorkItem', {
  275. /* 20240408 前版本
  276. processId: selectedProcess.value,
  277. */
  278. technologicalProcessDetailId: selectedProcess.value,
  279. processId: store.dayworkInfo.currentProcess.id,
  280. // processId: store.dayworkInfo.processSequence.findIndex(v => v.technologicalProcessDetailId === selectedProcess.value) >= 0 ? store.dayworkInfo.processSequence.find(v => v.technologicalProcessDetailId === selectedProcess.value).id : null,
  281. equipmentDetailId: selectedEquipment.value.commonId,
  282. processStepNumber:store.dayworkInfo.currentProcess.processStepNumber,
  283. equipmentDetailCode: selectedEquipment.value.commonCode,
  284. collaborationList: selectedUserList.value
  285. });
  286. }
  287. }
  288. </script>
  289. <style lang="scss">
  290. .dialog-body {
  291. .equipment-container {
  292. height: 300rpx;
  293. overflow: auto;
  294. flex-wrap: wrap;
  295. justify-content: flex-start;
  296. margin: 24rpx 0 0 7%;
  297. .item {
  298. width: 236rpx;
  299. height: 60rpx;
  300. text-align: center;
  301. line-height: 60rpx;
  302. border-radius: 6rpx;
  303. margin: 16rpx;
  304. flex: 0 0 40%;
  305. border: 1px solid #000000;
  306. }
  307. .selected {
  308. background-color: #1684fc;
  309. color: #FFF;
  310. }
  311. }
  312. .add-btn-container {
  313. margin-top: 32rpx;
  314. .btn {
  315. flex: 1;
  316. }
  317. }
  318. .switch {
  319. font-size: 26rpx;
  320. align-items: center;
  321. justify-content: space-between;
  322. margin: 16rpx;
  323. }
  324. .userList {
  325. border: 1rpx solid #1684fc;
  326. border-radius: 8rpx;
  327. max-height: 300rpx;
  328. overflow: auto;
  329. width: 100%;
  330. .showUser {
  331. justify-content: flex-start;
  332. flex-wrap: wrap;
  333. .user {
  334. border: 1rpx solid #999;
  335. border-radius: 8rpx;
  336. width: 150rpx;
  337. height: 50rpx;
  338. text-align: center;
  339. line-height: 50rpx;
  340. margin: 10rpx;
  341. overflow: auto;
  342. }
  343. }
  344. }
  345. .selectedUserList {
  346. width: 100%;
  347. justify-content: flex-start;
  348. flex-wrap: wrap;
  349. .selectedUser {
  350. border: 1rpx solid #999;
  351. border-radius: 8rpx;
  352. width: 150rpx;
  353. height: 50rpx;
  354. text-align: center;
  355. line-height: 50rpx;
  356. margin: 20rpx 20rpx 0 0;
  357. justify-content: space-around;
  358. }
  359. }
  360. }
  361. </style>