plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

378 lines
14 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <script>
  2. import {searchCodeItemAllDefsSeq, searchCodeItemDefs, searchCodeItemDefsSeq} from "../../../api/code/codeItemDef";
  3. import {searchCodeGenerationItemValueList} from "../../../api/code/codeItemValue";
  4. import {codeNoGenerate, saveDrawing} from "../../../api/code/codeDrawing";
  5. import dayjs from "dayjs";
  6. import {queryCodeErpPartNo, searchCodeParameterById} from "../../../api/code/codeParameterDef";
  7. import itemValue from "./item/itemValue.vue";
  8. export default {
  9. name: "CodeGeneration",
  10. computed: {
  11. itemValue() {
  12. return itemValue
  13. },
  14. showConditionName() {
  15. return (val) => {
  16. if (val && val.length > 0){
  17. return val[0].conditionName
  18. }
  19. return ''
  20. };
  21. }
  22. },
  23. data(){
  24. return {
  25. codeItemDefs: [],
  26. searchModel:{
  27. drawingNo: "",
  28. drawingNoNew: "",
  29. drawingDesc: "",
  30. erpPartNo: "",
  31. erpPartDesc: "",
  32. remark: "",
  33. seqFlag: "N",
  34. },
  35. codeItemTypes: [],
  36. codeItemValues: [],
  37. width: 800,
  38. loadingIndex:-1,
  39. checkCodeFlag:'N',
  40. getCodeNoLoading: false,
  41. saveCodeLoading: false,
  42. rules:{
  43. drawingNo: [{ required: true, message: '“编码”不能为空,请先指定各个元素的值!', trigger: 'blur' }],
  44. erpPartNo: [{ required: true, message: '请输入IFS Part No', trigger: 'blur' }],
  45. erpPartDesc: [{ required: true, message: '请输入IFS Part Descriptions', trigger: 'blur' }],
  46. drawingDesc: [{ required: true, message: '请输入编码描述', trigger: 'blur' }],
  47. remark: [{ required: true, message: '请输入编码备注', trigger: 'blur' }],
  48. }
  49. }
  50. },
  51. created() {
  52. this.searchCodeItemDefs();
  53. this.searchCodeParameterById();
  54. },
  55. beforeDestroy() {
  56. },
  57. methods:{
  58. searchCodeItemDefs(){
  59. let params = {
  60. site:this.$store.state.user.site,
  61. }
  62. this.codeItemTypes = [];
  63. this.codeItemValues = [];
  64. searchCodeItemAllDefsSeq(params).then(({data})=>{
  65. if (data && data.code === 0){
  66. this.codeItemDefs = data.rows;
  67. for (let i = 0; i < this.codeItemDefs.length; i++) {
  68. let arr = this.codeItemDefs[i].itemType.split('或');
  69. this.codeItemTypes[i] = arr[0]
  70. this.codeItemValues[i] = undefined
  71. }
  72. }else {
  73. this.$message.warning(data.msg);
  74. }
  75. }).catch((error) => {
  76. this.$message.error(error);
  77. });
  78. },
  79. changeCodeItemType(index){
  80. this.$set(this.codeItemValues, index, undefined)
  81. this.changeRowCodeItemValue(index)
  82. },
  83. getCodeNoBtn(){
  84. if (this.codeItemDefs.length === 0){
  85. this.showAlert("尚未设置编码规则!请先到“编码组成元素定义”中定义!")
  86. return;
  87. }
  88. // this.getCodeNoLoading = true;
  89. let params = [];
  90. // 验证是否都输入
  91. for (let i = 0; i < this.codeItemDefs.length; i++) {
  92. if (!this.codeItemValues[i] && !(this.codeItemDefs[i].itemType.includes('流水号') && this.codeItemTypes[i] === '流水号')){
  93. this.showAlert(`元素${this.codeItemDefs[i].itemDesc}的值为空`);
  94. this.getCodeNoLoading = false;
  95. return;
  96. }
  97. if (this.codeItemDefs[i].itemType.includes('手工') && this.codeItemTypes[i] === '手工' && this.codeItemValues[i].length > this.codeItemDefs[i].bits ){
  98. this.showAlert(`元素${this.codeItemDefs[i].itemDesc}的值长度不正确,编码位数应为${this.codeItemDefs[i].bits}`)
  99. this.getCodeNoLoading = false;
  100. return;
  101. }
  102. // let paramsData = {
  103. // codeItemDef: {...this.codeItemDefs[i]},
  104. // currentValueNo:"",
  105. // currentSeqValueNo:"",
  106. // currentCodeDesc:"",
  107. // currentCodeRemark:"",
  108. // codeNo:"",
  109. // codeHasSeq:"N",
  110. // hasSeqCount:0,
  111. // };
  112. // if (this.codeItemDefs[i].itemType.includes('手工') && this.codeItemTypes[i] === '手工'){
  113. // paramsData.currentValueNo = this.codeItemValues[i];
  114. // paramsData.currentSeqValueNo = `{${paramsData.currentValueNo}}`
  115. // }else if (this.codeItemDefs[i].itemType.includes('选择') && this.codeItemTypes[i] === '选择'){
  116. // // 寻找 简码
  117. // paramsData.currentValueNo = this.getValueNo(this.codeItemDefs[i].itemValues,this.codeItemValues[i]).valueNo
  118. // paramsData.currentSeqValueNo = `{${paramsData.currentValueNo}}`
  119. // }else {
  120. // paramsData.codeHasSeq = "Y";
  121. // paramsData.hasSeqCount++;
  122. // }
  123. let paramsData = {
  124. ...this.codeItemDefs[i],
  125. }
  126. if (this.codeItemDefs[i].itemType.includes('手工') && this.codeItemTypes[i] === '手工'){
  127. paramsData.value = this.codeItemValues[i];
  128. paramsData.itemType = '手工'
  129. }else if (this.codeItemDefs[i].itemType.includes('选择') && this.codeItemTypes[i] === '选择'){
  130. // 寻找 简码
  131. paramsData.name = this.codeItemDefs[i].itemValues[0].conditionName
  132. paramsData.value = this.getValueNo(this.codeItemDefs[i].itemValues,this.codeItemValues[i]).valueNo
  133. paramsData.label = this.getValueNo(this.codeItemDefs[i].itemValues,this.codeItemValues[i]).itemValue
  134. paramsData.itemType = '选择'
  135. }else if (this.codeItemDefs[i].itemType.includes('流水号') && this.codeItemTypes[i] === '流水号'){
  136. paramsData.itemType = '流水号'
  137. }
  138. params.push(paramsData)
  139. }
  140. this.codeNoGenerate(params)
  141. },
  142. codeNoGenerate(params){
  143. codeNoGenerate(params).then(({data})=>{
  144. if (data && data.code === 0){
  145. this.searchModel = {
  146. ...this.searchModel,
  147. drawingNo: data.row.drawingNo,
  148. drawingDesc: data.row.drawingDesc,
  149. remark: data.row.remark,
  150. }
  151. }else {
  152. this.$message.warning(data.msg)
  153. }
  154. }).catch((error) => {
  155. this.$message.error(error);
  156. })
  157. },
  158. getValueNo(arr,valueItemNo){
  159. // 寻找 简码
  160. return arr.find(item=>item.valueItemNo === valueItemNo)
  161. },
  162. showAlert(msg){
  163. this.$alert(msg, '提示', {
  164. confirmButtonText: '确定',
  165. });
  166. },
  167. changeCodeItemValue(index,val){
  168. let codeItemDef = this.codeItemDefs[index]
  169. if (val === true && codeItemDef.itemByCondition === 'Y'){
  170. if (index === 0){
  171. this.$message.warning("请先检查该元素的定义可选值设置中是否都已经维护了条件!")
  172. }else {
  173. // 请求后台,让后台校验参数/获得数据
  174. let codeItemDefs = [];
  175. for (let i = 0; i <= index; i++) {
  176. let codeItemDef = {
  177. ...this.codeItemDefs[i],
  178. value:this.codeItemValues[i]
  179. }
  180. codeItemDefs.push(codeItemDef)
  181. }
  182. this.searchCodeGenerationItemValueList(codeItemDefs,index)
  183. }
  184. }
  185. },
  186. searchCodeGenerationItemValueList(arr,index){
  187. if (arr.length === 0){
  188. return;
  189. }
  190. this.loadingIndex = index
  191. this.codeItemDefs[index].itemValues = []
  192. this.$set(this.codeItemDefs, index, {...this.codeItemDefs[index]})
  193. searchCodeGenerationItemValueList(arr).then(({data})=>{
  194. if (data && data.code === 0){
  195. let itemDefs = {...this.codeItemDefs[index], itemValues: data.rows}
  196. this.$set(this.codeItemDefs, index, itemDefs)
  197. }else {
  198. this.$refs[`codeItemValue${index}`][0].blur();
  199. this.$alert(data.msg, '提示', {
  200. confirmButtonText: '确定',
  201. });
  202. }
  203. this.loadingIndex = -1
  204. }).catch((error)=>{
  205. this.$message.error(error);
  206. this.loadingIndex = -1
  207. })
  208. },
  209. changeRowCodeItemValue(index){
  210. // 值发生变化清空后续所有参数
  211. if (this.checkCodeFlag === 'Y'){
  212. for (let i = index+1; i < this.codeItemDefs.length; i++) {
  213. if (this.codeItemDefs[i].itemByCondition === 'Y'){
  214. this.$set(this.codeItemValues, i, undefined)
  215. }
  216. }
  217. }
  218. },
  219. saveDrawing(){
  220. this.$refs.drawingForm.validate((valid,obj)=>{
  221. if (valid){
  222. let params = {
  223. ...this.searchModel,
  224. site:this.$store.state.user.site,
  225. creator:this.$store.state.user.name,
  226. createDate:dayjs().format('YYYY-MM-DD HH:mm:ss'),
  227. }
  228. this.saveCodeLoading = true;
  229. saveDrawing(params).then(({data})=>{
  230. if (data && data.code === 0){
  231. this.$alert(`成功获取并保存了编码${this.searchModel.drawingNo}`, '提示', {
  232. confirmButtonText: '确定',
  233. });
  234. Object.keys(this.searchModel).forEach(key => {
  235. this.$set(this.searchModel, key, '')
  236. })
  237. for (let i = 0; i < this.codeItemDefs.length; i++) {
  238. this.$set(this.codeItemValues, i, undefined)
  239. }
  240. this.saveCodeLoading = false;
  241. this.searchCodeItemDefs();
  242. }else {
  243. this.saveCodeLoading = false;
  244. this.$message.warning(data.msg)
  245. }
  246. }).catch((error) => {
  247. this.$message.error(error);
  248. })
  249. }else {
  250. let i = 1;
  251. for (let key in obj) {
  252. this.$message.error(`${obj[key][0].message}`);
  253. if (i === 1){
  254. return
  255. }
  256. i++;
  257. }
  258. }
  259. })
  260. },
  261. searchCodeParameterById(){
  262. searchCodeParameterById(11).then(({data})=>{
  263. if (data && data.code === 0){
  264. this.checkCodeFlag = data.row.parameterValue
  265. }else {
  266. this.$message.warning(data.msg)
  267. }
  268. }).catch((error)=>{
  269. this.$message.error(error)
  270. })
  271. },
  272. handleBlurErpPartNo(){
  273. let params = {
  274. erpPartNo:this.searchModel.erpPartNo,
  275. }
  276. queryCodeErpPartNo(params).then(({data})=>{
  277. if (data && data.code === 0){
  278. if (data.row){
  279. this.searchModel.erpPartDesc = data.row.partDesc
  280. }else {
  281. this.searchModel.erpPartDesc = ''
  282. }
  283. }else {
  284. this.$message.warning(data.msg)
  285. }
  286. }).catch((error)=>{
  287. this.$message.error(error)
  288. })
  289. }
  290. },
  291. watch:{
  292. 'searchModel.erpPartNo'(newVal,oldVal){
  293. this.searchModel.erpPartNo = newVal.toUpperCase()
  294. }
  295. }
  296. }
  297. </script>
  298. <template>
  299. <div>
  300. <el-form :model="searchModel" ref="drawingForm" :rules="rules" label-position="top">
  301. <el-row :gutter="20">
  302. <el-col :span="6">
  303. <el-form-item label="编码:" prop="drawingNo" :show-message="false">
  304. <el-input readonly v-model="searchModel.drawingNo"></el-input>
  305. </el-form-item>
  306. </el-col>
  307. <el-col :span="1.5">
  308. <el-form-item label=" ">
  309. <el-button type="primary" :loading="getCodeNoLoading" @click="getCodeNoBtn">获取编码</el-button>
  310. </el-form-item>
  311. </el-col>
  312. <el-col :span="1.5">
  313. <el-form-item label=" ">
  314. <el-button type="primary" :loading="saveCodeLoading" @click="saveDrawing">占有编码</el-button>
  315. </el-form-item>
  316. </el-col>
  317. <el-col :span="3">
  318. <el-form-item label="IFS Part No" prop="erpPartNo" :show-message="false">
  319. <el-input v-model="searchModel.erpPartNo" @blur="handleBlurErpPartNo"></el-input>
  320. </el-form-item>
  321. </el-col>
  322. <el-col :span="5">
  323. <el-form-item label="IFS Part Description" prop="erpPartDesc" :show-message="false">
  324. <el-input v-model="searchModel.erpPartDesc" disabled></el-input>
  325. </el-form-item>
  326. </el-col>
  327. <el-col :span="24">
  328. <el-form-item label="编码描述:">
  329. <el-input readonly v-model="searchModel.drawingDesc"></el-input>
  330. </el-form-item>
  331. </el-col>
  332. <el-col :span="24">
  333. <el-form-item label="备注">
  334. <el-input v-model="searchModel.remark"></el-input>
  335. </el-form-item>
  336. </el-col>
  337. </el-row>
  338. </el-form>
  339. <div style="margin-top: 10px;border-top: 1px solid #ccc;padding-top: 10px;height: 680px;overflow-y: auto;width: 100%" >
  340. <el-form label-position="left" label-width="100px">
  341. <el-form-item :label="`${item.itemDesc}:`" v-for="(item, index) in codeItemDefs" :key="index" style="margin-bottom: 10px">
  342. <div v-if="item.itemType.includes('或')" style="width: 240px;display: inline-block">
  343. <el-radio-group v-model="codeItemTypes[index]" @change="changeCodeItemType(index)">
  344. <el-radio v-if="item.itemType.includes('选择')" label="选择">选择</el-radio>
  345. <el-radio v-if="item.itemType.includes('手工')" label="手工">手工</el-radio>
  346. <el-radio v-if="item.itemType.includes('流水号')" label="流水号">流水号</el-radio>
  347. </el-radio-group>
  348. </div>
  349. <div style="display: inline-block;" :style="{width: `${item.itemType.includes('或')?(width-240-205):(width-200)}px`}">
  350. <el-select
  351. :loading="loadingIndex === index"
  352. :ref="`codeItemValue${index}`"
  353. clearable v-if="codeItemTypes[index] === '选择'"
  354. filterable
  355. @change="changeRowCodeItemValue(index)"
  356. @visible-change="(val)=>changeCodeItemValue(index,val)"
  357. style="width: 100%;"
  358. v-model="codeItemValues[index]">
  359. <el-option :value="val.valueItemNo" :label="val.itemValue" v-for="(val , i) in item.itemValues" :key="i"></el-option>
  360. </el-select>
  361. <el-input v-if="codeItemTypes[index] === '手工'" placeholder="请输入" v-model="codeItemValues[index]"></el-input>
  362. <el-input v-if="codeItemTypes[index] === '流水号'" disabled v-model="codeItemValues[index]"></el-input>
  363. </div>
  364. <div style="display: inline-block" v-if="showConditionName(item.itemValues) !== ''">
  365. <span v-if="">(</span><span>{{showConditionName(item.itemValues)}}</span><span>)</span>
  366. </div>
  367. </el-form-item>
  368. </el-form>
  369. </div>
  370. </div>
  371. </template>
  372. <style scoped>
  373. </style>