user-list.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <el-dialog :title="$t('device.user-list.041943-0')" :visible.sync="openSelectUser" width="800px">
  3. <div style="margin-top: -50px">
  4. <el-divider></el-divider>
  5. </div>
  6. <!--用户数据-->
  7. <el-form :model="queryParams" ref="queryForm" :rules="rules" :inline="true" label-width="80px">
  8. <el-form-item :label="$t('device.user-list.041943-1')" prop="phonenumber">
  9. <el-input
  10. type="text"
  11. :placeholder="$t('device.user-list.041943-2')"
  12. v-model="queryParams.phonenumber"
  13. minlength="10"
  14. clearable
  15. size="small"
  16. show-word-limit
  17. style="width: 240px"
  18. @keyup.enter.native="handleQuery"
  19. ></el-input>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('device.user-list.041943-3') }}</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-table :border="false" v-loading="loading" :data="userList" highlight-current-row size="mini" @current-change="handleCurrentChange" border>
  26. <el-table-column :label="$t('device.device-edit.148398-6')" width="50" align="center">
  27. <template slot-scope="scope">
  28. <input type="radio" :checked="scope.row.isSelect" name="user" />
  29. </template>
  30. </el-table-column>
  31. <el-table-column :label="$t('device.user-list.041943-5')" align="center" key="userId" prop="userId" width="120" />
  32. <el-table-column :label="$t('device.user-list.041943-6')" align="center" key="userName" prop="userName" />
  33. <el-table-column :label="$t('device.user-list.041943-7')" align="center" key="nickName" prop="nickName" />
  34. <el-table-column :label="$t('device.user-list.041943-1')" align="center" key="phonenumber" prop="phonenumber" width="120" />
  35. <el-table-column :label="$t('device.user-list.041943-8')" align="center" prop="createTime" width="160">
  36. <template slot-scope="scope">
  37. <span>{{ parseTime(scope.row.createTime) }}</span>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <div slot="footer" class="dialog-footer">
  42. <el-button type="primary" @click="addDeviceUser">{{ $t('device.user-list.041943-9') }}</el-button>
  43. <el-button @click="closeSelectUser">{{ $t('device.user-list.041943-10') }}</el-button>
  44. </div>
  45. </el-dialog>
  46. </template>
  47. <script>
  48. import { listUser } from '@/api/iot/tool';
  49. import { addDeviceUser, addDeviceUsers } from '@/api/iot/deviceuser';
  50. export default {
  51. name: 'user-list',
  52. props: {
  53. device: {
  54. type: Array,
  55. default: null,
  56. },
  57. },
  58. watch: {
  59. // 获取到父组件传递的device
  60. device: function (newVal, oldVal) {
  61. this.deviceInfo = newVal;
  62. },
  63. },
  64. data() {
  65. return {
  66. // 遮罩层
  67. loading: false,
  68. // 选中数组
  69. ids: [],
  70. // 弹出层标题
  71. title: '',
  72. // 用户列表
  73. userList: [],
  74. // 选中的用户
  75. user: {},
  76. // 设备信息
  77. deviceInfo: {},
  78. // 是否显示选择用户弹出层
  79. openSelectUser: false,
  80. // 查询参数
  81. queryParams: {
  82. pageNum: 1,
  83. pageSize: 10,
  84. userName: undefined,
  85. phonenumber: undefined,
  86. status: 0,
  87. deptId: undefined,
  88. },
  89. // 表单校验
  90. rules: {
  91. phonenumber: [
  92. {
  93. required: true,
  94. message: this.$t('device.user-list.041943-11'),
  95. trigger: 'blur',
  96. },
  97. {
  98. min: 11,
  99. max: 11,
  100. message: this.$t('device.user-list.041943-12'),
  101. trigger: 'blur',
  102. },
  103. ],
  104. },
  105. };
  106. },
  107. created() {},
  108. methods: {
  109. /** 查询用户列表 */
  110. getList() {
  111. this.loading = true;
  112. listUser(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
  113. this.userList = response.rows;
  114. this.total = response.total;
  115. this.loading = false;
  116. });
  117. },
  118. /** 搜索按钮操作 */
  119. handleQuery() {
  120. this.$refs['queryForm'].validate((valid) => {
  121. if (valid) {
  122. this.queryParams.pageNum = 1;
  123. this.getList();
  124. }
  125. });
  126. },
  127. // 重置查询
  128. resetQuery() {
  129. this.$refs['queryForm'].resetFields();
  130. this.userList = [];
  131. },
  132. //设置单选按钮选中
  133. setRadioSelected(userId) {
  134. for (let i = 0; i < this.userList.length; i++) {
  135. if (this.userList[i].userId == userId) {
  136. this.userList[i].isSelect = true;
  137. this.user = this.userList[i];
  138. } else {
  139. this.userList[i].isSelect = false;
  140. }
  141. }
  142. },
  143. // 单选数据
  144. handleCurrentChange(user) {
  145. if (user != null) {
  146. this.setRadioSelected(user.userId);
  147. this.user = user;
  148. }
  149. },
  150. // 关闭选择用户
  151. closeSelectUser() {
  152. this.openSelectUser = false;
  153. this.resetQuery();
  154. },
  155. // 添加设备用户
  156. addDeviceUser() {
  157. if (this.deviceInfo != null && this.deviceInfo.length > 0 && this.user != null) {
  158. if (this.deviceInfo.length == 1) {
  159. var form = {};
  160. form.deviceId = this.deviceInfo[0].deviceId;
  161. form.deviceName = this.deviceInfo[0].deviceName;
  162. form.userId = this.user.userId;
  163. form.userName = this.user.userName;
  164. form.phonenumber = this.user.phonenumber;
  165. addDeviceUser(form).then((response) => {
  166. this.$modal.msgSuccess(this.$t('device.user-list.041943-13'));
  167. this.resetQuery();
  168. this.openSelectUser = false;
  169. this.$parent.getList();
  170. });
  171. } else {
  172. var form = [];
  173. this.deviceInfo.forEach((device) => {
  174. let data = {};
  175. data.deviceId = device.deviceId;
  176. data.deviceName = device.deviceName;
  177. data.userId = this.user.userId;
  178. data.userName = this.user.userName;
  179. data.phonenumber = this.user.phonenumber;
  180. form.push(data);
  181. });
  182. addDeviceUsers(form).then((response) => {
  183. this.$modal.msgSuccess(this.$t('device.user-list.041943-13'));
  184. this.resetQuery();
  185. this.openSelectUser = false;
  186. this.$parent.getList();
  187. });
  188. }
  189. } else {
  190. this.openSelectUser = false;
  191. }
  192. },
  193. },
  194. };
  195. </script>