prodnum-FW01B.vue 5.4 KB

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