allocation.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true" :model="filters">
  6. <el-col :span="3">
  7. <el-form-item>
  8. <el-select v-model="filters.companyId" clearable filterable placeholder="请选择公司">
  9. <el-option v-for="item in companies" :key="item.id" :label="item.companyName" :value="item.id">
  10. </el-option>
  11. </el-select>
  12. </el-form-item>
  13. </el-col>
  14. <el-form-item>
  15. <el-input v-model="filters.keyName" placeholder="请输入关键字进行搜索"></el-input>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" @click="getMoulds">查询</el-button>
  19. </el-form-item>
  20. <el-form-item style="float: right;">
  21. <a class="download" href="/upload/云模盒批量导入模板.xlsx" download="云模盒批量导入模板.xlsx">
  22. <el-button type="primary">
  23. 下载模板
  24. </el-button>
  25. </a>
  26. </el-form-item>
  27. <el-form-item style="float: right;">
  28. <el-upload ref="upload" action="customize" :show-file-list="false" :http-request="uploadFile" :limit="1">
  29. <el-button type="primary" :loading="uploading">批量导入</el-button>
  30. </el-upload>
  31. </el-form-item>
  32. <el-form-item style="float: right;">
  33. <el-button type="primary" @click="showAllocation">新建</el-button>
  34. </el-form-item>
  35. <el-form-item style="float: right;">
  36. <el-button type="primary" @click="issued">下发</el-button>
  37. </el-form-item>
  38. </el-form>
  39. </el-col>
  40. <!--列表-->
  41. <el-table :data="allocations" :height="tableHeight" highlight-current-row v-loading="listLoading" @selection-change="handleSelectionChange" style="width: 100%;">
  42. <el-table-column type="selection" width="50"></el-table-column>
  43. <el-table-column type="index" width="60"></el-table-column>
  44. <el-table-column prop="equipmentNo" label="云模盒编号" width="180" sortable>
  45. <template slot-scope="scope">12345678998765432132</template>
  46. </el-table-column>
  47. <el-table-column prop="hillNumber" label="电量" width="80" align="center" sortable></el-table-column>
  48. <el-table-column prop="useLife" label="使用年限" width="100" align="center" sortable>
  49. <template slot-scope="scope">{{scope.row.useLife}}年</template>
  50. </el-table-column>
  51. <el-table-column prop="useLife" label="倒计时" width="100" align="center" sortable>
  52. <template slot-scope="scope">{{scope.row.diffTime}}</template>
  53. </el-table-column>
  54. <el-table-column prop="modelName" label="模具名称" sortable></el-table-column>
  55. <el-table-column prop="modelNo" label="模具编号" width="120" align="center" sortable></el-table-column>
  56. <el-table-column prop="companyName" label="公司名称" sortable></el-table-column>
  57. <el-table-column prop="agent" label="代理商" width="120" sortable></el-table-column>
  58. <el-table-column label="云模盒状态" align="center" width="120" sortable>
  59. <template slot-scope="scope">
  60. <span v-if="scope.row.isUse == 0">未启用</span>
  61. <span v-else>已启用</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="操作" align="center" width="160">
  65. <template slot-scope="scope">
  66. <el-button size="small" v-if="scope.row.modelNo != null && scope.row.isUse == 0" type="primary" @click="openEnable(scope.$index)">启用</el-button>
  67. <el-button size="small" v-if="scope.row.modelNo != null && scope.row.isUse == 1" type="danger" @click="disableEquipment(scope.$index)">停用</el-button>
  68. <!-- :disabled="scope.row.isUse == 1" -->
  69. <el-button size="small" :style="scope.row.modelNo != null?'':'float:right;margin-right:6px'" @click="showEdit(scope.$index, scope.row, scope.row.isUse == 1)">修改</el-button>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <!--工具条-->
  74. <el-col :span="24" class="toolbar">
  75. <el-pagination
  76. @size-change="handleSizeChange"
  77. @current-change="handleCurrentChange"
  78. :page-sizes="[20 , 50 , 80 , 100]"
  79. :page-size="20"
  80. layout="total, sizes, prev, pager, next"
  81. :total="total"
  82. style="float:right;"
  83. ></el-pagination>
  84. </el-col>
  85. <!--新增界面-->
  86. <el-dialog title="新建云模盒" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth">
  87. <el-form :model="newAllocation" label-width="100px" :rules="formRules" ref="newAllocation" :inline="true" class="demo-form-inline">
  88. <el-form-item label="云模盒编号" prop="equipmentNo">
  89. <el-input v-model="newAllocation.equipmentNo" autocomplete="off" placeholder="请输入云模盒编号"></el-input>
  90. </el-form-item>
  91. <el-form-item label="所属公司" prop="belongCompanyId">
  92. <el-select v-model="newAllocation.belongCompanyId" filterable clearable placeholder="请选择所属公司" style="width: 202px">
  93. <el-option v-for="item in companies" :key="item.id" :label="item.companyName" :value="item.id"></el-option>
  94. </el-select>
  95. </el-form-item>
  96. <el-form-item label="使用年限" prop="useLife">
  97. <el-input v-model.number="newAllocation.useLife" type="age" autocomplete="off" placeholder="请输入使用年限"></el-input>
  98. </el-form-item>
  99. <el-form-item label="代理商" prop="agent">
  100. <el-input v-model="newAllocation.agent" autocomplete="off" placeholder="请输入代理商" style="width: 202px"></el-input>
  101. </el-form-item>
  102. </el-form>
  103. <div slot="footer" class="dialog-footer">
  104. <el-button @click.native="addFormVisible = false">取消</el-button>
  105. <el-button type="primary" @click="addMould()">提交</el-button>
  106. </div>
  107. </el-dialog>
  108. <!--修改界面-->
  109. <el-dialog title="修改云模盒" v-if="editFormVisible" :visible.sync="editFormVisible" :close-on-click-modal="false" customClass="customWidth">
  110. <el-form :model="newAllocation" label-width="100px" :rules="formRules" ref="newAllocation" :inline="true" class="demo-form-inline">
  111. <el-form-item label="云模盒编号" prop="equipmentNo">
  112. <el-input v-model="newAllocation.equipmentNo" autocomplete="off" placeholder="请输入云模盒编号"></el-input>
  113. </el-form-item>
  114. <el-form-item label="所属公司" prop="belongCompanyId">
  115. <el-select v-model="newAllocation.belongCompanyId" filterable clearable placeholder="请选择所属公司" style="width: 202px" :disabled="newAllocation.usage">
  116. <el-option v-for="item in companies" :key="item.id" :label="item.companyName" :value="item.id"></el-option>
  117. </el-select>
  118. </el-form-item>
  119. <el-form-item label="使用年限" prop="useLife">
  120. <el-input v-model.number="newAllocation.useLife" type="age" autocomplete="off" placeholder="请输入使用年限"></el-input>
  121. </el-form-item>
  122. <el-form-item label="代理商" prop="agent">
  123. <el-input v-model="newAllocation.agent" autocomplete="off" placeholder="请输入代理商" style="width: 202px"></el-input>
  124. </el-form-item>
  125. </el-form>
  126. <div slot="footer" class="dialog-footer">
  127. <el-button @click.native="editFormVisible = false">取消</el-button>
  128. <el-button type="primary" @click="editMould(newAllocation.id)">提交</el-button>
  129. </div>
  130. </el-dialog>
  131. <!-- 启用弹窗 -->
  132. <el-dialog title="启用" :visible.sync="operateDialogVisible" width="400px">
  133. <el-form label-width="100px" :rules="formRules" :inline="true" class="demo-form-inline">
  134. <!-- <el-form-item label="某个参数">
  135. <el-input autocomplete="off" placeholder="填了也不会发生什么"></el-input>
  136. </el-form-item> -->
  137. </el-form>
  138. <span slot="footer" class="dialog-footer">
  139. <el-button @click="operateDialogVisible = false">取消</el-button>
  140. <el-button type="primary" @click="enable">启用</el-button>
  141. </span>
  142. </el-dialog>
  143. <!-- 下发弹窗 -->
  144. <el-dialog title="下发" :visible.sync="issuedVisible" width="450px">
  145. <el-form :model="issuedVal" label-width="130px" :rules="formRules" ref="issuedVal" :inline="true" class="demo-form-inline">
  146. <el-form-item label="报警电池电量" prop="alarmBattery">
  147. <el-input v-model.number="issuedVal.alarmBattery" type="age" autocomplete="off" placeholder="请输入报警电池电量" style="width:250px;"></el-input>
  148. %
  149. </el-form-item>
  150. <el-form-item label="热报警度数" prop="alarmDegree">
  151. <el-input v-model.number="issuedVal.alarmDegree" type="age" autocomplete="off" placeholder="请输入热报警度数" style="width:250px;"></el-input>
  152. </el-form-item>
  153. </el-form>
  154. <span slot="footer" class="dialog-footer">
  155. <el-button @click="issuedVisible = false">取消</el-button>
  156. <el-button type="primary" @click="saveIssued">下发</el-button>
  157. </span>
  158. </el-dialog>
  159. </section>
  160. </template>
  161. <script>
  162. import util from "../../common/js/util";
  163. export default {
  164. data() {
  165. return {
  166. allocations: [],
  167. companies: {},
  168. newAllocation: {
  169. equipmentNo: "", //设备编号
  170. useLife: "", //使用年限
  171. equipmentName: "", //设备名称
  172. id: "", //设备id
  173. belongCompanyId: "", //所属公司ID
  174. agent: "", //代理商
  175. usage: true //是否可以修改公司
  176. },
  177. filters: {
  178. keyName: "",
  179. companyId: ""
  180. },
  181. formRules: {
  182. equipmentNo: [
  183. { required: true, message: "请输入云模盒编号", trigger: "blur" }
  184. ],
  185. useLife: [
  186. { required: true, message: '请输入使用年限'},
  187. { type: 'number', message: '使用年限必须为数字值'}
  188. ],
  189. belongCompanyId: [
  190. { required: true, message: "请选择所属公司", trigger: ["blur", "change"] }
  191. ],
  192. agent: [
  193. { required: true, message: "请输入代理商", trigger: "blur" }
  194. ],
  195. alarmBattery: [
  196. { required: true, message: '请输入报警电池电量'},
  197. { type: 'number', message: '报警电池电量必须为数字值'}
  198. ],
  199. alarmDegree: [
  200. { required: true, message: '请输入热报警度数'},
  201. { type: 'number', message: '热报警度数必须为数字值'}
  202. ],
  203. },
  204. listLoading: false,
  205. addLoading: false,
  206. editLoading: false,
  207. uploading: false,
  208. total: 0,
  209. page: 1,
  210. size: 20,
  211. tableHeight: 0,
  212. addFormVisible: false,
  213. editFormVisible: false,
  214. operateDialogVisible: false,
  215. activeIndex: 0,
  216. issuedVal: {
  217. alarmBattery: 30,
  218. alarmDegree: 80,
  219. },
  220. issuedVisible: false,
  221. multipleSelection: [],
  222. };
  223. },
  224. methods: {
  225. getMsg() {
  226. //获取公司下拉列表
  227. this.http.post( this.port.base.getCompanys, {},
  228. res => {
  229. if (res.code == "ok") {
  230. this.companies = res.data;
  231. } else {
  232. this.$message({
  233. message: res.msg,
  234. type: "error"
  235. });
  236. }
  237. },
  238. error => {
  239. this.$message({
  240. message: error,
  241. type: "error"
  242. });
  243. });
  244. },
  245. //分页
  246. handleCurrentChange(val) {
  247. this.page = val;
  248. this.getMoulds();
  249. },
  250. handleSizeChange(val) {
  251. this.size = val;
  252. this.getMoulds();
  253. },
  254. //读取云模盒信息
  255. getMoulds() {
  256. this.listLoading = true;
  257. this.http.post(this.port.base.mouldeList,{
  258. pageNum: this.page,
  259. pageSize: this.size,
  260. keyName: this.filters.keyName,
  261. companyId: this.filters.companyId
  262. },
  263. res => {
  264. this.listLoading = false;
  265. if (res.code == "ok") {
  266. var list = res.data.list
  267. for(var i in list){
  268. if(list[i].endTime == null){
  269. list[i].diffTime = "";
  270. } else {
  271. list[i].diffTime = util.formatDate.dateDiff(
  272. //util.formatDate.format(new Date(list[i].endTime), 'yyyy-MM-dd'),
  273. list[i].endTime,
  274. util.formatDate.format(new Date(new Date()), 'yyyy-MM-dd')
  275. );
  276. }
  277. }
  278. this.allocations = list;
  279. this.total = res.data.total;
  280. } else {
  281. this.$message({
  282. message: res.msg,
  283. type: "error"
  284. });
  285. }
  286. },
  287. error => {
  288. this.listLoading = false;
  289. this.$message({
  290. message: error,
  291. type: "error"
  292. });
  293. });
  294. },
  295. //添加界面
  296. showAllocation() {
  297. this.addFormVisible = true;
  298. this.newAllocation = {
  299. id: "",
  300. useLife: "",
  301. equipmentNo: "",
  302. belongCompanyId: "",
  303. agent: ""
  304. };
  305. },
  306. //添加模具
  307. addMould() {
  308. this.$refs.newAllocation.validate(valid => {
  309. if (valid) {
  310. this.addLoading = true;
  311. this.http.post(
  312. this.port.base.editMould,
  313. {
  314. equipmentNo: this.newAllocation.equipmentNo,
  315. belongCompanyId: this.newAllocation.belongCompanyId,
  316. useLife: this.newAllocation.useLife,
  317. agent: this.newAllocation.agent
  318. },
  319. res => {
  320. this.addLoading = false;
  321. if (res.code == "ok") {
  322. this.addFormVisible = false;
  323. this.$message({
  324. message: "添加成功",
  325. type: "success"
  326. });
  327. this.getMoulds();
  328. } else {
  329. this.$message({
  330. message: res.msg,
  331. type: "error"
  332. });
  333. }
  334. },
  335. error => {
  336. this.addLoading = false;
  337. this.addFormVisible = false;
  338. this.$message({
  339. message: error,
  340. type: "error"
  341. });
  342. }
  343. );
  344. }
  345. });
  346. },
  347. //修改界面
  348. showEdit(index, row, usageBoolean) {
  349. this.editFormVisible = true;
  350. this.newAllocation = {
  351. id: row.id,
  352. useLife: row.useLife,
  353. equipmentNo: row.equipmentNo,
  354. belongCompanyId: row.belongCompanyId,
  355. agent: row.agent,
  356. usage: usageBoolean
  357. };
  358. },
  359. //编辑模具
  360. editMould() {
  361. this.$refs.newAllocation.validate(valid => {
  362. if (valid) {
  363. this.editLoading = true;
  364. this.http.post( this.port.base.editMould, {
  365. id: this.newAllocation.id,
  366. equipmentNo: this.newAllocation.equipmentNo,
  367. equipmentName: this.newAllocation.equipmentName,
  368. belongCompanyId: this.newAllocation.belongCompanyId,
  369. useLife: this.newAllocation.useLife,
  370. agent: this.newAllocation.agent
  371. },
  372. res => {
  373. this.editLoading = false;
  374. if (res.code == "ok") {
  375. this.editFormVisible = false;
  376. this.$message({
  377. message: "修改成功",
  378. type: "success"
  379. });
  380. this.getMoulds();
  381. } else {
  382. this.$message({
  383. message: res.msg,
  384. type: "error"
  385. });
  386. }
  387. },
  388. error => {
  389. this.editLoading = false;
  390. this.editFormVisible = false;
  391. this.$message({
  392. message: error,
  393. type: "error"
  394. });
  395. });
  396. }
  397. });
  398. },
  399. //打开启用窗口
  400. openEnable(index) {
  401. this.operateDialogVisible = true;
  402. this.activeIndex = index;
  403. },
  404. //启用设备
  405. enable() {
  406. if(this.allocations[this.activeIndex].belongCompanyId == null){
  407. this.$message({
  408. message: "输入所属公司后才能启用模具",
  409. type: "error"
  410. });
  411. }else{
  412. this.operateDialogVisible = false;
  413. this.allocations[this.activeIndex].isUse = 1;
  414. this.http.post( this.port.base.enableMould, {
  415. id: this.allocations[this.activeIndex].id,
  416. isUse: 1
  417. },
  418. res => {
  419. if (res.code == "ok") {
  420. this.$message({
  421. message: "设备已启用",
  422. type: "success"
  423. });
  424. this.getMoulds();
  425. } else {
  426. this.$message({
  427. message: res.msg,
  428. type: "error"
  429. });
  430. }
  431. },
  432. error => {
  433. this.$message({
  434. message: error,
  435. type: "error"
  436. });
  437. });
  438. }
  439. },
  440. //停用云模盒
  441. disableEquipment(index) {
  442. if(this.allocations[index].belongCompanyId == null){
  443. this.$message({
  444. message: "输入所属公司后才能启用模具",
  445. type: "error"
  446. });
  447. }else{
  448. this.operateDialogVisible = false;
  449. this.allocations[index].isUse = 0;
  450. this.http.post( this.port.base.enableMould, {
  451. id: this.allocations[index].id,
  452. isUse: 0
  453. },
  454. res => {
  455. if (res.code == "ok") {
  456. this.$message({
  457. message: "设备已停用",
  458. type: "success"
  459. });
  460. this.getMoulds();
  461. } else {
  462. this.$message({
  463. message: res.msg,
  464. type: "error"
  465. });
  466. }
  467. },
  468. error => {
  469. this.$message({
  470. message: error,
  471. type: "error"
  472. });
  473. });
  474. }
  475. },
  476. //导入云模盒
  477. uploadFile(params) {
  478. var fileObj = params.file;
  479. var form = new FormData();
  480. form.append("file", fileObj);
  481. this.uploading = true;
  482. this.http.uploadFile( this.port.base.importMouldEquipmentExcel, form,
  483. res => {
  484. this.uploading = false;
  485. this.$refs.upload.clearFiles();
  486. if (res.code == "ok") {
  487. this.$message({
  488. message: "上传成功",
  489. type: "success"
  490. });
  491. this.getMoulds();
  492. } else {
  493. this.$message({
  494. message: res.msg,
  495. type: "error"
  496. });
  497. }
  498. },
  499. error => {
  500. this.uploading = false;
  501. this.$refs.upload.clearFiles();
  502. this.$message({
  503. message: error,
  504. type: "error"
  505. });
  506. });
  507. },
  508. //列表选择
  509. handleSelectionChange(val) {
  510. this.multipleSelection = val;
  511. },
  512. //下发云模盒
  513. issued() {
  514. this.issuedVisible = true;
  515. },
  516. saveIssued() {
  517. console.log(this.multipleSelection)
  518. console.log(this.issuedVal)
  519. console.log(this.issuedVal.alarmBattery.toString(16))
  520. console.log(this.issuedVal.alarmDegree.toString(16))
  521. if(this.multipleSelection.length == 0) {
  522. this.$message({
  523. message: "请选择要下发的云模盒",
  524. type: "error"
  525. });
  526. } else {
  527. var str = '';
  528. for(var i in this.multipleSelection) {
  529. str += this.multipleSelection[i].equipmentNo + ',';
  530. }
  531. str = str.substring(0,str.length-1)
  532. this.http.post( this.port.base.setPacket, {
  533. lowPowerLimit: this.issuedVal.alarmBattery.toString(16),
  534. hotAlarmLimit: this.issuedVal.alarmDegree.toString(16),
  535. equipmentNo: str
  536. },
  537. res => {
  538. if (res.code == "ok") {
  539. this.$message({
  540. message: "下发成功",
  541. type: "success"
  542. });
  543. this.getMoulds();
  544. } else {
  545. this.$message({
  546. message: res.msg,
  547. type: "error"
  548. });
  549. }
  550. },
  551. error => {
  552. this.$message({
  553. message: error,
  554. type: "error"
  555. });
  556. });
  557. }
  558. }
  559. },
  560. created() {
  561. let height = window.innerHeight;
  562. this.tableHeight = height - 210;
  563. const that = this;
  564. window.onresize = function temp() {
  565. that.tableHeight = window.innerHeight - 210;
  566. };
  567. },
  568. mounted() {
  569. this.getMsg();
  570. //获取模具列表
  571. this.getMoulds();
  572. }
  573. };
  574. </script>
  575. <style scoped>
  576. .download {
  577. color: #fff;
  578. text-decoration: none;
  579. }
  580. </style>