InspectForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  5. <a-row class="inspect-order-layout">
  6. <a-col :span="6" class="inspect-tree">
  7. <a-tree
  8. :tree-data="treeData"
  9. show-icon
  10. showLine
  11. default-expand-all
  12. :selected-keys="selectedKeys"
  13. :replaceFields="replaceFields"
  14. @select="onSelect"
  15. >
  16. <!-- 每项 最前面的 箭头的 icon -->
  17. <a-icon slot="switcherIcon" type="caret-down" />
  18. <!-- slot="praent" 配合 treeData数据中的 slots 设置目录下 的 icon -->
  19. <!-- <a-icon slot="parent" style="color:#0DD3FF" type="folder-open" /> -->
  20. <!-- slot="child" 配合 treeData数据children下的 slots 设置children目录 的 icon -->
  21. <!-- <a-icon slot="child" style="color:#FED037" type="folder-open" /> -->
  22. <!-- 数据中 每个 节点 的 scopedSlots 字段(插槽) 用来设置 所有(子父节点)节点 的 统一的 icon-->
  23. <template slot="handle" slot-scope="item">
  24. <!--item.title 为treeData的 title 字段-->
  25. <span>{{item.title}}</span>
  26. <!-- completionStatus === '1'表示已完成 -->
  27. <a-icon type="check-circle" theme="twoTone" two-tone-color="#52c41a" v-if="item.completionStatus === '1'" style="margin-left: 4px;"/>
  28. </template>
  29. </a-tree>
  30. </a-col>
  31. <a-col :span="18" class="itemList-table">
  32. <a-button type="primary" @click="handleFeedback" style="margin-bottom: 8px;float: right;z-index: 9999;">提交反馈</a-button>
  33. <a-table
  34. ref="table"
  35. size="middle"
  36. :scroll="{x:true}"
  37. bordered
  38. rowKey="id"
  39. :columns="columns"
  40. :dataSource="model.itemList"
  41. :pagination="false"
  42. class="j-table-force-nowrap">
  43. <template slot="iresult" slot-scope="text, record,index">
  44. <a-form-model-item :prop="'itemList.'+index+'.iresult'" :rules="validatorRules.iresult" style="margin-bottom: 0px;">
  45. <a-radio-group name="radioGroup" v-model="record.iresult">
  46. <a-radio value="0">
  47. 正常
  48. </a-radio>
  49. <a-radio value="1">
  50. 异常
  51. </a-radio>
  52. </a-radio-group>
  53. </a-form-model-item>
  54. </template>
  55. <template slot="iremark" slot-scope="text, record,index">
  56. <a-form-model-item :prop="'itemList.'+index+'.iremark'" :rules="validatorRules.iremark" style="margin-bottom: 0px;">
  57. <a-input v-model="record.iremark" placeholder="请输入点检备注"></a-input>
  58. </a-form-model-item>
  59. </template>
  60. </a-table>
  61. </a-col>
  62. </a-row>
  63. </a-form-model>
  64. </j-form-container>
  65. </a-spin>
  66. </template>
  67. <script>
  68. const treeData1 = [
  69. {
  70. title: '测试123456',
  71. key: '1111111111111',
  72. type: '巡检路线',
  73. completionStatus: '0',
  74. slots: { icon: 'parent', },
  75. // ⚠️重点这这里⚠️每一条数据上都添加scopedSlots属性
  76. scopedSlots:{ title:"handle" },
  77. children: [
  78. {
  79. title: '测试巡检点的修改NO1',
  80. key: '12223333333',
  81. type: '巡检点',
  82. slots: { icon: 'child', },
  83. // ⚠️重点这这里⚠️每一条数据上都添加scopedSlots属性
  84. scopedSlots:{ title:"handle" },
  85. children: [
  86. {
  87. title: '半自动立钻Z5180C',
  88. key: '55555555555',
  89. type: '巡检内容',
  90. scopedSlots:{ title:"handle" },
  91. ItemList: [
  92. // 巡检项相关信息
  93. ]
  94. },
  95. ],
  96. },
  97. ],
  98. },
  99. {
  100. title: '测试巡检点的修改NO2',
  101. key: '456293324552',
  102. type: '巡检点',
  103. completionStatus: '1',
  104. scopedSlots:{ title:"handle" },
  105. children: [
  106. {
  107. title: '半自动立钻Z5180D',
  108. key: '1335633666666',
  109. type: '巡检内容',
  110. ItemList: [
  111. // 巡检项相关信息
  112. ]
  113. },
  114. ],
  115. },
  116. ];
  117. import { httpAction, getAction, putAction } from '@/api/manage'
  118. import { validateDuplicateValue } from '@/utils/util'
  119. export default {
  120. name: 'InspectForm',
  121. components: {
  122. },
  123. props: {
  124. //表单禁用
  125. disabled: {
  126. type: Boolean,
  127. default: false,
  128. required: false
  129. }
  130. },
  131. data () {
  132. return {
  133. model: {
  134. itemList: []
  135. },
  136. labelCol: {
  137. xs: { span: 24 },
  138. sm: { span: 5 },
  139. },
  140. wrapperCol: {
  141. xs: { span: 24 },
  142. sm: { span: 16 },
  143. },
  144. confirmLoading: false,
  145. validatorRules: {
  146. result: [
  147. { required: true, message: '请输入点检结果!'},
  148. ],
  149. },
  150. url: {
  151. add: "/cmmsInspect/cmmsInspect/add",
  152. edit: "/cmmsInspect/cmmsInspect/edit",
  153. queryById: "/cmmsInspect/cmmsInspect/queryById",
  154. queryTreeById: "/cmmsInspect/cmmsInspect/queryTreeById",
  155. queryItemByCountId: "/cmmsInspect/cmmsInspect/queryItemByCountId",
  156. feedback: "/cmmsInspect/cmmsInspect/feedback",
  157. },
  158. treeData: [],
  159. selectedKeys: [], // (受控)设置选中的树节点
  160. replaceFields: {
  161. children:'children',
  162. title:'title',
  163. key:'id'
  164. },
  165. columns: [
  166. // {
  167. // title: '序号',
  168. // dataIndex: '',
  169. // key:'rowIndex',
  170. // width:60,
  171. // align:"center",
  172. // customRender:function (t,r,index) {
  173. // return parseInt(index)+1;
  174. // }
  175. // },
  176. {
  177. title:'巡检项编号',
  178. align:"center",
  179. dataIndex: 'itemcode'
  180. },
  181. {
  182. title:'巡检项名称',
  183. align:"center",
  184. dataIndex: 'itemname'
  185. },
  186. {
  187. title:'标准',
  188. align:"center",
  189. dataIndex: 'inspectionstandards',
  190. },
  191. {
  192. title:'巡检结果',
  193. align:"center",
  194. dataIndex: 'iresult',
  195. scopedSlots: { customRender: 'iresult' }
  196. },
  197. {
  198. title:'巡检备注',
  199. align:"center",
  200. dataIndex: 'iremark',
  201. scopedSlots: { customRender: 'iremark' }
  202. }
  203. ],
  204. }
  205. },
  206. computed: {
  207. formDisabled(){
  208. return this.disabled
  209. },
  210. },
  211. created () {
  212. //备份model原始值
  213. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  214. },
  215. methods: {
  216. edit (record) {
  217. // this.model = Object.assign({}, record);
  218. this.visible = true;
  219. this.confirmLoading = true
  220. // getAction(this.url.queryById, {id: record.id}).then((res) => {
  221. // console.log(res)
  222. // this.model = res.result
  223. // // console.log(res.result.planList)
  224. // var planList = res.result.planList
  225. // var orderData = []
  226. // if(planList.length>0){
  227. // for (let p = 0; p < planList.length; p++) {
  228. // // 巡检路线
  229. // const planItem = planList[p];
  230. // planItem.children = []
  231. // if(planItem.inspectLineVo){
  232. // for (let s = 0; s < planItem.inspectLineVo.detailList.length; s++) {
  233. // // 巡检点
  234. // const spotItem = planItem.inspectLineVo.detailList[s];
  235. // spotItem.children = []
  236. // if(spotItem.inspectContentList){
  237. // for (let i = 0; i < spotItem.inspectContentList.length; i++) {
  238. // const contentItem = spotItem.inspectContentList[i];
  239. // console.log(spotItem, contentItem)
  240. // // 巡检内容数据
  241. // if(contentItem){
  242. // var contentNode = {
  243. // key: contentItem.id,
  244. // title: contentItem.equipmentname,
  245. // slots: {
  246. // icon: 'smile',
  247. // },
  248. // inspectTcontentItemList: contentItem.inspectTcontentItemList
  249. // }
  250. // spotItem.children.push(contentNode)
  251. // }
  252. // }
  253. // }
  254. // // 巡检点数据
  255. // var spotNode = {
  256. // key: spotItem.id,
  257. // title: spotItem.contentname,
  258. // slots: {
  259. // icon: 'smile',
  260. // },
  261. // children: spotItem.children,
  262. // }
  263. // planItem.children.push(spotNode)
  264. // }
  265. // // 路线数据
  266. // var planNode = {
  267. // key: planItem.inspectLineVo.id,
  268. // title: planItem.inspectLineVo.linename,
  269. // slots: {
  270. // icon: planItem.tasktype? 'smile': 'smile',
  271. // },
  272. // children: planItem.children,
  273. // }
  274. // orderData.push(planNode)
  275. // }
  276. // }
  277. // }
  278. // console.log(orderData)
  279. // this.treeData = orderData
  280. // // if(planList.length>0){
  281. // // planList.map(item => {
  282. // // var spotList = item.detailList
  283. // // if(spotList.length > 0){
  284. // // spotList.map(spot => {
  285. // // var
  286. // // return {
  287. // // key: item.id,
  288. // // title: item.linename,
  289. // // slots: {
  290. // // icon: 'smile',
  291. // // },
  292. // // children: item.inspectLineVo,
  293. // // }
  294. // // })
  295. // // }
  296. // // return {
  297. // // key: item.id,
  298. // // title: item.linename,
  299. // // slots: {
  300. // // icon: 'smile',
  301. // // },
  302. // // children: item.inspectLineVo,
  303. // // }
  304. // // })
  305. // // }
  306. // this.confirmLoading = false
  307. // })
  308. getAction(this.url.queryTreeById, {id: record.id}).then((res) => {
  309. console.log(res)
  310. if(this.selectedKeys.length === 0){
  311. this.model = res.result
  312. }
  313. // this.model.itemList = []
  314. this.treeData = this.setIcon(res.result.children)
  315. this.confirmLoading = false
  316. })
  317. },
  318. // 设置树结构图标
  319. setIcon(data) {
  320. var setIconData = data
  321. for (let item of setIconData) {
  322. // 判断是不是父级
  323. if (item.children && item.children.length > 0) {
  324. //是父级的话递归调用
  325. this.setIcon(item.children);
  326. item.scopedSlots = { title: "handle" }
  327. } else {
  328. item.scopedSlots = { title: "handle" }
  329. }
  330. }
  331. return setIconData
  332. },
  333. onSelect(selectedKeys, info) {
  334. // 二次点击树节点时selectedKeys为空,直接return中断执行
  335. if (selectedKeys.length === 0) return
  336. this.selectedKeys = selectedKeys
  337. // console.log('selected', selectedKeys, info);
  338. // console.log(info.selectedNodes[0].data.props.inspectTcontentItemList)
  339. var props = info.selectedNodes[0].data.props
  340. if(props.type === '巡检内容'){
  341. this.model.itemList = props.inspectTcontentItemList
  342. this.$forceUpdate()
  343. // this.getItemList(props.id)
  344. }
  345. },
  346. getItemList(id){
  347. getAction(this.url.queryItemByCountId, {countId: id, inspectId: this.model.id}).then((res) => {
  348. console.log(res)
  349. this.model.itemList = res.result
  350. console.log(this.model)
  351. this.$forceUpdate()
  352. })
  353. },
  354. handleFeedback(){
  355. console.log(this.model.itemList)
  356. this.confirmLoading = true
  357. putAction(this.url.feedback, this.model.itemList).then((res) => {
  358. if(res.success){
  359. this.$message.success(res.message);
  360. this.edit(this.model)
  361. }else{
  362. this.$message.warning(res.message);
  363. }
  364. }).finally(() => {
  365. this.confirmLoading = false;
  366. })
  367. },
  368. }
  369. }
  370. </script>
  371. <style lang="less" scoped>
  372. .inspect-order-layout{
  373. height: calc(100vh - 150px);
  374. overflow: hidden;
  375. .inspect-tree{
  376. height: calc(100vh - 150px);
  377. overflow: auto;
  378. }
  379. .itemList-table{
  380. height: calc(100vh - 150px);
  381. overflow: auto;
  382. }
  383. }
  384. </style>