prodnum-FW01B.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. setTimeout(() => {
  75. this.authentication(this);
  76. }, 100);
  77. this.$refs.refCD.init();
  78. }
  79. },
  80. },
  81. methods: {
  82. authentication(that) {
  83. try {
  84. uni.showLoading({
  85. title: "身份验证中...",
  86. mask: true,
  87. });
  88. const E013 = that.list.find((v) => v.paramName == "E013");
  89. if (E013) {
  90. that.$refs.refCD.send({ password: that.control.bluetoothcode }, E013);
  91. }
  92. } catch (error) {
  93. console.error("下发身份验证失败", error);
  94. }
  95. },
  96. onClick(item) {
  97. this.$refs.MyInput.openInput(item);
  98. },
  99. radioName(item) {
  100. try {
  101. item.showValue =
  102. item.params.options.find((v) => v.value == item.params.lastvalue)
  103. .label || "";
  104. } catch (error) {
  105. item.showValue;
  106. }
  107. return "";
  108. },
  109. changeSwitch(item, index) {
  110. const value = item.params.lastvalue == 1 ? 0 : 1;
  111. let msg = {
  112. d: {
  113. [item.params.param]: value,
  114. },
  115. };
  116. this.$refs.refCD.send(msg, item);
  117. this.$set(this.list[index], "loading", true);
  118. },
  119. onSendMsg(w_functionid, d) {
  120. const index = this.list.findIndex((v) => v.w_functionid == w_functionid);
  121. let msg = {
  122. d,
  123. };
  124. this.$refs.refCD.send(msg, this.list[index]);
  125. this.$set(this.list[index], "loading", true);
  126. },
  127. onFeedback(res) {
  128. console.log("onFeedback", res);
  129. const index = res.node
  130. ? this.list.findIndex((v) => res.node == v.paramName)
  131. : this.list.findIndex((v) => v.msgid == res.msgid);
  132. uni.hideLoading();
  133. let that = this;
  134. if (index != -1) {
  135. let item = this.list[index];
  136. let MyInput = this.$refs.MyInput;
  137. MyInput.loading = false;
  138. if (res.status == 1) {
  139. if (res.node) {
  140. item.params.lastvalue = res.v;
  141. } else if (res.msgid) {
  142. try {
  143. item.params.lastvalue = item.msg.d[item.params.param];
  144. } catch (error) {}
  145. }
  146. MyInput.show = false;
  147. MyInput.stepIsCalculate = null;
  148. } else if (res.status == 0) {
  149. if (item.paramName == "E013") {
  150. uni.showModal({
  151. content: `身份验证失败`,
  152. confirmText: "重新验证",
  153. cancelText: "断开连接",
  154. complete: ({ confirm, cancel }) => {
  155. if (confirm) {
  156. that.authentication(that);
  157. }
  158. if (cancel) {
  159. uni.closeBLEConnection({
  160. deviceId: that.connected,
  161. });
  162. that.$Http.setDetailMode(0);
  163. }
  164. },
  165. });
  166. } else {
  167. uni.showModal({
  168. title: "失败",
  169. content: `“${item.funcname}”设置失败`,
  170. showCancel: false,
  171. });
  172. }
  173. }
  174. MyInput.$refs.uModal.loading = false;
  175. delete item.loading;
  176. // delete item.msgid;
  177. // delete item.msg;
  178. this.$set(this.list, index, item);
  179. console.log(item);
  180. }
  181. },
  182. },
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .item {
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. margin: 10px 0;
  191. box-sizing: border-box;
  192. padding: 16px 20px;
  193. border-radius: 6px;
  194. background: rgba($color: #ffffff, $alpha: 0.1);
  195. .label {
  196. color: #fff;
  197. font-size: 14px;
  198. width: 230px;
  199. }
  200. }
  201. </style>