dialog-selectEquipment.vue 8.3 KB

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