dialog-selectEquipment.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. res.data.some((item2) => item2.processCode === item1.processCode)
  120. );
  121. for (let i = 0; i < filteredData.length; i++) {
  122. processList.value[i] = {
  123. text: filteredData[i].processAlias,
  124. value: filteredData[i].technologicalProcessDetailId,
  125. processId: filterData[i].id
  126. }
  127. }
  128. console.log(processList.value)
  129. selectedProcess.value = filteredData[0].technologicalProcessDetailId;
  130. isDefaultItem(firstItem.value);
  131. }
  132. })
  133. // Promise.all([getEquipmentByUidAndDid(store.planDetails.id), getDayWorkItemList({
  134. // // userId: store.userInfo.userId,
  135. // // dayworkId: store.dayworkInfo.id,
  136. // status: 1
  137. // })])
  138. // .then(([equipmentRes, response]) => {
  139. // console.log(equipmentRes)
  140. // console.log(response.rows)
  141. // if (equipmentRes.code == 200 && response.code == 200) {
  142. // let equipmentListData = equipmentRes.rows.filter((equipment) => {
  143. // return !response.rows.some((item) => item.equipmentDetailId == equipment.commonId);
  144. // });
  145. // equipmentList.value = equipmentListData.map((equipment) => {
  146. // return {
  147. // text: equipment.commonCode,
  148. // value: equipment
  149. // }
  150. // });
  151. // selectedEquipment.value = equipmentListData.length > 0 ? equipmentListData[0] : null;
  152. // }
  153. // baseDialog.value.open()
  154. // });
  155. getEquipmentByUidAndDid(store.planDetails.id,store.curDeptDetails.deptId).then(equipmentRes => {
  156. if(equipmentRes.code == 200){
  157. for (var i = 0; i < equipmentRes.rows.length; i++) {
  158. equipmentList.value[i] = {
  159. text: equipmentRes.rows[i].commonCode,
  160. value: equipmentRes.rows[i]
  161. }
  162. }
  163. selectedEquipment.value = equipmentRes.rows.length > 0 ? equipmentRes.rows[0] : null;
  164. }
  165. baseDialog.value.open()
  166. })
  167. }
  168. function open(data) {
  169. resetPage()
  170. firstItem.value = data;
  171. userName.value = null;
  172. userList.value = [];
  173. init();
  174. }
  175. function isDefaultItem(item){
  176. if(item){
  177. showProcessList.value = false;
  178. selectedProcess.value = null;
  179. }
  180. }
  181. function close() {
  182. baseDialog.value.close()
  183. }
  184. defineExpose({
  185. open
  186. })
  187. function handleProcessChange() {
  188. }
  189. function handleEquipmentChange() {
  190. }
  191. function handleSearchUserName() {
  192. if (userName.value) {
  193. getUserByLikeUsername(userName.value).then(res => {
  194. if (res.code == 200) {
  195. userList.value = res.data;
  196. }
  197. })
  198. }
  199. }
  200. function handleClickUserName(item) {
  201. selectedUserList.value.push(item);
  202. userList.value = [];
  203. }
  204. function handleBlur() {
  205. setTimeout(function() {
  206. userList.value = [];
  207. }, 200)
  208. }
  209. function handleRemoveUserName(item) {
  210. selectedUserList.value.splice(selectedUserList.value.indexOf(item), 1);
  211. }
  212. function switchChange(e) {
  213. flag.value = e.detail.value;
  214. }
  215. function handleStart() {
  216. uni.showModal({
  217. title: "提示",
  218. content: "确认开始新的报工吗",
  219. success: function(res) {
  220. if (res.confirm) {
  221. handleDoStart();
  222. } else if (res.cancel) {
  223. close();
  224. }
  225. }
  226. })
  227. }
  228. function handleDoStart() {
  229. // if (!selectedProcess.value || !selectedEquipment.value) {
  230. // uni.showToast({
  231. // icon: "none",
  232. // title: "未选择工序或设备"
  233. // })
  234. // selectedProcess.value = null;
  235. // selectedEquipment.value = null;
  236. // return;
  237. // }
  238. close();
  239. if (firstItem.value) {
  240. sendReqParam.value = {
  241. ...firstItem.value,
  242. /* 20240408 前版本
  243. processId: selectedProcess.value,
  244. */
  245. technologicalProcessDetailId: selectedProcess.value,
  246. processId: processList.value.findIndex(v => v.value === selectedProcess.value) >= 0 ? processList.value.find(v => v.value === selectedProcess.value).processId : null,
  247. equipmentDetailId: selectedEquipment.value.commonId,
  248. equipmentDetailCode: selectedEquipment.value.commonCode,
  249. startTime: timestampToTime(new Date()),
  250. status: 1,
  251. collaborationList: selectedUserList.value
  252. };
  253. console.log(sendReqParam.value)
  254. emit('handleAddDayWorkItem', sendReqParam.value);
  255. } else {
  256. emit('handleAddDayWorkItem', {
  257. /* 20240408 前版本
  258. processId: selectedProcess.value,
  259. */
  260. technologicalProcessDetailId: selectedProcess.value,
  261. processId: processList.value.findIndex(v => v.value === selectedProcess.value) >= 0 ? processList.value.find(v => v.value === selectedProcess.value).processId : null,
  262. equipmentDetailId: selectedEquipment.value.commonId,
  263. equipmentDetailCode: selectedEquipment.value.commonCode,
  264. collaborationList: selectedUserList.value
  265. });
  266. }
  267. }
  268. </script>
  269. <style lang="scss">
  270. .dialog-body {
  271. .equipment-container {
  272. height: 300rpx;
  273. overflow: auto;
  274. flex-wrap: wrap;
  275. justify-content: flex-start;
  276. margin: 24rpx 0 0 7%;
  277. .item {
  278. width: 236rpx;
  279. height: 60rpx;
  280. text-align: center;
  281. line-height: 60rpx;
  282. border-radius: 6rpx;
  283. margin: 16rpx;
  284. flex: 0 0 40%;
  285. border: 1px solid #000000;
  286. }
  287. .selected {
  288. background-color: #1684fc;
  289. color: #FFF;
  290. }
  291. }
  292. .add-btn-container {
  293. margin-top: 32rpx;
  294. .btn {
  295. flex: 1;
  296. }
  297. }
  298. .switch {
  299. font-size: 26rpx;
  300. align-items: center;
  301. justify-content: space-between;
  302. margin: 16rpx;
  303. }
  304. .userList {
  305. border: 1rpx solid #1684fc;
  306. border-radius: 8rpx;
  307. max-height: 300rpx;
  308. overflow: auto;
  309. width: 100%;
  310. .showUser {
  311. justify-content: flex-start;
  312. flex-wrap: wrap;
  313. .user {
  314. border: 1rpx solid #999;
  315. border-radius: 8rpx;
  316. width: 150rpx;
  317. height: 50rpx;
  318. text-align: center;
  319. line-height: 50rpx;
  320. margin: 10rpx;
  321. overflow: auto;
  322. }
  323. }
  324. }
  325. .selectedUserList {
  326. width: 100%;
  327. justify-content: flex-start;
  328. flex-wrap: wrap;
  329. .selectedUser {
  330. border: 1rpx solid #999;
  331. border-radius: 8rpx;
  332. width: 150rpx;
  333. height: 50rpx;
  334. text-align: center;
  335. line-height: 50rpx;
  336. margin: 20rpx 20rpx 0 0;
  337. justify-content: space-around;
  338. }
  339. }
  340. }
  341. </style>