allocation.vue 22 KB

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