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.

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