workshop.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <div class="leftcon">
  3. <!-- <img src="../../assets/images/workshop.png" alt="" /> -->
  4. <div class="lefttop">
  5. <el-form ref="form" :model="form" label-width="100px" :inline="true">
  6. <el-form-item label="车间">
  7. <el-select
  8. :disabled="this.getSopLook"
  9. v-model="form.workShop"
  10. placeholder="请选择车间"
  11. @change="handleselect"
  12. >
  13. <el-option
  14. v-for="item in this.workShopOptions"
  15. :key="item.value"
  16. :label="item.label"
  17. :value="item.value"
  18. >
  19. </el-option>
  20. </el-select>
  21. <!-- <el-select-->
  22. <!-- v-model="form.workShop"-->
  23. <!-- v-bind="$attrs"-->
  24. <!-- multiple-->
  25. <!-- style="width: 100%"-->
  26. <!-- placeholder="请选择线路"-->
  27. <!-- @change="handleSelect"-->
  28. <!-- >-->
  29. <!-- <div style="padding: 0 20px; line-height: 34px">-->
  30. <!-- <el-checkbox-->
  31. <!-- v-model="checkAll"-->
  32. <!-- :indeterminate="isIndeterminate"-->
  33. <!-- @change="handleCheckAllChange"-->
  34. <!-- >全选</el-checkbox-->
  35. <!-- >-->
  36. <!-- </div>-->
  37. <!-- <el-checkbox-group v-model="form.workShop">-->
  38. <!-- <el-option-->
  39. <!-- v-for="item in this.workShopOptions"-->
  40. <!-- :key="item.value"-->
  41. <!-- :label="item.label"-->
  42. <!-- :value="item.value"-->
  43. <!-- >-->
  44. <!-- <el-checkbox style="pointer-events: none" :label="item.value">-->
  45. <!-- {{ item.label }}-->
  46. <!-- </el-checkbox>-->
  47. <!-- </el-option>-->
  48. <!-- </el-checkbox-group>-->
  49. <!-- </el-select>-->
  50. </el-form-item>
  51. <el-form-item label="生产线">
  52. <el-select
  53. :disabled="this.getSopLook"
  54. v-model="form.producLine"
  55. placeholder="请选择生产线"
  56. @change="handleselectProductLine"
  57. >
  58. <el-option
  59. v-for="item in this.producLineOptions"
  60. :key="item.value"
  61. :label="item.label"
  62. :value="item.value"
  63. >
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. </el-form>
  68. </div>
  69. <div class="leftbottom">
  70. <!-- <img src="../../assets/images/workshop.png" alt="" /> -->
  71. <img :src="imgsrc" alt="" v-if="imgsrc"/>
  72. <p v-else>—————— 请选择车间 ——————</p>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import { listAllWorkshop } from '@/api/mes/md/workshop'
  78. import { getIsWorkareaList, getMapData } from '@/api/mes/wa/workarea'
  79. import { selectIsSopById } from '@/api/mes/sop/sopindex'
  80. import { mapActions, mapGetters } from 'vuex'
  81. export default {
  82. props: {
  83. sopProps: {
  84. type: Array,
  85. default: () => []
  86. },
  87. jobProps: {
  88. type: Array,
  89. default: () => []
  90. }
  91. },
  92. data() {
  93. return {
  94. form: {
  95. checkAll: false,
  96. isIndeterminate: false,
  97. workShop: [],
  98. producLine: '',
  99. sopId: ''
  100. },
  101. workShopOptions: [],
  102. producLineOptions: [],
  103. imgsrc: ''
  104. }
  105. },
  106. watch: {
  107. 'form.workShop': {
  108. handler(newVal) {
  109. if (newVal) {
  110. this.imgsrc = localStorage.getItem('img')
  111. }
  112. }
  113. },
  114. // 监听父组件传递的数据
  115. sopProps: {
  116. handler(newVal, oldVal) {
  117. console.log('sopProps 发生变化', newVal)
  118. this.form.workShop = newVal[0].workshopId
  119. this.form.producLine = newVal[0].workareaId
  120. // 确保 handleselect 完成后再调用 handleselectProductLine
  121. this.handleselect(newVal[0].workshopId)
  122. .then(() => {
  123. this.handleselectProductLine(newVal[0].workareaId)
  124. })
  125. .catch((error) => {
  126. console.error('处理车间下拉失败', error)
  127. })
  128. // 这里是为了拿到sop模板里默认的隔离点选中的数据
  129. selectIsSopById(newVal[0].sopId).then((res) => {
  130. console.log(res, 'sop')
  131. const selectSopPoints = res.data.pointDetailVOList.map((item) => {
  132. return item.pointId
  133. })
  134. // 调用 Vuex action 来存储 selectSopPoints
  135. this.setSelectSopPoints(selectSopPoints)
  136. this.setSopEdit(true)
  137. console.log(selectSopPoints, 'sop_selectePoints')
  138. })
  139. },
  140. immediate: true // 立即执行一次,确保在组件初始化时也能捕获到 jobProps 的值
  141. },
  142. jobProps: {
  143. handler(newVal, oldVal) {
  144. console.log('jobProps 发生变化', newVal)
  145. // 在这里处理 jobProps 变化后的逻辑
  146. this.form.workShop = newVal[0].workshopId
  147. this.form.producLine = newVal[0].workareaId
  148. this.form.sopId = newVal[0].sopId
  149. console.log(this.form.sopId,'form.sopId jobProps')
  150. // 确保 handleselect 完成后再调用 handleselectProductLine
  151. this.handleselect(newVal[0].workshopId)
  152. .then(() => {
  153. this.handleselectProductLine(newVal[0].workareaId)
  154. })
  155. .catch((error) => {
  156. console.error('处理车间下拉失败', error)
  157. })
  158. // 这里是为了拿到sop模板里默认的隔离点选中的数据a
  159. if (!newVal[0].EditBool) {
  160. selectIsSopById(newVal[0].sopId).then((res) => {
  161. console.log(res, 'sop')
  162. const selectSopPoints = res.data.pointDetailVOList.map((item) => {
  163. return item.pointId
  164. })
  165. // 调用 Vuex action 来存储 selectSopPoints
  166. this.setSelectSopPoints(selectSopPoints)
  167. this.setPointTableData(res.data)
  168. this.setSopEdit(false)
  169. console.log(selectSopPoints, 'sop_selectePoints')
  170. })
  171. } else {
  172. const selectSopPoints = newVal[0].spoint.map((item) => {
  173. return item.pointId
  174. })
  175. this.setSelectSopPoints(selectSopPoints)
  176. this.setPointTableData(newVal[0].spoint)
  177. this.setSopEdit(true)
  178. }
  179. },
  180. immediate: true // 立即执行一次,确保在组件初始化时也能捕获到 jobProps 的值
  181. }
  182. },
  183. mounted() {
  184. this.getworkshopList()
  185. },
  186. computed: {
  187. ...mapGetters('sopSelectPoints', ['getSopLook'])
  188. },
  189. methods: {
  190. ...mapActions('sopSelectPoints', [
  191. 'setSelectSopPoints',
  192. 'setPointTableData',
  193. 'setSopEdit',
  194. 'setMapData'
  195. ]),
  196. // 获取车间列表
  197. getworkshopList() {
  198. listAllWorkshop().then((response) => {
  199. console.log(response, '车间信息')
  200. this.workShopOptions = response.data.map((item) => {
  201. return {
  202. label: item.workshopName,
  203. value: item.workshopId,
  204. key: item.workshopCode,
  205. attr1: item.attr1
  206. }
  207. })
  208. })
  209. },
  210. // 单选车间下拉
  211. handleselect(value) {
  212. return new Promise((resolve, reject) => {
  213. getIsWorkareaList(value)
  214. .then((response) => {
  215. this.producLineOptions = response.data.map((item) => {
  216. return {
  217. label: item.workareaName,
  218. value: item.workareaId,
  219. key: item.workareaCode,
  220. map: item.map
  221. }
  222. })
  223. // 根据选择的车间更新 imgsrc
  224. const selectedWorkshop = this.workShopOptions.find(
  225. (item) => item.value === value
  226. )
  227. localStorage.setItem('img', selectedWorkshop.attr1)
  228. if (selectedWorkshop) {
  229. this.imgsrc = selectedWorkshop.attr1
  230. } else {
  231. this.imgsrc = '' // 如果没有找到,清空 imgsrc
  232. }
  233. console.log(this.producLineOptions, 'this.producLineOptions')
  234. resolve() // 异步操作成功后 resolve
  235. })
  236. .catch((error) => {
  237. console.error('获取生产线下拉列表失败', error)
  238. reject(error) // 异步操作失败后 reject
  239. })
  240. })
  241. },
  242. // 生产线下拉
  243. handleselectProductLine(val) {
  244. console.log(val, '生产线下拉')
  245. // 获取区域map解析数据
  246. const data = val
  247. let data1 = ''
  248. let data2 = ''
  249. if (this.$route.query.sopId !== 'null' && this.$route.query.sopId) {
  250. data1 = this.$route.query.sopId
  251. } else if (this.$route.query.ticketId !== 'null' && this.$route.query.ticketId) {
  252. data2 = this.$route.query.ticketId // ticketId 存在时,data1 设置为空字符串
  253. }
  254. console.log(this.form.sopId,'form.sopId')
  255. if (this.form.sopId) {
  256. data1 = this.form.sopId
  257. }
  258. getMapData(data, data1, data2).then((res) => {
  259. console.log(res, '获取区域map的解析数据')
  260. const mapdata = res.data
  261. this.setMapData(mapdata)
  262. }).catch((error) => {
  263. console.error('获取区域map数据失败', error)
  264. })
  265. // 利用组件逆传递 selectProductLine方法传递数据给兄弟组件
  266. const selectedOption = this.producLineOptions.filter((item) => {
  267. return item.value == val
  268. })
  269. const selectworkShop = this.workShopOptions.filter((item) => {
  270. return item.value == this.form.workShop
  271. })
  272. console.log(selectworkShop, selectedOption, 'workshop-components')
  273. // 触发自定义事件,传递 selectedOption[0] 数据给父组件
  274. console.log(selectedOption, 'selectedOption[0]', this.producLineOptions)
  275. this.$emit('product-line-selected', selectedOption[0])
  276. this.$emit('work-shop-selected', selectworkShop[0])
  277. },
  278. // 多选车间下拉框选择事件
  279. // handleSelect(value) {
  280. // console.log(value, "value");
  281. // const checkedCount = value.length;
  282. // this.checkAll = checkedCount === this.workShopOptions.length;
  283. // this.isIndeterminate =
  284. // checkedCount > 0 && checkedCount < this.workShopOptions.length;
  285. // const data = value.map((item) => {
  286. // return item;
  287. // });
  288. // this.form.workShop = value.length > 0 ? data : [];
  289. //
  290. // console.log(this.form.workShop, " form.workShop");
  291. // },
  292. // 全选事件
  293. handleCheckAllChange(val) {
  294. const data = this.workShopOptions.map((item) => {
  295. return item.value
  296. })
  297. this.form.workShop = val ? data : []
  298. this.isIndeterminate = false
  299. }
  300. }
  301. }
  302. </script>
  303. <style scoped lang="scss">
  304. .leftcon {
  305. width: 100%;
  306. height: 100%;
  307. background-size: 100% 100%;
  308. .lefttop {
  309. width: 100%;
  310. height: 60px;
  311. }
  312. .leftbottom {
  313. width: 1100px;
  314. height: 780px;
  315. margin: -16px 0 0 60px;
  316. img {
  317. width: 100%;
  318. height: 100%;
  319. }
  320. p {
  321. text-align: center;
  322. margin: 30% 0;
  323. }
  324. }
  325. }
  326. </style>