allocation.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. <el-button type="primary" @click="showAllocation">新建</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </el-col>
  25. <!--列表-->
  26. <el-table :data="allocations" :height="tableHeight" highlight-current-row v-loading="listLoading" style="width: 100%;">
  27. <el-table-column type="index" width="60"></el-table-column>
  28. <el-table-column prop="equipmentNo" label="云模盒编号" width="130" sortable></el-table-column>
  29. <el-table-column prop="hillNumber" label="电量" width="80" align="center" sortable></el-table-column>
  30. <el-table-column prop="useLife" label="使用年限" width="100" align="center" sortable>
  31. <template slot-scope="scope">{{scope.row.useLife}}年</template>
  32. </el-table-column>
  33. <el-table-column prop="useLife" label="倒计时" width="100" align="center" sortable>
  34. <template slot-scope="scope">{{scope.row.diffTime}}</template>
  35. </el-table-column>
  36. <el-table-column prop="modelName" label="模具名称" sortable></el-table-column>
  37. <el-table-column prop="modelNo" label="模具编号" width="120" align="center" sortable></el-table-column>
  38. <el-table-column prop="companyName" label="公司名称" sortable></el-table-column>
  39. <el-table-column prop="agent" label="代理商" width="120" sortable></el-table-column>
  40. <el-table-column label="云模盒状态" align="center" width="120" sortable>
  41. <template slot-scope="scope">
  42. <span v-if="scope.row.isUse == 0">未启用</span>
  43. <span v-else>已启用</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="操作" align="center" width="160" sortable>
  47. <template slot-scope="scope">
  48. <el-button size="small" type="primary" @click="openEnable(scope.$index)" :disabled="scope.row.isUse == 1">启用</el-button>
  49. <el-button size="small" @click="showEdit(scope.$index, scope.row, scope.row.isUse == 1)">修改</el-button>
  50. <!-- <el-button type="danger" size="small">删除</el-button> -->
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. <!--工具条-->
  55. <el-col :span="24" class="toolbar">
  56. <el-pagination
  57. @size-change="handleSizeChange"
  58. @current-change="handleCurrentChange"
  59. :page-sizes="[20 , 50 , 80 , 100]"
  60. :page-size="20"
  61. layout="total, sizes, prev, pager, next"
  62. :total="total"
  63. style="float:right;"
  64. ></el-pagination>
  65. </el-col>
  66. <!--新增界面-->
  67. <el-dialog title="新建模具" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth">
  68. <el-form
  69. :model="newAllocation"
  70. label-width="100px"
  71. :rules="formRules"
  72. ref="newAllocation"
  73. :inline="true"
  74. class="demo-form-inline"
  75. >
  76. <el-form-item label="云模盒编号" prop="equipmentNo">
  77. <el-input v-model="newAllocation.equipmentNo" autocomplete="off" placeholder="请填写云模盒编号"></el-input>
  78. </el-form-item>
  79. <el-form-item label="所属公司" prop="belongCompanyId">
  80. <el-select
  81. v-model="newAllocation.belongCompanyId"
  82. filterable
  83. clearable
  84. placeholder="请选择所属公司"
  85. style="width: 202px"
  86. >
  87. <el-option
  88. v-for="item in companies"
  89. :key="item.id"
  90. :label="item.companyName"
  91. :value="item.id"
  92. ></el-option>
  93. </el-select>
  94. </el-form-item>
  95. <el-form-item label="使用年限" prop="useLife">
  96. <el-input
  97. v-model.number="newAllocation.useLife"
  98. type="age"
  99. autocomplete="off"
  100. placeholder="请填写使用年限"
  101. ></el-input>
  102. </el-form-item>
  103. <el-form-item label="代理商" prop="agent">
  104. <el-input
  105. v-model="newAllocation.agent"
  106. autocomplete="off"
  107. placeholder="请填写代理商"
  108. style="width: 202px"
  109. ></el-input>
  110. </el-form-item>
  111. </el-form>
  112. <div slot="footer" class="dialog-footer">
  113. <el-button @click.native="addFormVisible = false">取消</el-button>
  114. <el-button type="primary" @click="addMould()">提交</el-button>
  115. </div>
  116. </el-dialog>
  117. <!--修改界面-->
  118. <el-dialog
  119. title="修改模具"
  120. v-if="editFormVisible"
  121. :visible.sync="editFormVisible"
  122. :close-on-click-modal="false"
  123. customClass="customWidth"
  124. >
  125. <el-form
  126. :model="newAllocation"
  127. label-width="100px"
  128. :rules="formRules"
  129. ref="newAllocation"
  130. :inline="true"
  131. class="demo-form-inline"
  132. >
  133. <el-form-item label="云模盒编号" prop="equipmentNo">
  134. <el-input v-model="newAllocation.equipmentNo" autocomplete="off" placeholder="请填写"></el-input>
  135. </el-form-item>
  136. <el-form-item label="所属公司" prop="belongCompanyId">
  137. <el-select
  138. v-model="newAllocation.belongCompanyId"
  139. filterable
  140. clearable
  141. placeholder="请选择所属公司"
  142. style="width: 202px"
  143. :disabled="newAllocation.usage"
  144. >
  145. <el-option
  146. v-for="item in companies"
  147. :key="item.id"
  148. :label="item.companyName"
  149. :value="item.id"
  150. ></el-option>
  151. </el-select>
  152. </el-form-item>
  153. <el-form-item label="使用年限" prop="useLife">
  154. <el-input
  155. v-model.number="newAllocation.useLife"
  156. type="age"
  157. autocomplete="off"
  158. placeholder="请填写使用年限"
  159. ></el-input>
  160. </el-form-item>
  161. <el-form-item label="代理商" prop="agent">
  162. <el-input
  163. v-model="newAllocation.agent"
  164. autocomplete="off"
  165. placeholder="请填写代理商"
  166. style="width: 202px"
  167. ></el-input>
  168. </el-form-item>
  169. </el-form>
  170. <div slot="footer" class="dialog-footer">
  171. <el-button @click.native="editFormVisible = false">取消</el-button>
  172. <el-button type="primary" @click="editMould(newAllocation.id)">提交</el-button>
  173. </div>
  174. </el-dialog>
  175. <!-- 启用弹窗 -->
  176. <el-dialog title="启用" :visible.sync="operateDialogVisible" width="100" center>
  177. <el-form
  178. label-width="100px"
  179. :rules="formRules"
  180. :inline="true"
  181. class="demo-form-inline"
  182. >
  183. <el-form-item label="某个参数">
  184. <el-input autocomplete="off" placeholder="填了也不会发生什么"></el-input>
  185. </el-form-item>
  186. </el-form>
  187. <span slot="footer" class="dialog-footer">
  188. <el-button @click="operateDialogVisible = false">取消</el-button>
  189. <el-button type="primary" @click="enable">启用</el-button>
  190. </span>
  191. </el-dialog>
  192. </section>
  193. </template>
  194. <script>
  195. import util from "../../common/js/util";
  196. export default {
  197. data() {
  198. return {
  199. allocations: [],
  200. companies: {},
  201. newAllocation: {
  202. equipmentNo: "", //设备编号
  203. useLife: "", //使用年限
  204. equipmentName: "", //设备名称
  205. id: "", //设备id
  206. belongCompanyId: "", //所属公司ID
  207. agent: "", //代理商
  208. usage: true //是否可以修改公司
  209. },
  210. filters: {
  211. keyName: "",
  212. companyId: ""
  213. },
  214. formRules: {
  215. equipmentNo: [
  216. { required: true, message: "请输入云模盒编号", trigger: "blur" }
  217. ],
  218. useLife: [
  219. { required: true, message: '请输入使用年限'},
  220. { type: 'number', message: '使用年限必须为数字值'}
  221. ],
  222. belongCompanyId: [
  223. { required: true, message: "请选择所属公司", trigger: ["blur", "change"] }
  224. ],
  225. agent: [
  226. { required: true, message: "请填写代理商", trigger: "blur" }
  227. ]
  228. },
  229. listLoading: false,
  230. addLoading: false,
  231. editLoading: false,
  232. total: 0,
  233. page: 1,
  234. size: 20,
  235. tableHeight: 0,
  236. addFormVisible: false,
  237. editFormVisible: false,
  238. operateDialogVisible: false,
  239. activeIndex: 0
  240. };
  241. },
  242. methods: {
  243. getMsg() {
  244. //获取公司下拉列表
  245. this.http.post( this.port.base.comps, {},
  246. res => {
  247. if (res.code == "ok") {
  248. this.companies = res.data;
  249. } else {
  250. this.$message({
  251. message: res.msg,
  252. type: "error"
  253. });
  254. }
  255. },
  256. error => {
  257. this.$message({
  258. message: error,
  259. type: "error"
  260. });
  261. });
  262. },
  263. //分页
  264. handleCurrentChange(val) {
  265. this.page = val;
  266. this.getMoulds();
  267. },
  268. handleSizeChange(val) {
  269. this.size = val;
  270. this.getMoulds();
  271. },
  272. //读取云模盒信息
  273. getMoulds() {
  274. this.listLoading = true;
  275. this.http.post(this.port.base.mouldeList,{
  276. pageNum: this.page,
  277. pageSize: this.size,
  278. keyName: this.filters.keyName,
  279. companyId: this.filters.companyId
  280. },
  281. res => {
  282. this.listLoading = false;
  283. if (res.code == "ok") {
  284. var list = res.data.list
  285. for(var i in list){
  286. if(list[i].endTime == null){
  287. list[i].diffTime = "";
  288. } else {
  289. list[i].diffTime = util.formatDate.dateDiff(
  290. util.formatDate.format(new Date(list[i].endTime), 'yyyy-MM-dd'),
  291. util.formatDate.format(new Date(new Date()), 'yyyy-MM-dd')
  292. );
  293. }
  294. }
  295. this.allocations = list;
  296. this.total = res.data.total;
  297. } else {
  298. this.$message({
  299. message: res.msg,
  300. type: "error"
  301. });
  302. }
  303. },
  304. error => {
  305. this.listLoading = false;
  306. this.$message({
  307. message: error,
  308. type: "error"
  309. });
  310. });
  311. },
  312. //添加界面
  313. showAllocation() {
  314. this.addFormVisible = true;
  315. this.newAllocation = {
  316. id: "",
  317. useLife: "",
  318. equipmentNo: "",
  319. belongCompanyId: "",
  320. agent: ""
  321. };
  322. },
  323. //添加模具
  324. addMould() {
  325. this.$refs.newAllocation.validate(valid => {
  326. if (valid) {
  327. this.addLoading = true;
  328. this.http.post(
  329. this.port.base.editMould,
  330. {
  331. equipmentNo: this.newAllocation.equipmentNo,
  332. belongCompanyId: this.newAllocation.belongCompanyId,
  333. useLife: this.newAllocation.useLife,
  334. agent: this.newAllocation.agent
  335. },
  336. res => {
  337. this.addLoading = false;
  338. if (res.code == "ok") {
  339. this.addFormVisible = false;
  340. this.$message({
  341. message: "添加成功",
  342. type: "success"
  343. });
  344. this.getMoulds();
  345. } else {
  346. this.$message({
  347. message: res.msg,
  348. type: "error"
  349. });
  350. }
  351. },
  352. error => {
  353. this.addLoading = false;
  354. this.addFormVisible = false;
  355. this.$message({
  356. message: error,
  357. type: "error"
  358. });
  359. }
  360. );
  361. }
  362. });
  363. },
  364. //修改界面
  365. showEdit(index, row, usageBoolean) {
  366. this.editFormVisible = true;
  367. this.newAllocation = {
  368. id: row.id,
  369. useLife: row.useLife,
  370. equipmentNo: row.equipmentNo,
  371. belongCompanyId: row.belongCompanyId,
  372. agent: row.agent,
  373. usage: usageBoolean
  374. };
  375. },
  376. //编辑模具
  377. editMould() {
  378. this.$refs.newAllocation.validate(valid => {
  379. if (valid) {
  380. this.editLoading = true;
  381. this.http.post( this.port.base.editMould, {
  382. id: this.newAllocation.id,
  383. equipmentNo: this.newAllocation.equipmentNo,
  384. equipmentName: this.newAllocation.equipmentName,
  385. belongCompanyId: this.newAllocation.belongCompanyId,
  386. useLife: this.newAllocation.useLife,
  387. agent: this.newAllocation.agent
  388. },
  389. res => {
  390. this.editLoading = false;
  391. if (res.code == "ok") {
  392. this.editFormVisible = false;
  393. this.$message({
  394. message: "添加成功",
  395. type: "success"
  396. });
  397. this.getMoulds();
  398. } else {
  399. this.$message({
  400. message: res.msg,
  401. type: "error"
  402. });
  403. }
  404. },
  405. error => {
  406. this.editLoading = false;
  407. this.editFormVisible = false;
  408. this.$message({
  409. message: error,
  410. type: "error"
  411. });
  412. });
  413. }
  414. });
  415. },
  416. //打开启用窗口
  417. openEnable(index) {
  418. this.operateDialogVisible = true;
  419. this.activeIndex = index;
  420. },
  421. //启用设备
  422. enable() {
  423. this.operateDialogVisible = false;
  424. this.allocations[this.activeIndex].isUse = 1;
  425. this.http.post( this.port.base.enableMould, {
  426. id: this.allocations[this.activeIndex].id,
  427. isUse: 1
  428. },
  429. res => {
  430. if (res.code == "ok") {
  431. this.$message({
  432. message: "修改成功",
  433. type: "success"
  434. });
  435. this.getMoulds();
  436. } else {
  437. this.$message({
  438. message: res.msg,
  439. type: "error"
  440. });
  441. }
  442. },
  443. error => {
  444. this.$message({
  445. message: error,
  446. type: "error"
  447. });
  448. });
  449. }
  450. },
  451. created() {
  452. let height = window.innerHeight;
  453. this.tableHeight = height - 210;
  454. const that = this;
  455. window.onresize = function temp() {
  456. that.tableHeight = window.innerHeight - 210;
  457. };
  458. },
  459. mounted() {
  460. this.getMsg();
  461. //获取模具列表
  462. this.getMoulds();
  463. }
  464. };
  465. </script>
  466. <style scoped>
  467. </style>