thxyset.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view>
  3. <view class="setitem">
  4. 设备编号:{{option.device_id}}
  5. </view>
  6. <view class="setitem">
  7. 设备名称:{{option.device_name}}
  8. </view>
  9. <view class="setitem" v-for="(item, index) in equipContrlForm">
  10. <view class="timeBox" @click="seleteTime(item)">
  11. 定时时间:{{item.time ? item.time : '请选择时间'}}
  12. </view>
  13. <u-radio-group v-model="item.value">
  14. <u-radio :name="1">开</u-radio>
  15. <u-radio :name="0">关</u-radio>
  16. </u-radio-group>
  17. <u-button style="margin: 0" type="primary" v-if="index == equipContrlForm.length - 1" size="mini" @click="editForm('add')">增加</u-button>
  18. <u-button style="margin: 0" type="error" v-if="index < equipContrlForm.length - 1" size="mini" @click="editForm(index)">删除</u-button>
  19. </view>
  20. <u-picker mode="time" v-model="timePiker" :default-time="`${item.time}`" :params="params" @confirm="(e) => changeControlTime(e)"></u-picker>
  21. <view class="submit-box">
  22. <u-button @click="submit" type="success">确定</u-button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. myuser_type:false,
  31. option: {},
  32. dsArr: ['关机', '开机'],
  33. timePiker: false,
  34. equipContrlForm: [{ time: '', value: 0 }],
  35. item:{}, // 当前编辑的对象
  36. params: {
  37. year: false,
  38. month: false,
  39. day: false,
  40. hour: true,
  41. minute: true,
  42. second: false
  43. },
  44. }
  45. },
  46. methods: {
  47. editForm(type) {
  48. if (type == 'add') {
  49. this.equipContrlForm.push({ time: '', value: 0 });
  50. } else {
  51. this.equipContrlForm.splice(type, 1);
  52. }
  53. },
  54. seleteTime(item) {
  55. this.item = item;
  56. this.timePiker = true;
  57. },
  58. changeControlTime(e) {
  59. this.item.time = `${e.hour}:${e.minute}`
  60. this.timePiker = false;
  61. },
  62. async getconf() {
  63. const res = await this.$myRequest({
  64. url: '/api/api_gateway?method=forecast.address_info.get_set_time',
  65. data: {
  66. d_id: this.option.d_id
  67. }
  68. })
  69. this.equipContrlForm = res.length > 0 ? res : [{ time: '', value: 0 }];
  70. console.log(res)
  71. },
  72. async submit() {
  73. const res = await this.$myRequest({
  74. url: '/api/api_gateway?method=forecast.address_info.set_time',
  75. data: {
  76. device_type_id: 29,
  77. device_id: this.option.device_id,
  78. data: JSON.stringify(this.equipContrlForm),
  79. }
  80. })
  81. console.log(res)
  82. if (res == true) {
  83. uni.showToast({
  84. title: '指令下发成功!',
  85. duration: 2000
  86. });
  87. } else {
  88. uni.showToast({
  89. title: '指令下发失败!',
  90. duration: 2000,
  91. icon: "none"
  92. });
  93. }
  94. },
  95. },
  96. onLoad(option) {
  97. uni.getStorage({
  98. key:"myuser_type",
  99. success:(res)=>{
  100. console.log(res.data)
  101. if(Number(res.data) == 1){
  102. this.myuser_type = true
  103. }
  104. }
  105. })
  106. this.option = option
  107. this.getconf()
  108. }
  109. }
  110. </script>
  111. <style lang='less'>
  112. page {
  113. padding: 20rpx;
  114. box-sizing: border-box;
  115. .buttonbox {
  116. display: flex;
  117. justify-content: space-between;
  118. }
  119. .setitem {
  120. margin-top: 30rpx;
  121. display: flex;
  122. justify-content: space-between;
  123. align-items: center;
  124. }
  125. .uni-list-cell {
  126. background: #F7F8FA;
  127. padding: 10rpx 40rpx;
  128. font-size: 28rpx;
  129. box-sizing: border-box;
  130. /* margin-top: 30rpx; */
  131. .arrow {
  132. display: inline-block;
  133. border-width: 12rpx 8rpx;
  134. border-style: solid;
  135. float: right;
  136. margin-top: 10rpx;
  137. border-color: #888 transparent transparent transparent;
  138. }
  139. }
  140. .submit-box {
  141. margin-top: 60rpx
  142. }
  143. }
  144. </style>