prodnum-FW01B.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view>
  3. <connectingDevice ref="refCD" @onFeedback="onFeedback" />
  4. <block v-for="(item, index) in list" :key="item.w_functionid">
  5. <view
  6. v-if="item.paramName != 'E013'"
  7. class="item"
  8. :hover-class="item.inputType == 'switch' ? '' : 'navigator-hover'"
  9. @click="item.inputType == 'switch' ? '' : onClick(item)"
  10. >
  11. <view class="label">
  12. {{ item.funcname }}
  13. <block v-if="item.inputType == 'radio'">
  14. {{ radioName(item) }}
  15. </block>
  16. <block v-if="item.inputType != 'switch'">
  17. :{{
  18. item.inputType == "radio"
  19. ? item.showValue || "未设置"
  20. : item.params.lastvalue || "未设置"
  21. }}
  22. <text v-if="item.params.unit" style="margin-left: 2px"
  23. >({{ item.params.unit }})</text
  24. >
  25. </block>
  26. </view>
  27. <view>
  28. <block v-if="item.inputType == 'switch'">
  29. <u-switch
  30. :value="item.params.lastvalue == 1"
  31. asyncChange
  32. size="24"
  33. :loading="item.loading"
  34. @change="changeSwitch(item, index)"
  35. />
  36. </block>
  37. <block v-else>
  38. <u-loading-icon v-if="item.loading" />
  39. <text
  40. v-else
  41. class="iconfont icon-a-wodetiaozhuan"
  42. style="color: #fff"
  43. />
  44. </block>
  45. </view>
  46. </view>
  47. </block>
  48. <My_input mode="1" ref="MyInput" @sendMsg="onSendMsg" />
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. name: "prodnum-FW01",
  54. components: {},
  55. props: {
  56. control: Object,
  57. },
  58. data() {
  59. return {
  60. list: [],
  61. };
  62. },
  63. watch: {
  64. control: function (newVal) {
  65. if (newVal) {
  66. let names = [];
  67. for (const key in newVal.function) {
  68. names.push(key);
  69. }
  70. this.list = this.__proto__.getControlItem(names, newVal, {
  71. 安装位置: "radio",
  72. 第二域名: "string",
  73. });
  74. console.log(this.list);
  75. try {
  76. const E013 = this.list.find((v) => v.paramName == "E013");
  77. if (E013) {
  78. this.$refs.refCD.send(
  79. { password: E013.params.options[0].value },
  80. E013
  81. );
  82. }
  83. } catch (error) {}
  84. this.$refs.refCD.init();
  85. }
  86. },
  87. },
  88. methods: {
  89. onClick(item) {
  90. this.$refs.MyInput.openInput(item);
  91. },
  92. radioName(item) {
  93. try {
  94. item.showValue =
  95. item.params.options.find((v) => v.value == item.params.lastvalue)
  96. .label || "";
  97. } catch (error) {
  98. item.showValue;
  99. }
  100. return "";
  101. },
  102. changeSwitch(item, index) {
  103. const value = item.params.lastvalue == 1 ? 0 : 1;
  104. let msg = {
  105. d: {
  106. [item.params.param]: value,
  107. },
  108. };
  109. this.$refs.refCD.send(msg, item);
  110. this.$set(this.list[index], "loading", true);
  111. },
  112. onSendMsg(w_functionid, d) {
  113. const index = this.list.findIndex((v) => v.w_functionid == w_functionid);
  114. let msg = {
  115. d,
  116. };
  117. this.$refs.refCD.send(msg, this.list[index]);
  118. this.$set(this.list[index], "loading", true);
  119. },
  120. onFeedback(res) {
  121. console.log("onFeedback", res);
  122. const index = res.node
  123. ? this.list.findIndex((v) => res.node == v.paramName)
  124. : this.list.findIndex((v) => v.msgid == res.msgid);
  125. if (index != -1) {
  126. let item = this.list[index];
  127. let MyInput = this.$refs.MyInput;
  128. MyInput.loading = false;
  129. if (res.status == 1) {
  130. if (res.node) {
  131. item.params.lastvalue = res.v;
  132. } else if (res.msgid) {
  133. item.params.lastvalue = item.msg.d[item.params.param];
  134. }
  135. MyInput.show = false;
  136. MyInput.stepIsCalculate = null;
  137. } else if (res.status == 0) {
  138. if (item.paramName == "E013") {
  139. uni.showModal({
  140. title: "失败",
  141. content: `身份验证失败,将断开连接`,
  142. showCancel: false,
  143. });
  144. uni.closeBLEConnection({
  145. deviceId: that.connected
  146. });
  147. uni.closeBluetoothAdapter();
  148. } else {
  149. uni.showModal({
  150. title: "失败",
  151. content: `“${item.funcname}”设置失败`,
  152. showCancel: false,
  153. });
  154. }
  155. }
  156. MyInput.$refs.uModal.loading = false;
  157. delete item.loading;
  158. // delete item.msgid;
  159. // delete item.msg;
  160. this.$set(this.list, index, item);
  161. console.log(item);
  162. }
  163. },
  164. },
  165. };
  166. </script>
  167. <style lang="scss" scoped>
  168. .item {
  169. display: flex;
  170. justify-content: space-between;
  171. align-items: center;
  172. margin: 10px 0;
  173. box-sizing: border-box;
  174. padding: 16px 20px;
  175. border-radius: 6px;
  176. background: rgba($color: #ffffff, $alpha: 0.1);
  177. .label {
  178. color: #fff;
  179. font-size: 14px;
  180. width: 230px;
  181. }
  182. }
  183. </style>