dialog-selectEquipment.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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"
  18. placeholder="请选择/输入设备"></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(
  174. equipmentRes => {
  175. if (equipmentRes.code == 200) {
  176. for (var i = 0; i < equipmentRes.rows.length; i++) {
  177. equipmentList.value[i] = {
  178. text: equipmentRes.rows[i].commonCode,
  179. value: equipmentRes.rows[i]
  180. }
  181. }
  182. // selectedEquipment.value = equipmentRes.rows.length > 0 ? equipmentRes.rows[0] : null;
  183. }
  184. baseDialog.value.open()
  185. })
  186. }
  187. function open(data) {
  188. resetPage()
  189. firstItem.value = data;
  190. console.log(store.dayworkInfo)
  191. userName.value = null;
  192. userList.value = [];
  193. init();
  194. }
  195. function isDefaultItem(item) {
  196. if (item) {
  197. showProcessList.value = false;
  198. selectedProcess.value = null;
  199. }
  200. }
  201. function close() {
  202. baseDialog.value.close()
  203. }
  204. defineExpose({
  205. open
  206. })
  207. function handleProcessChange() {
  208. }
  209. function handleEquipmentChange() {
  210. }
  211. function handleSearchUserName() {
  212. if (userName.value) {
  213. getUserByLikeUsername(userName.value).then(res => {
  214. if (res.code == 200) {
  215. userList.value = res.data;
  216. }
  217. })
  218. }
  219. }
  220. function handleClickUserName(item) {
  221. selectedUserList.value.push(item);
  222. userList.value = [];
  223. }
  224. function handleBlur() {
  225. setTimeout(function() {
  226. userList.value = [];
  227. }, 200)
  228. }
  229. function handleRemoveUserName(item) {
  230. selectedUserList.value.splice(selectedUserList.value.indexOf(item), 1);
  231. }
  232. function switchChange(e) {
  233. flag.value = e.detail.value;
  234. }
  235. function handleStart() {
  236. uni.showModal({
  237. title: "提示",
  238. content: "确认开始新的报工吗",
  239. success: function(res) {
  240. if (res.confirm) {
  241. handleDoStart();
  242. } else if (res.cancel) {
  243. close();
  244. }
  245. }
  246. })
  247. }
  248. function handleDoStart() {
  249. if (!selectedEquipment.value) {
  250. uni.showToast({
  251. icon: "none",
  252. title: "未选择设备"
  253. })
  254. selectedProcess.value = null;
  255. selectedEquipment.value = null;
  256. return;
  257. }
  258. close();
  259. if (firstItem.value) {
  260. sendReqParam.value = {
  261. ...firstItem.value,
  262. /* 20240408 前版本
  263. processId: selectedProcess.value,
  264. */
  265. technologicalProcessDetailId: store.dayworkInfo.processSequence.filter(v => v.processStepNumber ==
  266. store.dayworkInfo.currentProcess.processStepNumber)[0].technologicalProcessDetailId,
  267. processId: store.dayworkInfo.currentProcess.id,
  268. equipmentDetailId: selectedEquipment.value.commonId,
  269. processStepNumber: store.dayworkInfo.currentProcess.processStepNumber,
  270. equipmentDetailCode: selectedEquipment.value.commonCode,
  271. startTime: timestampToTime(new Date()),
  272. status: 1,
  273. collaborationList: selectedUserList.value
  274. };
  275. console.log(sendReqParam.value)
  276. emit('handleAddDayWorkItem', sendReqParam.value);
  277. } else {
  278. emit('handleAddDayWorkItem', {
  279. /* 20240408 前版本
  280. processId: selectedProcess.value,
  281. */
  282. technologicalProcessDetailId: store.dayworkInfo.processSequence.filter(v => v.processStepNumber ==
  283. store.dayworkInfo.currentProcess.processStepNumber)[0].technologicalProcessDetailId,
  284. processId: store.dayworkInfo.currentProcess.id,
  285. // processId: store.dayworkInfo.processSequence.findIndex(v => v.technologicalProcessDetailId === selectedProcess.value) >= 0 ? store.dayworkInfo.processSequence.find(v => v.technologicalProcessDetailId === selectedProcess.value).id : null,
  286. equipmentDetailId: selectedEquipment.value.commonId,
  287. processStepNumber: store.dayworkInfo.currentProcess.processStepNumber,
  288. equipmentDetailCode: selectedEquipment.value.commonCode,
  289. collaborationList: selectedUserList.value
  290. });
  291. }
  292. }
  293. </script>
  294. <style lang="scss">
  295. .dialog-container {
  296. .dialog-body {
  297. margin-top: 180rpx !important;
  298. margin-left: auto !important;
  299. margin-right: auto !important;
  300. .equipment-container {
  301. height: 300rpx;
  302. overflow: auto;
  303. flex-wrap: wrap;
  304. justify-content: flex-start;
  305. margin: 24rpx 0 0 7%;
  306. .item {
  307. width: 236rpx;
  308. height: 60rpx;
  309. text-align: center;
  310. line-height: 60rpx;
  311. border-radius: 6rpx;
  312. margin: 16rpx;
  313. flex: 0 0 40%;
  314. border: 1px solid #000000;
  315. }
  316. .selected {
  317. background-color: #1684fc;
  318. color: #FFF;
  319. }
  320. }
  321. .add-btn-container {
  322. margin-top: 32rpx;
  323. .btn {
  324. flex: 1;
  325. }
  326. }
  327. .switch {
  328. font-size: 26rpx;
  329. align-items: center;
  330. justify-content: space-between;
  331. margin: 16rpx;
  332. }
  333. .userList {
  334. border: 1rpx solid #1684fc;
  335. border-radius: 8rpx;
  336. max-height: 300rpx;
  337. overflow: auto;
  338. width: 100%;
  339. .showUser {
  340. justify-content: flex-start;
  341. flex-wrap: wrap;
  342. .user {
  343. border: 1rpx solid #999;
  344. border-radius: 8rpx;
  345. width: 150rpx;
  346. height: 50rpx;
  347. text-align: center;
  348. line-height: 50rpx;
  349. margin: 10rpx;
  350. overflow: auto;
  351. }
  352. }
  353. }
  354. .selectedUserList {
  355. width: 100%;
  356. justify-content: flex-start;
  357. flex-wrap: wrap;
  358. .selectedUser {
  359. border: 1rpx solid #999;
  360. border-radius: 8rpx;
  361. width: 150rpx;
  362. height: 50rpx;
  363. text-align: center;
  364. line-height: 50rpx;
  365. margin: 20rpx 20rpx 0 0;
  366. justify-content: space-around;
  367. }
  368. }
  369. }
  370. }
  371. </style>