allocation.vue 29 KB

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