SpotcheckForm.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. <div class="cmms-dialog-item-title">基本信息</div>
  6. <a-row>
  7. <!-- <a-col :span="12">
  8. <a-form-model-item label="点检内容编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contentcode">
  9. <a-input v-model="model.contentcode" placeholder="请输入所属点检内容编号" ></a-input>
  10. </a-form-model-item>
  11. </a-col> -->
  12. <a-col :span="12">
  13. <a-form-model-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentid">
  14. <j-search-select-tag v-model="model.equipmentid" dict="tpm_equipment,equipmentname,id" placeholder="请选择设备" @change="handleChange"/>
  15. </a-form-model-item>
  16. </a-col>
  17. <a-col :span="12">
  18. <a-form-model-item label="点检内容名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contentname">
  19. <a-input v-model="model.contentname" placeholder="请输入所属点检内容名称" :disabled="disableds" ></a-input>
  20. </a-form-model-item>
  21. </a-col>
  22. <!-- <a-col :span="12">
  23. <a-form-model-item label="所属点检内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spotcheckcontid">
  24. <j-search-select-tag v-model="model.spotcheckcontid" dict="cmms_spotcheck_content,contentname,id" />
  25. </a-form-model-item>
  26. </a-col> -->
  27. <a-col :span="12">
  28. <a-form-model-item label="点检结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="result">
  29. <j-dict-select-tag type="list" v-model="model.result" dictCode="spotcheck_result" placeholder="请选择点检结果" @change="resultChange"/>
  30. </a-form-model-item>
  31. </a-col>
  32. <a-col :span="12">
  33. <a-form-model-item :label="resultStatus == -1? '故障日期' : '点检时间'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spotcheckdate">
  34. <j-date :placeholder="resultStatus == -1? '请选择故障日期':'请选择点检时间'" v-model="model.spotcheckdate" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
  35. </a-form-model-item>
  36. </a-col>
  37. <a-col :span="12">
  38. <a-form-model-item :label="resultStatus == -1? '故障描述' : '点检描述'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
  39. <!-- <a-input v-model="model.description" placeholder="请输入点检描述" ></a-input> -->
  40. <a-textarea v-model="model.description" :placeholder="resultStatus == -1?'请输入故障描述':'请输入点检描述'" :auto-size="{ minRows: 2, maxRows: 3 }" />
  41. </a-form-model-item>
  42. </a-col>
  43. <a-col :span="12">
  44. <a-form-model-item label="点检备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
  45. <!-- <a-input v-model="model.remark" placeholder="请输入点检备注" ></a-input> -->
  46. <a-textarea v-model="model.remark" placeholder="请输入点检备注" :auto-size="{ minRows: 2, maxRows: 3 }" />
  47. </a-form-model-item>
  48. </a-col>
  49. <a-col :span="12" v-if="resultStatus == -1">
  50. <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repairname">
  51. <span slot="label">
  52. 工单名称&nbsp;
  53. <a-tooltip title="点检结果为报修,需新增维修工单">
  54. <a-icon type="exclamation-circle" theme="filled" />
  55. </a-tooltip>
  56. </span>
  57. <a-input v-model="model.repairname" placeholder="请输入维修工单名称" ></a-input>
  58. </a-form-model-item>
  59. </a-col>
  60. <a-col :span="12" v-if="resultStatus == -1">
  61. <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priority">
  62. <span slot="label">
  63. 优先级&nbsp;
  64. <a-tooltip title="点检结果为报修,需新增维修工单">
  65. <a-icon type="exclamation-circle" theme="filled" />
  66. </a-tooltip>
  67. </span>
  68. <j-dict-select-tag v-model="model.priority" placeholder="请选择维修优先级" dictCode="repair_priority"/>
  69. </a-form-model-item>
  70. </a-col>
  71. <!-- <a-col :span="12">
  72. <a-form-model-item label="点检人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">
  73. </a-form-model-item>
  74. </a-col> -->
  75. <a-col :span="12">
  76. <a-form-model-item label="故障照片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
  77. <j-image-upload text="上传" v-model="model.files" isMultiple></j-image-upload>
  78. </a-form-model-item>
  79. </a-col>
  80. </a-row>
  81. <div class="cmms-dialog-item-title u-flex-jab">
  82. <div>点检列表</div>
  83. <div>
  84. <a-button @click="allT" type="link">一键正常</a-button>
  85. <a-button @click="allF" type="link">一键异常</a-button>
  86. </div>
  87. </div>
  88. <a-table
  89. ref="table"
  90. size="middle"
  91. :scroll="{x:true}"
  92. bordered
  93. rowKey="itemcode"
  94. :columns="columns"
  95. :dataSource="model.cmmsSpotcheckTitemList"
  96. :pagination="false"
  97. class="j-table-force-nowrap">
  98. <template slot="iresult" slot-scope="text, record,index">
  99. <a-form-model-item :prop="'cmmsSpotcheckTitemList.'+index+'.iresult'" :rules="validatorRules.iresult" style="margin-bottom: 0px;">
  100. <a-radio-group name="radioGroup" v-model="record.iresult">
  101. <a-radio value="0">
  102. 正常
  103. </a-radio>
  104. <a-radio value="1">
  105. 异常
  106. </a-radio>
  107. </a-radio-group>
  108. </a-form-model-item>
  109. </template>
  110. <template slot="iremark" slot-scope="text, record,index">
  111. <a-form-model-item :prop="'cmmsSpotcheckTitemList.'+index+'.iremark'" :rules="validatorRules.iremark" style="margin-bottom: 0px;">
  112. <a-input v-model="record.iremark" placeholder="请输入点检备注"></a-input>
  113. </a-form-model-item>
  114. </template>
  115. </a-table>
  116. </a-form-model>
  117. </j-form-container>
  118. </a-spin>
  119. </template>
  120. <script>
  121. import { httpAction, getAction } from '@/api/manage'
  122. import { validateDuplicateValue } from '@/utils/util'
  123. export default {
  124. name: 'SpotcheckForm',
  125. components: {
  126. },
  127. props: {
  128. //表单禁用
  129. disabled: {
  130. type: Boolean,
  131. default: false,
  132. required: false
  133. },
  134. // dataList: {
  135. // type: Object,
  136. // default: function(){
  137. // return {} // 使用工厂函数返回默认值
  138. // }
  139. // },
  140. },
  141. data () {
  142. return {
  143. model:{
  144. cmmsSpotcheckTitemList: []
  145. },
  146. modelWX:{
  147. },
  148. // 单个禁填
  149. disableds: false,
  150. // 点检结果(-1为报修,1为其他结果)
  151. resultStatus: 1,
  152. labelCol: {
  153. xs: { span: 24 },
  154. sm: { span: 5 },
  155. },
  156. wrapperCol: {
  157. xs: { span: 24 },
  158. sm: { span: 16 },
  159. },
  160. columns: [
  161. // {
  162. // title: '序号',
  163. // dataIndex: '',
  164. // key:'rowIndex',
  165. // width:60,
  166. // align:"center",
  167. // customRender:function (t,r,index) {
  168. // return parseInt(index)+1;
  169. // }
  170. // },
  171. {
  172. title:'点检项编号',
  173. align:"center",
  174. dataIndex: 'itemcode'
  175. },
  176. {
  177. title:'点检项名称',
  178. align:"center",
  179. dataIndex: 'itemname'
  180. },
  181. {
  182. title:'标准',
  183. align:"center",
  184. dataIndex: 'conditions',
  185. },
  186. {
  187. title:'点检结果',
  188. align:"center",
  189. dataIndex: 'iresult',
  190. scopedSlots: { customRender: 'iresult' }
  191. },
  192. {
  193. title:'点检备注',
  194. align:"center",
  195. dataIndex: 'iremark',
  196. scopedSlots: { customRender: 'iremark' }
  197. }
  198. ],
  199. confirmLoading: false,
  200. validatorRules: {
  201. contentname: [
  202. { required: true, message: '请输入点检内容名称!'},
  203. ],
  204. equipmentid: [
  205. { required: true, message: '请选择设备!'},
  206. ],
  207. result: [
  208. { required: true, message: '请输入点检结果!'},
  209. ],
  210. description: [
  211. { required: true, message: '请输入点检描述/故障描述!'},
  212. ],
  213. spotcheckdate: [
  214. { required: true, message: '请选择点检时间!'},
  215. ],
  216. repairname: [
  217. { required: true, message: '请输入工单名称!'},
  218. ],
  219. priority: [
  220. { required: true, message: '请选择优先级!'},
  221. ],
  222. },
  223. url: {
  224. add: "/cmmsSpotcheck/cmmsSpotcheck/add",
  225. add2: "/cmmsRepair/cmmsRepair/add",
  226. edit: "/cmmsSpotcheck/cmmsSpotcheck/edit",
  227. queryById: "/cmmsSpotcheck/cmmsSpotcheck/queryById"
  228. }
  229. }
  230. },
  231. computed: {
  232. formDisabled(){
  233. return this.disabled
  234. },
  235. },
  236. created () {
  237. //备份model原始值
  238. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  239. },
  240. methods: {
  241. add () {
  242. this.edit(this.modelDefault);
  243. this.disableds = true
  244. // 第二版
  245. // this.model = this.dataList
  246. // this.model.id = ""
  247. },
  248. // 监听选择的设备
  249. handleChange(value){
  250. console.log(value)
  251. getAction(`/cmmsSpotcheck/cmmsSpotcheck/getInfoByEquipmentid/${value}`).then((res) => {
  252. // this.model = res.result
  253. this.model.contentname = res.result.contentname
  254. this.model.spotcheckdate = res.result.spotcheckdate
  255. this.model.cmmsSpotcheckTitemList = res.result.cmmsSpotcheckTitemList
  256. this.model.id = ""
  257. })
  258. },
  259. edit (record) {
  260. this.disableds = true
  261. getAction(`/cmmsSpotcheck/cmmsSpotcheck/getInfoBySpotcheckid/${record.id}`).then((res) => {
  262. this.model = res.result
  263. const b = res.result.files.map((res) => {
  264. return res.url
  265. })
  266. this.model.files = b.join(',')
  267. this.visible = true;
  268. })
  269. // this.model = Object.assign({}, record);
  270. // this.visible = true;
  271. },
  272. submitForm () {
  273. const that = this;
  274. // 触发表单验证
  275. this.$refs.form.validate(valid => {
  276. if (valid) {
  277. that.confirmLoading = true;
  278. let httpurl = '';
  279. let httpurl2 = '';
  280. let method = '';
  281. if(!this.model.id){
  282. httpurl+=this.url.add;
  283. method = 'post';
  284. // 判断点检结果是否为报修
  285. if (this.resultStatus == -1) {
  286. console.log(99,this.model)
  287. this.modelWX.equipmentid = this.model.equipmentid
  288. // 下面两句:将带有时分秒的去掉,只传年月日
  289. // const time = this.model.spotcheckdate
  290. // this.modelWX.faultdate=time.replace(/ \d+(:\d+){2}/,'');
  291. this.modelWX.faultdate = this.model.spotcheckdate
  292. this.modelWX.faultdesc = this.model.description
  293. this.modelWX.repairname = this.model.repairname
  294. this.modelWX.priority = this.model.priority
  295. const c = this.model.files.split(',')
  296. this.modelWX.files = c.map((res) => {
  297. return {
  298. url: res
  299. }
  300. })
  301. console.log("00",this.modelWX)
  302. httpurl2+=this.url.add2;
  303. httpAction(httpurl2,this.modelWX,method).then((res)=>{
  304. if(res.success){
  305. that.$message.success("维修工单新增成功!");
  306. }else{
  307. that.$message.warning(res.message);
  308. }
  309. })
  310. }
  311. }else{
  312. httpurl+=this.url.edit;
  313. method = 'put';
  314. }
  315. if (this.model.files.length != 0) {
  316. const a = this.model.files.split(',')
  317. this.model.files = a.map((res) => {
  318. return {
  319. url: res
  320. }
  321. })
  322. }else{
  323. this.model.files = []
  324. }
  325. httpAction(httpurl,this.model,method).then((res)=>{
  326. if(res.success){
  327. that.$message.success(res.message);
  328. that.$emit('ok');
  329. }else{
  330. that.$message.warning(res.message);
  331. }
  332. }).finally(() => {
  333. that.confirmLoading = false;
  334. })
  335. }
  336. })
  337. },
  338. allT() {
  339. this.model.cmmsSpotcheckTitemList = this.model.cmmsSpotcheckTitemList.map((res) => {
  340. var data = res
  341. data.iresult = "0"
  342. return data
  343. })
  344. },
  345. allF() {
  346. this.model.cmmsSpotcheckTitemList = this.model.cmmsSpotcheckTitemList.map((res) => {
  347. var data = res
  348. data.iresult = "1"
  349. return data
  350. })
  351. },
  352. // 监听点检结果
  353. resultChange(value) {
  354. if (value == 2) {
  355. this.resultStatus = -1
  356. }else{
  357. this.resultStatus = 1
  358. }
  359. }
  360. }
  361. }
  362. </script>
  363. <style scoped>
  364. @import "~@/assets/less/uStyle.less";
  365. </style>