dialog-selectEquipment.vue 11 KB

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