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.

280 lines
11 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
  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. export default {
  7. name: "CodeGeneration",
  8. data(){
  9. return {
  10. codeItemDefs: [],
  11. searchModel:{
  12. drawingNo: "",
  13. drawingNoNew: "",
  14. drawingDesc: "",
  15. remark: "",
  16. seqFlag: "N",
  17. },
  18. codeItemTypes: [],
  19. codeItemValues: [],
  20. width: 700,
  21. loadingIndex:-1,
  22. getCodeNoLoading: false,
  23. saveCodeLoading: false,
  24. }
  25. },
  26. created() {
  27. this.searchCodeItemDefs();
  28. },
  29. beforeDestroy() {
  30. },
  31. methods:{
  32. searchCodeItemDefs(){
  33. let params = {
  34. site:this.$store.state.user.site,
  35. }
  36. this.codeItemTypes = [];
  37. this.codeItemValues = [];
  38. searchCodeItemAllDefsSeq(params).then(({data})=>{
  39. if (data && data.code === 0){
  40. this.codeItemDefs = data.rows;
  41. for (let i = 0; i < this.codeItemDefs.length; i++) {
  42. let arr = this.codeItemDefs[i].itemType.split('或');
  43. this.codeItemTypes[i] = arr[0]
  44. this.codeItemValues[i] = undefined
  45. }
  46. }else {
  47. this.$message.warning(data.msg);
  48. }
  49. }).catch((error) => {
  50. this.$message.error(error);
  51. });
  52. },
  53. changeCodeItemType(index){
  54. this.$set(this.codeItemValues, index, undefined)
  55. this.changeRowCodeItemValue(index)
  56. },
  57. getCodeNoBtn(){
  58. if (this.codeItemDefs.length === 0){
  59. this.showAlert("尚未设置编码规则!请先到“编码组成元素定义”中定义!")
  60. return;
  61. }
  62. // this.getCodeNoLoading = true;
  63. let params = [];
  64. // 验证是否都输入
  65. for (let i = 0; i < this.codeItemDefs.length; i++) {
  66. if (!this.codeItemValues[i] && !(this.codeItemDefs[i].itemType.includes('流水号') && this.codeItemTypes[i] === '流水号')){
  67. this.showAlert(`元素${this.codeItemDefs[i].itemDesc}的值为空`);
  68. this.getCodeNoLoading = false;
  69. return;
  70. }
  71. if (this.codeItemDefs[i].itemType.includes('手工') && this.codeItemTypes[i] === '手工' && this.codeItemValues[i].length > this.codeItemDefs[i].bits ){
  72. this.showAlert(`元素${this.codeItemDefs[i].itemDesc}的值长度不正确,编码位数应为${this.codeItemDefs[i].bits}`)
  73. this.getCodeNoLoading = false;
  74. return;
  75. }
  76. // let paramsData = {
  77. // codeItemDef: {...this.codeItemDefs[i]},
  78. // currentValueNo:"",
  79. // currentSeqValueNo:"",
  80. // currentCodeDesc:"",
  81. // currentCodeRemark:"",
  82. // codeNo:"",
  83. // codeHasSeq:"N",
  84. // hasSeqCount:0,
  85. // };
  86. // if (this.codeItemDefs[i].itemType.includes('手工') && this.codeItemTypes[i] === '手工'){
  87. // paramsData.currentValueNo = this.codeItemValues[i];
  88. // paramsData.currentSeqValueNo = `{${paramsData.currentValueNo}}`
  89. // }else if (this.codeItemDefs[i].itemType.includes('选择') && this.codeItemTypes[i] === '选择'){
  90. // // 寻找 简码
  91. // paramsData.currentValueNo = this.getValueNo(this.codeItemDefs[i].itemValues,this.codeItemValues[i]).valueNo
  92. // paramsData.currentSeqValueNo = `{${paramsData.currentValueNo}}`
  93. // }else {
  94. // paramsData.codeHasSeq = "Y";
  95. // paramsData.hasSeqCount++;
  96. // }
  97. let paramsData = {
  98. ...this.codeItemDefs[i],
  99. }
  100. if (this.codeItemDefs[i].itemType.includes('手工') && this.codeItemTypes[i] === '手工'){
  101. paramsData.value = this.codeItemValues[i];
  102. paramsData.itemType = '手工'
  103. }else if (this.codeItemDefs[i].itemType.includes('选择') && this.codeItemTypes[i] === '选择'){
  104. // 寻找 简码
  105. paramsData.value = this.getValueNo(this.codeItemDefs[i].itemValues,this.codeItemValues[i]).valueNo
  106. paramsData.label = this.getValueNo(this.codeItemDefs[i].itemValues,this.codeItemValues[i]).itemValue
  107. paramsData.itemType = '选择'
  108. }else if (this.codeItemDefs[i].itemType.includes('流水号') && this.codeItemTypes[i] === '流水号'){
  109. paramsData.itemType = '流水号'
  110. }
  111. params.push(paramsData)
  112. }
  113. this.codeNoGenerate(params)
  114. },
  115. codeNoGenerate(params){
  116. codeNoGenerate(params).then(({data})=>{
  117. if (data && data.code === 0){
  118. this.searchModel = {...data.row}
  119. }else {
  120. this.$message.warning(data.msg)
  121. }
  122. }).catch((error) => {
  123. this.$message.error(error);
  124. })
  125. },
  126. getValueNo(arr,valueItemNo){
  127. // 寻找 简码
  128. return arr.find(item=>item.valueItemNo === valueItemNo)
  129. },
  130. showAlert(msg){
  131. this.$alert(msg, '提示', {
  132. confirmButtonText: '确定',
  133. });
  134. },
  135. changeCodeItemValue(index,val){
  136. let codeItemDef = this.codeItemDefs[index]
  137. if (val === true && codeItemDef.itemByCondition === 'Y' && !this.codeItemValues[index]){
  138. if (index === 0){
  139. this.$message.warning("请先检查该元素的定义可选值设置中是否都已经维护了条件!")
  140. }else {
  141. // 请求后台,让后台校验参数/获得数据
  142. let codeItemDefs = [];
  143. for (let i = 0; i <= index; i++) {
  144. let codeItemDef = {
  145. ...this.codeItemDefs[i],
  146. value:this.codeItemValues[i]
  147. }
  148. codeItemDefs.push(codeItemDef)
  149. }
  150. this.searchCodeGenerationItemValueList(codeItemDefs,index)
  151. }
  152. }
  153. },
  154. searchCodeGenerationItemValueList(arr,index){
  155. if (arr.length === 0){
  156. return;
  157. }
  158. this.loadingIndex = index
  159. this.codeItemDefs[index].itemValues = []
  160. this.$set(this.codeItemDefs, index, {...this.codeItemDefs[index]})
  161. searchCodeGenerationItemValueList(arr).then(({data})=>{
  162. if (data && data.code === 0){
  163. let itemDefs = {...this.codeItemDefs[index], itemValues: data.rows}
  164. this.$set(this.codeItemDefs, index, itemDefs)
  165. }else {
  166. this.$refs[`codeItemValue${index}`][0].blur();
  167. this.$alert(data.msg, '提示', {
  168. confirmButtonText: '确定',
  169. });
  170. }
  171. this.loadingIndex = -1
  172. }).catch((error)=>{
  173. this.$message.error(error);
  174. this.loadingIndex = -1
  175. })
  176. },
  177. changeRowCodeItemValue(index){
  178. // 值发生变化清空后续所有参数
  179. for (let i = index+1; i < this.codeItemDefs.length; i++) {
  180. if (this.codeItemDefs[i].itemByCondition === 'Y'){
  181. this.$set(this.codeItemValues, i, undefined)
  182. }
  183. }
  184. },
  185. saveDrawing(){
  186. let params = {
  187. ...this.searchModel,
  188. site:this.$store.state.user.site,
  189. creator:this.$store.state.user.name,
  190. createDate:dayjs().format('YYYY-MM-DD HH:mm:ss'),
  191. }
  192. this.saveCodeLoading = true;
  193. saveDrawing(params).then(({data})=>{
  194. if (data && data.code === 0){
  195. this.$alert(`成功获取并保存了编码${this.searchModel.drawingNo}`, '提示', {
  196. confirmButtonText: '确定',
  197. });
  198. Object.keys(this.searchModel).forEach(key => {
  199. this.$set(this.searchModel, key, '')
  200. })
  201. for (let i = 0; i < this.codeItemDefs.length; i++) {
  202. this.$set(this.codeItemValues, i, undefined)
  203. }
  204. this.saveCodeLoading = false;
  205. this.searchCodeItemDefs();
  206. }else {
  207. this.saveCodeLoading = false;
  208. this.$message.warning(data.msg)
  209. }
  210. }).catch((error) => {
  211. this.$message.error(error);
  212. })
  213. }
  214. },
  215. }
  216. </script>
  217. <template>
  218. <div>
  219. <el-form :model="searchModel" label-position="top">
  220. <el-row :gutter="20">
  221. <el-col :span="6">
  222. <el-form-item label="编码:">
  223. <el-input readonly v-model="searchModel.drawingNo"></el-input>
  224. </el-form-item>
  225. </el-col>
  226. <el-col :span="6">
  227. <el-form-item label=" ">
  228. <el-button type="primary" :loading="getCodeNoLoading" @click="getCodeNoBtn">获取编码</el-button>
  229. <el-button type="primary" :loading="saveCodeLoading" @click="saveDrawing">占有编码</el-button>
  230. </el-form-item>
  231. </el-col>
  232. <el-col :span="24">
  233. <el-form-item label="编码描述:">
  234. <el-input readonly v-model="searchModel.drawingDesc"></el-input>
  235. </el-form-item>
  236. </el-col>
  237. <el-col :span="24">
  238. <el-form-item label="备注">
  239. <el-input readonly v-model="searchModel.remark"></el-input>
  240. </el-form-item>
  241. </el-col>
  242. </el-row>
  243. </el-form>
  244. <!-- {{codeItemDefs}}-->
  245. <div style="margin-top: 10px;border-top: 1px solid #ccc;padding-top: 10px;height: 680px;overflow-y: auto" :style="{width: `${width}px`}">
  246. <el-form label-position="left" label-width="100px">
  247. <el-form-item :label="`${item.itemDesc}:`" v-for="(item, index) in codeItemDefs" :key="index" style="margin-bottom: 10px">
  248. <div v-if="item.itemType.includes('或')" style="width: 240px;display: inline-block">
  249. <el-radio-group v-model="codeItemTypes[index]" @change="changeCodeItemType(index)">
  250. <el-radio v-if="item.itemType.includes('选择')" label="选择">选择</el-radio>
  251. <el-radio v-if="item.itemType.includes('手工')" label="手工">手工</el-radio>
  252. <el-radio v-if="item.itemType.includes('流水号')" label="流水号">流水号</el-radio>
  253. </el-radio-group>
  254. </div>
  255. <div style="display: inline-block;" :style="{width: `${item.itemType.includes('或')?(width-240-105):(width-100)}px`}">
  256. <el-select
  257. :loading="loadingIndex === index"
  258. :ref="`codeItemValue${index}`"
  259. clearable v-if="codeItemTypes[index] === '选择'"
  260. @change="changeRowCodeItemValue(index)"
  261. @visible-change="(val)=>changeCodeItemValue(index,val)"
  262. style="width: 100%;"
  263. v-model="codeItemValues[index]">
  264. <el-option :value="val.valueItemNo" :label="val.itemValue" v-for="(val , i) in item.itemValues" :key="i"></el-option>
  265. </el-select>
  266. <el-input v-if="codeItemTypes[index] === '手工'" placeholder="请输入" v-model="codeItemValues[index]"></el-input>
  267. <el-input v-if="codeItemTypes[index] === '流水号'" disabled v-model="codeItemValues[index]"></el-input>
  268. </div>
  269. </el-form-item>
  270. </el-form>
  271. </div>
  272. </div>
  273. </template>
  274. <style scoped>
  275. </style>