allocation.vue 19 KB

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