ReceivingCardInfoEdit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="c-info large">
  3. <template v-if="info">
  4. <div class="l-flex--row c-info__block">
  5. <div class="l-flex--row l-flex__fill c-info__item">
  6. <div class="l-flex__none c-info__title">厂家名称</div>
  7. <el-select
  8. v-model="defaults.manufacturerId"
  9. class="l-flex__fill c-info__value"
  10. placeholder="请选择厂家"
  11. :loading="manufacturers.loading"
  12. @visible-change="getReceivingCardManufacturers"
  13. @change="onChangeProp('manufacturerId')"
  14. >
  15. <el-option
  16. v-for="manufacturer in manufacturers.list"
  17. :key="manufacturer.value"
  18. :label="manufacturer.label"
  19. :value="manufacturer.value"
  20. />
  21. </el-select>
  22. </div>
  23. <div class="l-flex--row l-flex__fill c-info__item">
  24. <div class="l-flex__none c-info__title">拓扑结构文件</div>
  25. <el-upload
  26. ref="upload"
  27. class="l-flex__fill o-upload"
  28. action="none"
  29. :auto-upload="false"
  30. :show-file-list="false"
  31. :on-change="onChangeTopology"
  32. drag
  33. >
  34. <div class="u-color--black">
  35. {{ defaults.topology }}
  36. </div>
  37. </el-upload>
  38. </div>
  39. </div>
  40. <div class="l-flex--row c-info__block">
  41. <div class="l-flex--row l-flex__fill c-info__item">
  42. <div class="l-flex__none c-info__title">屏体型号</div>
  43. <edit-input
  44. v-model.trim="defaults.screen"
  45. class="l-flex__fill c-info__value"
  46. align="left"
  47. @edit="onChangeProp('screen')"
  48. />
  49. </div>
  50. <div class="l-flex--row l-flex__fill c-info__item">
  51. <div class="l-flex__none c-info__title">是否支持卡温度监测</div>
  52. <div class="l-flex__fill">
  53. <el-switch
  54. v-model="defaults.temperature"
  55. active-color="#13ce66"
  56. inactive-color="#ff4949"
  57. @change="onChangeProp('temperature')"
  58. />
  59. </div>
  60. </div>
  61. </div>
  62. <div class="l-flex--row c-info__block">
  63. <div class="l-flex--row l-flex__fill c-info__item">
  64. <div class="l-flex__none c-info__title">是否支持卡电压监测</div>
  65. <div class="l-flex__fill">
  66. <el-switch
  67. v-model="defaults.voltage"
  68. active-color="#13ce66"
  69. inactive-color="#ff4949"
  70. @change="onChangeProp('voltage')"
  71. />
  72. </div>
  73. </div>
  74. <div class="l-flex--row l-flex__fill c-info__item">
  75. <div class="l-flex__none c-info__title">是否为异步盒</div>
  76. <div class="l-flex__fill">
  77. <el-switch
  78. v-model="defaults.async"
  79. active-color="#13ce66"
  80. inactive-color="#ff4949"
  81. @change="onChangeProp('async')"
  82. />
  83. </div>
  84. </div>
  85. </div>
  86. </template>
  87. <template v-else>
  88. <button
  89. class="o-button"
  90. @click="onAdd"
  91. >
  92. <i class="o-button__icon el-icon-circle-plus-outline" />
  93. 新增
  94. </button>
  95. <el-dialog
  96. title="新增"
  97. :visible.sync="show"
  98. custom-class="c-dialog"
  99. :close-on-click-modal="false"
  100. >
  101. <el-upload
  102. ref="upload"
  103. class="o-upload"
  104. action="none"
  105. :auto-upload="false"
  106. :show-file-list="false"
  107. :on-change="onChange"
  108. drag
  109. >
  110. <div class="l-flex--row">
  111. <template v-if="receivingCard.topologyFile">
  112. <div class="o-upload__file">{{ receivingCard.topologyFile.name }}</div>
  113. </template>
  114. <template v-else>
  115. 添加拓扑结构文件将文件拖动到本窗口上传或
  116. <span class="o-upload__tip">点击选择文件</span>
  117. </template>
  118. </div>
  119. </el-upload>
  120. <div class="c-form">
  121. <div class="c-form__section">
  122. <span class="c-form__label large required">厂家:</span>
  123. <el-select
  124. v-model="receivingCard.manufacturerId"
  125. class="c-form__item"
  126. placeholder="请选择厂家"
  127. :loading="manufacturers.loading"
  128. @visible-change="getReceivingCardManufacturers"
  129. >
  130. <el-option
  131. v-for="manufacturer in manufacturers.list"
  132. :key="manufacturer.value"
  133. :label="manufacturer.label"
  134. :value="manufacturer.value"
  135. />
  136. </el-select>
  137. </div>
  138. <div class="c-form__section">
  139. <span class="c-form__label large">型号:</span>
  140. <el-input
  141. v-model.trim="receivingCard.screen"
  142. class="c-form__item"
  143. maxlength="50"
  144. show-word-limit
  145. />
  146. </div>
  147. <div class="c-form__section">
  148. <span class="c-form__label large">是否为异步盒:</span>
  149. <el-switch
  150. v-model="receivingCard.async"
  151. class="c-form__item"
  152. active-color="#13ce66"
  153. inactive-color="#ff4949"
  154. />
  155. </div>
  156. <div class="c-form__section">
  157. <span class="c-form__label large">是否支持卡温度监测::</span>
  158. <el-switch
  159. v-model="receivingCard.temperature"
  160. class="c-form__item"
  161. active-color="#13ce66"
  162. inactive-color="#ff4949"
  163. />
  164. </div>
  165. <div class="c-form__section">
  166. <span class="c-form__label large">是否支持卡电压监测::</span>
  167. <el-switch
  168. v-model="receivingCard.voltage"
  169. class="c-form__item"
  170. active-color="#13ce66"
  171. inactive-color="#ff4949"
  172. />
  173. </div>
  174. </div>
  175. <template #footer>
  176. <button
  177. class="o-button"
  178. @click="save"
  179. >
  180. 确定
  181. </button>
  182. <button
  183. class="o-button cancel"
  184. @click="close"
  185. >
  186. 取消
  187. </button>
  188. </template>
  189. </el-dialog>
  190. <el-dialog
  191. class="c-progress"
  192. :visible.sync="showProgress"
  193. width="50%"
  194. :close-on-click-modal="false"
  195. :close-on-press-escape="false"
  196. :show-close="false"
  197. >
  198. <el-progress
  199. :percentage="progress"
  200. :stroke-width="24"
  201. text-inside
  202. status="success"
  203. />
  204. </el-dialog>
  205. </template>
  206. </div>
  207. </template>
  208. <script>
  209. import {
  210. getReceivingCardManufacturers,
  211. addReceivingCard,
  212. updateReceivingCard
  213. } from '@/api/device'
  214. export default {
  215. name: 'DeviceReceivingCardInfoEdit',
  216. props: {
  217. info: {
  218. type: Object,
  219. default: null
  220. }
  221. },
  222. data () {
  223. return {
  224. show: false,
  225. receivingCard: {},
  226. showProgress: false,
  227. progress: 0,
  228. manufacturers: {
  229. loading: false,
  230. loaded: false,
  231. list: []
  232. },
  233. defaults: null
  234. }
  235. },
  236. watch: {
  237. info: {
  238. handler () {
  239. this.getDefaults()
  240. },
  241. immediate: true
  242. }
  243. },
  244. methods: {
  245. getDefaults () {
  246. if (this.info) {
  247. this.defaults = {
  248. manufacturerId: this.info.manufacturerId,
  249. screen: this.info.screen,
  250. temperature: this.info.temperature,
  251. voltage: this.info.voltage,
  252. async: this.info.async,
  253. topology: this.info.topology?.version ?? '未上传'
  254. }
  255. if (!this.manufacturers.loaded) {
  256. this.manufacturers.list = [{ value: this.info.manufacturerId, label: this.info.manufacturer }]
  257. }
  258. }
  259. },
  260. getReceivingCardManufacturers (visible) {
  261. if (visible && !this.manufacturers.loading && !this.manufacturers.loaded) {
  262. this.manufacturers.loading = true
  263. getReceivingCardManufacturers().then(({ data }) => {
  264. this.manufacturers.list = data.map(({ id, name }) => {
  265. return { value: id, label: name }
  266. })
  267. this.manufacturers.loading = false
  268. this.manufacturers.loaded = true
  269. }, () => {
  270. this.manufacturers.loading = false
  271. })
  272. }
  273. },
  274. onAdd () {
  275. this.receivingCard = {
  276. manufacturerId: '',
  277. topologyFile: null,
  278. screen: '',
  279. temperature: false,
  280. voltage: false,
  281. async: false
  282. }
  283. this.show = true
  284. },
  285. close () {
  286. this.show = false
  287. },
  288. save () {
  289. if (!this.receivingCard.topologyFile) {
  290. this.$message({
  291. type: 'warning',
  292. message: '请选择拓扑结构文件'
  293. })
  294. return
  295. }
  296. if (!this.receivingCard.manufacturerId) {
  297. this.$message({
  298. type: 'warning',
  299. message: '请选择厂家'
  300. })
  301. return
  302. }
  303. const formData = new FormData()
  304. formData.append('manufacturerId', this.receivingCard.manufacturerId)
  305. formData.append('topologyFile', this.receivingCard.topologyFile)
  306. formData.append('screen', this.receivingCard.screen)
  307. formData.append('temperature', this.receivingCard.temperature)
  308. formData.append('voltage', this.receivingCard.voltage)
  309. formData.append('async', this.receivingCard.async)
  310. this.progress = 0
  311. this.showProgress = true
  312. addReceivingCard(this.$route.params.id, formData, ({ loaded, total }) => {
  313. this.progress = Math.min(99, loaded * 100 / total | 0)
  314. }).finally(() => {
  315. this.progress = 100
  316. this.showProgress = false
  317. }).then(() => {
  318. this.close()
  319. this.emitChange('all')
  320. })
  321. },
  322. updateReceivingCard () {
  323. updateReceivingCard()
  324. },
  325. onChange ({ raw }) {
  326. this.$refs.upload.clearFiles()
  327. this.receivingCard.topologyFile = raw
  328. },
  329. onChangeTopology ({ raw }) {
  330. this.$refs.upload.clearFiles()
  331. this.progress = 0
  332. this.showProgress = true
  333. this.updateProp('topologyFile', raw, ({ loaded, total }) => {
  334. this.progress = Math.min(99, loaded * 100 / total | 0)
  335. }).finally(() => {
  336. this.progress = 100
  337. this.showProgress = false
  338. })
  339. },
  340. onChangeProp (key) {
  341. if (this.defaults[key] === this.info[key]) {
  342. return
  343. }
  344. this.updateProp(key, this.defaults[key]).catch(() => {
  345. this.defaults[key] = this.info[key]
  346. })
  347. },
  348. updateProp (key, data, options) {
  349. const formData = new FormData()
  350. formData.append(key, data)
  351. return updateReceivingCard(this.$route.params.id, formData, options).then(() => {
  352. this.emitChange(key)
  353. })
  354. },
  355. emitChange (key) {
  356. let tip = null
  357. let reset = false
  358. switch (key) {
  359. case 'manufacturerId':
  360. tip = '厂商'
  361. break
  362. case 'topologyFile':
  363. tip = '拓扑图'
  364. reset = true
  365. break
  366. case 'all':
  367. tip = '数据'
  368. reset = true
  369. break
  370. default:
  371. break
  372. }
  373. if (!reset) {
  374. this.info[key] = this.defaults[key]
  375. }
  376. this.$emit('refresh', { tip, reset })
  377. }
  378. }
  379. }
  380. </script>