index.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--部门数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
  8. </div>
  9. <div class="head-container">
  10. <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree" @node-click="handleNodeClick" />
  11. </div>
  12. </el-col>
  13. <!--用户数据-->
  14. <el-col :span="20" :xs="24">
  15. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  16. <el-form-item label="员工后台昵称" prop="nickName">
  17. <el-input v-model="queryParams.nickName" placeholder="请输入员工后台昵称" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
  18. </el-form-item>
  19. <el-form-item label="手机号码" prop="phonenumber">
  20. <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="员工状态" clearable size="small" style="width: 240px" @change="handleQuery">
  24. <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="企微状态" prop="qwStatus">
  28. <el-select v-model="queryParams.qwStatus" placeholder="企微绑定状态" clearable size="small" style="width: 240px" @change="handleQuery">
  29. <el-option v-for="dict in qwStatusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="创建时间">
  33. <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  37. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  38. </el-form-item>
  39. </el-form>
  40. <el-row :gutter="10" class="mb8">
  41. <el-col :span="1.5">
  42. <el-button plain type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['company:user:add']">新增</el-button>
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button plain type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['company:user:edit']">修改</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button plain type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['company:user:remove']">删除</el-button>
  49. </el-col>
  50. <!-- <el-col :span="1.5">
  51. <el-button plain type="info" icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['company:user:import']">导入</el-button>
  52. </el-col> -->
  53. <el-col :span="1.5">
  54. <el-button plain type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['company:user:export']">导出</el-button>
  55. </el-col>
  56. <el-col :span="1.5">
  57. <el-button
  58. type="primary"
  59. plain
  60. size="mini"
  61. @click="synOpen=true"
  62. v-hasPermi="['qw:user:sync']"
  63. >同步企微员工和部门</el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button
  67. type="primary"
  68. plain
  69. size="mini"
  70. @click="synNameOpen=true"
  71. v-hasPermi="['qw:user:sync']"
  72. >同步企微员工名称</el-button>
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="primary"
  77. plain
  78. size="mini"
  79. :disabled="multiple"
  80. @click="handerCompanyUserAreaList"
  81. >批量设置销售所属区域(原有的暂用)</el-button>
  82. </el-col>
  83. <el-col :span="1.5">
  84. <el-button
  85. type="primary"
  86. plain
  87. size="mini"
  88. :disabled="multiple"
  89. @click="handleSetRegister"
  90. >设置单独注册会员</el-button>
  91. </el-col>
  92. <el-col :span="1.5">
  93. <el-button
  94. type="primary"
  95. plain
  96. size="mini"
  97. :disabled="multiple"
  98. @click="handleAllowedAllRegister"
  99. >允许注册会员开关</el-button>
  100. </el-col>
  101. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  102. </el-row>
  103. <el-table height="500" border v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  104. <el-table-column type="selection" width="50" align="center" />
  105. <el-table-column label="ID" align="center" prop="userId" :show-overflow-tooltip="true" />
  106. <el-table-column label="员工账号" align="center" prop="userName" :show-overflow-tooltip="true" width="100" />
  107. <el-table-column label="员工昵称" align="center" prop="nickName" :show-overflow-tooltip="true" width="100"/>
  108. <el-table-column label="部门" align="center" prop="deptName" :show-overflow-tooltip="true" />
  109. <el-table-column label="手机号码" align="center" prop="phonenumber" width="120" />
  110. <el-table-column label="二维码" align="center" prop="qrCodeWeixin">
  111. <template slot-scope="scope">
  112. <!-- 显示已上传的二维码 -->
  113. <el-image
  114. v-if="scope.row.qrCodeWeixin"
  115. style="width: 80px; height: 80px; margin-bottom: 5px; display: block; margin-left: auto; margin-right: auto;"
  116. :src="scope.row.qrCodeWeixin"
  117. :preview-src-list="[scope.row.qrCodeWeixin]"
  118. fit="contain">
  119. <div slot="error" class="image-slot">
  120. <i class="el-icon-picture-outline"></i>
  121. </div>
  122. </el-image>
  123. <!-- 上传组件 -->
  124. <el-upload
  125. class="avatar-uploader"
  126. action="#"
  127. :show-file-list="false"
  128. :http-request="(options) => handleCustomUpload(options, scope.row)"
  129. :before-upload="(file) => beforeImageUpload(file, scope.row)"
  130. >
  131. <el-button size="small" type="primary" :loading="scope.row.uploading">
  132. {{ scope.row.qrCodeWeixin ? '更换图片' : '上传图片' }}
  133. <i class="el-icon-upload el-icon--right"></i>
  134. </el-button>
  135. </el-upload>
  136. <div v-if="scope.row.uploadError" class="el-upload__tip" style="color: red;">
  137. {{ scope.row.uploadError }}
  138. </div>
  139. </template>
  140. </el-table-column>
  141. <el-table-column label="状态" align="center">
  142. <template slot-scope="scope">
  143. <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="企微状态" align="center">
  147. <template slot-scope="scope">
  148. <dict-tag :options="qwStatusOptions" :value="scope.row.qwStatus"/>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="区域" align="center" prop="addressId">
  152. </el-table-column>
  153. <el-table-column label="是否单独注册会员" align="center" prop="isNeedRegisterMember" width="80px">
  154. <template slot-scope="scope">
  155. <el-tag
  156. :type="scope.row.isNeedRegisterMember === 1 ? 'success' : 'info'">{{scope.row.isNeedRegisterMember === 1 ? '是' : '否' }}</el-tag>
  157. </template>
  158. </el-table-column>
  159. <el-table-column label="创建时间" sortable align="center" prop="createTime" width="160">
  160. <template slot-scope="scope">
  161. <span>{{ parseTime(scope.row.createTime) }}</span>
  162. </template>
  163. </el-table-column>
  164. <el-table-column label="允许注册会员" align="center" prop="isNeedRegisterMember" width="80px">
  165. <template slot-scope="scope">
  166. <el-tag
  167. :type="scope.row.isAllowedAllRegister === 1 ? 'success' : 'info'">{{scope.row.isAllowedAllRegister === 1 ? '是' : '否' }}</el-tag>
  168. </template>
  169. </el-table-column>
  170. <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
  171. <template slot-scope="scope">
  172. <el-button
  173. v-if="scope.row.qwStatus == 0"
  174. size="mini"
  175. type="text"
  176. icon="el-icon-edit"
  177. @click="qwBind(scope.row)"
  178. v-hasPermi="['qw:user:bind']"
  179. >绑定企微</el-button>
  180. <el-button
  181. v-else
  182. size="mini"
  183. type="text"
  184. icon="el-icon-edit"
  185. @click="qwBind(scope.row)"
  186. v-hasPermi="['qw:user:bind']"
  187. >查或换绑企微</el-button>
  188. <el-button v-if="scope.row.userType !== '00'" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['company:user:edit']">修改</el-button>
  189. <!--<el-button v-if="scope.row.userType !== '00'" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['company:user:remove']">删除</el-button>-->
  190. <el-button size="mini" type="text" icon="el-icon-key" @click="handleResetPwd(scope.row)" v-hasPermi="['company:user:resetPwd']">重置密码</el-button>
  191. </template>
  192. </el-table-column>
  193. </el-table>
  194. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  195. </el-col>
  196. </el-row>
  197. <el-dialog title="绑定企微账号" :visible.sync="qwOpen" width="800px" append-to-body >
  198. <el-form ref="form" :model="form" label-width="80px" >
  199. <el-form-item label="查询" prop="companyUserId">
  200. <el-button type="primary" icon="el-icon-search" @click="selectQwUser()" size="mini">搜索账号</el-button>
  201. </el-form-item>
  202. <el-form-item label="企微账号" prop="companyUserId">
  203. <el-tag
  204. style="margin-left: 5px"
  205. size="medium"
  206. :key="id"
  207. v-for="id in qwUser"
  208. closable
  209. :disable-transitions="false"
  210. @close="handleClosegroupUser(id)">
  211. <span v-for="list in qwUserList" :key="list.qwUserId" v-if="list.id==id">{{list.qwUserName}}({{list.corpName}})
  212. </span>
  213. </el-tag>
  214. </el-form-item>
  215. </el-form>
  216. <div slot="footer" class="dialog-footer">
  217. <el-button type="primary" @click="qwSubmitForm">绑 定</el-button>
  218. <el-button @click="qwCancel">取 消</el-button>
  219. </div>
  220. </el-dialog>
  221. <el-dialog title="绑定个微账号" :visible.sync="gwOpen" width="800px" append-to-body>
  222. <el-form ref="gwForm" :model="gwForm" label-width="80px">
  223. <el-form-item label="查询" prop="companyUserId">
  224. <el-button type="primary" icon="el-icon-search" @click="selectGwUser()" size="mini">搜索账号</el-button>
  225. </el-form-item>
  226. <el-form-item label="个微账号" prop="companyUserId">
  227. <el-tag
  228. style="margin-left: 5px"
  229. size="medium"
  230. :key="id"
  231. v-for="id in qwUser"
  232. closable
  233. :disable-transitions="false"
  234. @close="handleClosegroupUser(id)">
  235. <span v-for="list in qwUserList" :key="list.qwUserId" v-if="list.id==id">{{list.qwUserName}}({{list.corpName}})
  236. </span>
  237. </el-tag>
  238. </el-form-item>
  239. </el-form>
  240. </el-dialog>
  241. <el-dialog title="选择企微主体" :visible.sync="synOpen" width="800px" append-to-body>
  242. <el-form label-width="80px">
  243. <el-form-item label="企微公司" prop="corpId">
  244. <el-select v-model="synform.corpId" placeholder="企微公司" >
  245. <el-option
  246. v-for="dict in myQwCompanyList"
  247. :key="dict.dictValue"
  248. :label="dict.dictLabel"
  249. :value="dict.dictValue"
  250. />
  251. </el-select>
  252. </el-form-item>
  253. </el-form>
  254. <div slot="footer" class="dialog-footer">
  255. <el-button type="primary" @click="synSubmitForm">确 定</el-button>
  256. <el-button @click="synOpen=false">取 消</el-button>
  257. </div>
  258. </el-dialog>`
  259. <!-- 添加或修改参数配置对话框 -->
  260. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  261. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  262. <el-row>
  263. <el-col :span="12">
  264. <el-form-item label="员工姓名" prop="nickName">
  265. <el-input v-model="form.nickName" placeholder="请输入员工后台昵称搜索" />
  266. </el-form-item>
  267. </el-col>
  268. <el-col :span="12">
  269. <el-form-item label="归属部门" prop="deptId">
  270. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
  271. </el-form-item>
  272. </el-col>
  273. </el-row>
  274. <el-row>
  275. <el-col :span="12">
  276. <el-form-item label="手机号码" prop="phonenumber">
  277. <el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11" />
  278. </el-form-item>
  279. </el-col>
  280. <el-col :span="12">
  281. <el-form-item label="邮箱" prop="email">
  282. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  283. </el-form-item>
  284. </el-col>
  285. </el-row>
  286. <el-row>
  287. <el-col :span="12">
  288. <el-form-item v-if="form.userId == undefined" label="员工工号" prop="userName">
  289. <el-input v-model="form.userName" placeholder="请输入员工工号" />
  290. </el-form-item>
  291. </el-col>
  292. <el-col :span="12">
  293. <el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
  294. <el-input v-model="form.password" placeholder="请输入用户密码" type="password" />
  295. </el-form-item>
  296. </el-col>
  297. </el-row>
  298. <el-row>
  299. <el-col :span="12">
  300. <el-form-item label="员工性别">
  301. <el-select v-model="form.sex" placeholder="请选择">
  302. <el-option v-for="dict in sexOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
  303. </el-select>
  304. </el-form-item>
  305. </el-col>
  306. <el-col :span="12">
  307. <el-form-item label="状态">
  308. <el-radio-group v-model="form.status">
  309. <el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
  310. </el-radio-group>
  311. </el-form-item>
  312. </el-col>
  313. </el-row>
  314. <el-row>
  315. <el-col :span="12">
  316. <el-form-item label="岗位">
  317. <el-select v-model="form.postIds" multiple placeholder="请选择">
  318. <el-option v-for="item in postOptions" :key="item.postId" :label="item.postName" :value="item.postId" :disabled="item.status == 1"></el-option>
  319. </el-select>
  320. </el-form-item>
  321. </el-col>
  322. <el-col :span="12">
  323. <el-form-item label="角色">
  324. <el-select v-model="form.roleIds" multiple placeholder="请选择">
  325. <el-option v-for="item in roleOptions" :key="item.roleId" :label="item.roleName" :value="item.roleId" :disabled="item.status == 1"></el-option>
  326. </el-select>
  327. </el-form-item>
  328. </el-col>
  329. </el-row>
  330. <el-row>
  331. <el-col :span="12">
  332. <el-form-item label="身份证号">
  333. <el-input v-model="form.idCard" placeholder="请输入身份证号" maxlength="18" />
  334. </el-form-item>
  335. </el-col>
  336. <el-col :span="12">
  337. <el-form-item label="销售区域" prop="addressId">
  338. <el-select v-model="form.addressId" filterable placeholder="请选择所属销售的区域" style="width: 200px;">
  339. <el-option
  340. v-for="item in citysAreaList"
  341. :key="item.cityId"
  342. :label="item.cityName"
  343. :value="item.cityId"
  344. ></el-option>
  345. </el-select>
  346. </el-form-item>
  347. </el-col>
  348. </el-row>
  349. <el-row>
  350. <el-col :span="24">
  351. <el-form-item label="数据权限" prop="userType">
  352. <el-radio-group v-model="form.userType">
  353. <el-radio v-for="dict in userTypeOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
  354. </el-radio-group>
  355. </el-form-item>
  356. </el-col>
  357. </el-row>
  358. <el-row>
  359. <el-col :span="24">
  360. <el-form-item label="备注">
  361. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  362. </el-form-item>
  363. </el-col>
  364. </el-row>
  365. <el-row>
  366. <el-col :span="24">
  367. <el-form-item label="二级域名">
  368. <el-input v-model="form.domain" :disabled="true" type="input" placeholder="请输入域名" style="width: 85%;"></el-input>
  369. <el-button type="primary" @click="generateSubDomain" style="margin-left: 10px;">生成</el-button>
  370. </el-form-item>
  371. </el-col>
  372. </el-row>
  373. </el-form>
  374. <div slot="footer" class="dialog-footer">
  375. <el-button type="primary" @click="submitForm">确 定</el-button>
  376. <el-button @click="cancel">取 消</el-button>
  377. </div>
  378. </el-dialog>
  379. <el-dialog :title="user.title" :visible.sync="user.open" width="800px" append-to-body>
  380. <selectUser ref="selectUser" @bindQwUser="bindQwUser"></selectUser>
  381. </el-dialog>
  382. <el-dialog :title="companyUserArea.title" :visible.sync="companyUserArea.open" width="300px" append-to-body>
  383. <el-select v-model="addressId" filterable placeholder="请选择所属销售的区域" style="width: 200px;">
  384. <el-option
  385. v-for="item in citysAreaList"
  386. :key="item.cityId"
  387. :label="item.cityName"
  388. :value="item.cityId"
  389. ></el-option>
  390. </el-select>
  391. <div slot="footer" style="text-align: center;">
  392. <el-button type="primary" @click="submitFormArea(addressId)">确 定</el-button>
  393. <el-button @click="cancelArea">取 消</el-button>
  394. </div>
  395. </el-dialog>
  396. <!-- 设置单独注册会员弹窗 -->
  397. <el-dialog title="设置单独注册会员" :visible.sync="registerOpen" width="400px" append-to-body>
  398. <el-form ref="registerForm" :model="registerForm" label-width="180px">
  399. <el-form-item label="是否需要开启单独注册">
  400. <el-switch v-model="registerForm.status" active-value="true" inactive-value="false"></el-switch>
  401. </el-form-item>
  402. </el-form>
  403. <div slot="footer" class="dialog-footer">
  404. <el-button type="primary" @click="submitRegisterForm">确 定</el-button>
  405. <el-button @click="registerOpen = false">取 消</el-button>
  406. </div>
  407. </el-dialog>
  408. <!-- 是否允许所有方式注册会员弹窗 -->
  409. <el-dialog title="允许注册会员" :visible.sync="allowedAllRegisterOpen" width="400px" append-to-body>
  410. <el-form ref="registerForm" :model="allowedAllRegisterForm" label-width="180px">
  411. <el-form-item label="是否允许注册会员">
  412. <el-switch v-model="allowedAllRegisterForm.status" active-value="true" inactive-value="false"></el-switch>
  413. </el-form-item>
  414. </el-form>
  415. <div slot="footer" class="dialog-footer">
  416. <el-button type="primary" @click="submitAllowedAllRegisterForm">确 定</el-button>
  417. <el-button @click="allowedAllRegisterOpen = false">取 消</el-button>
  418. </div>
  419. </el-dialog>
  420. </div>
  421. </template>
  422. <script>
  423. import {
  424. qwList,
  425. delUser,
  426. addUser,
  427. getUser,
  428. updateUser,
  429. exportUser,
  430. resetUserPwd,
  431. changeUserStatus,
  432. importTemplate,
  433. generateSubDomain,
  434. getCitysAreaList, updateCompanyUserAreaList,
  435. setIsRegisterMember,
  436. isAllowedAllRegister
  437. } from '@/api/company/companyUser'
  438. import { getToken } from "@/utils/auth";
  439. import { treeselect } from "@/api/company/companyDept";
  440. import Treeselect from "@riophae/vue-treeselect";
  441. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  442. import {bindQwUser, getQwUserList, addQwUser, getQwUser, getQwUserByIds,addQwUserName} from '@/api/qw/user';
  443. import { syncDept } from '@/api/qw/qwDept';
  444. import { getMyQwUserList,getMyQwCompanyList } from "@/api/qw/user";
  445. import selectUser from "@/views/company/components/selectQwUser.vue";
  446. import {listWxUser} from "@/api/wxUser/wxUser";
  447. import GwQueryListDialog from "@/views/company/companyUser/gwQueryListDialog/gwQueryListDialog.vue";
  448. import axios from "axios";
  449. export default {
  450. name: "User",
  451. components: { Treeselect ,selectUser},
  452. data() {
  453. return {
  454. uploadUrl: process.env.VUE_APP_BASE_API+"/company/user/common/uploadOSS",
  455. // 遮罩层
  456. loading: false,
  457. qwUserList:[],
  458. qwUserId:[],
  459. myQwCompanyList:[],
  460. qwUser:[],
  461. user:{
  462. open:false,
  463. title:"搜索企业"
  464. },
  465. // 选中数组
  466. ids: [],
  467. synform:{corpId:null},
  468. synOpen:false,
  469. synNameform:{corpId:null},
  470. synNameOpen:false,
  471. // 非单个禁用
  472. single: true,
  473. // 非多个禁用
  474. multiple: true,
  475. // 显示搜索条件
  476. showSearch: true,
  477. // 总条数
  478. total: 0,
  479. // 用户表格数据
  480. userList: null,
  481. // 弹出层标题
  482. title: "",
  483. // 部门树选项
  484. deptOptions: undefined,
  485. // 是否显示弹出层
  486. open: false,
  487. qwOpen:false,
  488. // 部门名称
  489. deptName: undefined,
  490. // 日期范围
  491. dateRange: [],
  492. // 状态数据字典
  493. statusOptions: [],
  494. // 性别状态字典
  495. sexOptions: [],
  496. // 岗位选项
  497. postOptions: [],
  498. // 角色选项
  499. roleOptions: [],
  500. userTypeOptions:[
  501. { "dictLabel": "临时管理员","dictValue": "02"},
  502. { "dictLabel": "普通用户","dictValue": "01"}
  503. ],
  504. qwForm:{
  505. id:null,
  506. companyUserId:null,
  507. },
  508. companyUserArea:{
  509. open:false,
  510. title:"分配区域",
  511. },
  512. //选择的区域
  513. addressId:null,
  514. citysAreaList:[],
  515. // 表单参数
  516. form: {},
  517. defaultProps: {
  518. children: "children",
  519. label: "label",
  520. },
  521. // 查询参数
  522. queryParams: {
  523. pageNum: 1,
  524. pageSize: 10,
  525. userName: null,
  526. phonenumber: null,
  527. status: null,
  528. deptId: null,
  529. qwStatus:null,
  530. },
  531. qwStatusOptions:[],
  532. // 表单校验
  533. rules: {
  534. userName: [
  535. { required: true, message: "员工工号不能为空", trigger: "blur" },
  536. ],
  537. nickName: [
  538. { required: true, message: "员工姓名不能为空", trigger: "blur" },
  539. ],
  540. deptId: [
  541. { required: true, message: "归属部门不能为空", trigger: "blur" },
  542. ],
  543. addressId: [
  544. { required: true, message: "销售所属区域不能为空", trigger: "blur" },
  545. ],
  546. password: [
  547. { required: true, message: "员工密码不能为空", trigger: "blur" },
  548. {
  549. pattern: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,20}$/,
  550. message: "密码长度为 8-20 位,必须包含字母、数字和特殊字符",
  551. trigger: ["blur", "change"],
  552. }
  553. ],
  554. idCard: [
  555. { required: true, message: "身份证号不能为空", trigger: "blur" },
  556. ],
  557. // email: [
  558. // { required: true, message: "邮箱地址不能为空", trigger: "blur" },
  559. // {
  560. // type: "email",
  561. // message: "'请输入正确的邮箱地址",
  562. // trigger: ["blur", "change"],
  563. // },
  564. // ],
  565. phonenumber: [
  566. { required: true, message: "手机号码不能为空", trigger: "blur" },
  567. {
  568. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  569. message: "请输入正确的手机号码",
  570. trigger: "blur",
  571. },
  572. ],
  573. userType: [
  574. { required: true, message: "数据权限不能为空", trigger: "change" },
  575. ],
  576. domain: [
  577. {
  578. pattern: /^(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))$/,
  579. message: "请输入正确的二级域名",
  580. trigger: "blur",
  581. }
  582. ],
  583. },
  584. registerOpen: false,
  585. registerForm: {
  586. status: false
  587. },
  588. // 是否允许注册会员开关
  589. allowedAllRegisterOpen: false,
  590. allowedAllRegisterForm: {
  591. status: true
  592. },
  593. };
  594. },
  595. watch: {
  596. // 根据名称筛选部门树
  597. deptName(val) {
  598. this.$refs.tree.filter(val);
  599. },
  600. },
  601. created() {
  602. getCitysAreaList().then(res=>{
  603. this.citysAreaList=res.data;
  604. })
  605. this.getList();
  606. this.getTreeselect();
  607. this.getDicts("sys_normal_disable").then((response) => {
  608. this.statusOptions = response.data;
  609. });
  610. this.getDicts("company_user_sex").then((response) => {
  611. this.sexOptions = response.data;
  612. });
  613. this.getConfigKey("sys.user.initPassword").then((response) => {
  614. this.initPassword = response.msg;
  615. });
  616. this.getDicts("sys_qw_user_status").then(response => {
  617. this.qwStatusOptions = response.data;
  618. });
  619. getMyQwCompanyList().then(response => {
  620. this.myQwCompanyList = response.data;
  621. });
  622. },
  623. methods: {
  624. /**
  625. * 上传文件之前的钩子,参数为上传的文件,若返回 false 或者返回 Promise且被 reject,则停止上传。
  626. * @param {File} file - 用户选择的文件对象
  627. * @param {Object} row - 当前行的数据对象
  628. */
  629. beforeImageUpload(file, row) {
  630. // 清除之前的错误信息
  631. this.$set(row, 'uploadError', '');
  632. const isJPG = file.type === 'image/jpeg';
  633. const isPNG = file.type === 'image/png';
  634. const isGIF = file.type === 'image/gif'; // 根据需要添加更多格式
  635. const isValidFormat = isJPG || isPNG || isGIF;
  636. const isLt2M = file.size / 1024 / 1024 < 2; // 限制图片大小为 2MB
  637. if (!isValidFormat) {
  638. const errorMsg = '上传二维码图片只能是 JPG/PNG/GIF 格式!';
  639. this.$message.error(errorMsg);
  640. this.$set(row, 'uploadError', errorMsg); // 在行内显示错误
  641. return false;
  642. }
  643. if (!isLt2M) {
  644. const errorMsg = '上传二维码图片大小不能超过 2MB!';
  645. this.$message.error(errorMsg);
  646. this.$set(row, 'uploadError', errorMsg); // 在行内显示错误
  647. return false;
  648. }
  649. return true; // 校验通过,允许上传
  650. },
  651. /**
  652. * 自定义上传方法
  653. * @param {Object} options - Element UI upload 组件传递的参数,包含 file, onSuccess, onError, onProgress 等
  654. * @param {Object} row - 当前行的数据对象
  655. */
  656. async handleCustomUpload(options, row) {
  657. const file = options.file;
  658. const formData = new FormData();
  659. formData.append('file', file);
  660. formData.append('userId',row.userId)
  661. this.$set(row, 'uploading', true);
  662. this.$set(row, 'uploadError', '');
  663. try {
  664. const response = await axios.post(this.uploadUrl, formData, {
  665. headers: {
  666. 'Content-Type': 'multipart/form-data',
  667. },
  668. onUploadProgress: progressEvent => {
  669. const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
  670. console.log(`上传进度: ${percentCompleted}%`);
  671. }
  672. });
  673. if (response.data && (response.data.url || (response.data.data && response.data.data.url))) {
  674. const imageUrl = response.data.url || response.data.data.url;
  675. this.$set(row, 'qrCodeWeixin', imageUrl); // 更新行数据中的图片URL
  676. this.$message.success('图片上传成功!');
  677. options.onSuccess(response.data, file); // 通知el-upload上传成功 (虽然我们自定义了,但调用一下也无妨)
  678. } else {
  679. const errorMsg = response.data.message || '图片上传失败,服务器未返回有效URL';
  680. this.$message.error(errorMsg);
  681. this.$set(row, 'uploadError', errorMsg);
  682. options.onError(new Error(errorMsg), file); // 通知el-upload上传失败
  683. }
  684. } catch (error) {
  685. console.error('上传失败:', error);
  686. let errorMsg = '图片上传失败';
  687. if (error.response && error.response.data && error.response.data.message) {
  688. errorMsg = error.response.data.message;
  689. } else if (error.message) {
  690. errorMsg = error.message;
  691. }
  692. this.$message.error(errorMsg);
  693. this.$set(row, 'uploadError', errorMsg);
  694. options.onError(error, file); // 通知el-upload上传失败
  695. } finally {
  696. this.$set(row, 'uploading', false); // 无论成功失败,结束上传状态
  697. }
  698. },
  699. requestUpload() {
  700. },
  701. beforeUpload(){
  702. console.log(file.type)
  703. const isPic =
  704. file.type === 'image/jpeg' ||
  705. file.type === 'image/png' ||
  706. file.type === 'image/gif' ||
  707. file.type === 'image/jpg' ||
  708. file.type === 'audio/mpeg'
  709. const isLt2M = file.size / 1024 / 1024 < 2
  710. if (!isPic) {
  711. this.$message.error('上传图片只能是 JPG、JPEG、PNG、GIF 格式!')
  712. return false
  713. }
  714. if (!isLt2M) {
  715. this.$message.error('上传头像图片大小不能超过 2MB!')
  716. }
  717. return isPic && isLt2M
  718. },
  719. submitFormArea(address){
  720. const uIds = this.ids;
  721. if (address == null){
  722. this.$message.error("请选择地区");
  723. return;
  724. }
  725. updateCompanyUserAreaList({userIds:uIds,addressId:address}).then(res=>{
  726. this.companyUserArea.open=false;
  727. this.getList();
  728. this.msgSuccess("操作成功");
  729. })
  730. },
  731. // 绑定个微
  732. gwBind(row){
  733. this.gwOpen = true
  734. },
  735. // 查询个微账号
  736. selectGwUser(){
  737. listWxUser().then(res=>{
  738. this.gwSearchOpen = true;
  739. })
  740. },
  741. /** 查询用户列表 */
  742. getList() {
  743. this.loading = true;
  744. qwList(this.addDateRange(this.queryParams, this.dateRange)).then(
  745. (response) => {
  746. this.userList = response.rows;
  747. this.total = response.total;
  748. this.loading = false;
  749. console.log(" this.userList ", this.userList )
  750. }
  751. );
  752. },
  753. selectQwUser(){
  754. this.user.open=true;
  755. },
  756. handleClosegroupUser(list){
  757. const index = this.qwUser.findIndex(t => t === list);
  758. if (index !== -1) {
  759. this.qwUser.splice(index, 1);
  760. }
  761. },
  762. /** 查询部门下拉树结构 */
  763. getTreeselect() {
  764. treeselect().then((response) => {
  765. this.deptOptions = response.data;
  766. });
  767. },
  768. // 筛选节点
  769. filterNode(value, data) {
  770. if (!value) return true;
  771. return data.label.indexOf(value) !== -1;
  772. },
  773. // 节点单击事件
  774. handleNodeClick(data) {
  775. this.queryParams.deptId = data.id;
  776. this.getList();
  777. },
  778. // 用户状态修改
  779. handleStatusChange(row) {
  780. let text = row.status === "0" ? "启用" : "停用";
  781. this.$confirm(
  782. '确认要"' + text + '""' + row.userName + '"用户吗?',
  783. "警告",
  784. {
  785. confirmButtonText: "确定",
  786. cancelButtonText: "取消",
  787. type: "warning",
  788. }
  789. )
  790. .then(function () {
  791. return changeUserStatus(row.userId, row.status);
  792. })
  793. .then(() => {
  794. this.msgSuccess(text + "成功");
  795. })
  796. .catch(function () {
  797. row.status = row.status === "0" ? "1" : "0";
  798. });
  799. },
  800. // 取消按钮
  801. cancel() {
  802. this.open = false;
  803. this.reset();
  804. },
  805. cancelArea(){
  806. this.companyUserArea.open=false;
  807. this.addressId=null;
  808. },
  809. qwCancel() {
  810. this.qwOpen = false;
  811. this.qwUserId=null;
  812. },
  813. handerCompanyUserAreaList(){
  814. this.companyUserArea.open=true;
  815. },
  816. // 表单重置
  817. reset() {
  818. this.form = {
  819. userId: undefined,
  820. deptId: undefined,
  821. userName: undefined,
  822. nickName: undefined,
  823. password: undefined,
  824. idCard: undefined,
  825. phonenumber: undefined,
  826. email: undefined,
  827. sex: undefined,
  828. status: "0",
  829. remark: undefined,
  830. domain: undefined,
  831. postIds: [],
  832. roleIds: [],
  833. };
  834. this.resetForm("form");
  835. },
  836. /** 搜索按钮操作 */
  837. handleQuery() {
  838. this.queryParams.page = 1;
  839. this.getList();
  840. },
  841. /** 重置按钮操作 */
  842. resetQuery() {
  843. this.dateRange = [];
  844. this.resetForm("queryForm");
  845. this.handleQuery();
  846. },
  847. // 多选框选中数据
  848. handleSelectionChange(selection) {
  849. this.ids = selection.map((item) => item.userId);
  850. this.single = selection.length != 1;
  851. this.multiple = !selection.length;
  852. },
  853. /** 新增按钮操作 */
  854. handleAdd() {
  855. this.reset();
  856. this.getTreeselect();
  857. getUser().then((response) => {
  858. this.postOptions = response.posts;
  859. this.roleOptions = response.roles;
  860. this.open = true;
  861. this.title = "添加员工";
  862. this.form.password = null;
  863. this.form.userType = "01"; //普通用户
  864. });
  865. },
  866. qwBind(row){
  867. this.qwUser=[];
  868. this.qwUserList=[];
  869. this.qwForm.companyUserId=row.userId
  870. getUser(row.userId).then((response) => {
  871. if(response.data.qwUserId!=null){
  872. this.qwUser=((response.data.qwUserId).split(",").map(Number))
  873. getQwUserByIds(this.qwUser).then(res => {
  874. this.qwUserList=res.data;
  875. })
  876. // this.qwUser.forEach(item => {
  877. // getQwUser(item).then(response => {
  878. // this.qwUserList.push(response.data);
  879. // });
  880. // });
  881. }
  882. this.qwOpen = true;
  883. });
  884. },
  885. bindQwUser(row){
  886. this.user.open=false;
  887. if (!this.qwUserList.some(item => item.id == row.id)) {
  888. this.qwUserList.push(row)
  889. }
  890. if (!this.qwUser.some(item => item == row.id)) {
  891. this.qwUser.push(row.id);
  892. }
  893. },
  894. /** 修改按钮操作 */
  895. handleUpdate(row) {
  896. this.reset();
  897. this.getTreeselect();
  898. const userId = row.userId || this.ids;
  899. getUser(userId).then((response) => {
  900. this.form = response.data;
  901. this.postOptions = response.posts;
  902. this.roleOptions = response.roles;
  903. this.form.postIds = response.postIds;
  904. this.form.roleIds = response.roleIds;
  905. this.open = true;
  906. this.title = "修改员工";
  907. this.form.password = "";
  908. });
  909. },
  910. /** 重置密码按钮操作 */
  911. handleResetPwd(row) {
  912. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  913. confirmButtonText: "确定",
  914. cancelButtonText: "取消",
  915. inputPlaceholder: "8-20 位,包含字母、数字和特殊字符",
  916. inputValidator: (value) => {
  917. const pattern = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,20}/;
  918. const hasChinese = /[\u4e00-\u9fa5]/.test(value);
  919. const hasFullWidth = /[!-~]/.test(value);
  920. if (hasChinese) return '不能包含中文字符';
  921. if (hasFullWidth) return '不能包含全角符号,请使用英文输入法';
  922. if (!pattern.test(value)) return '密码格式错误:需包含字母、数字和英文特殊字符,长度为 8-20 位';
  923. return true;
  924. }
  925. })
  926. .then(({ value }) => {
  927. resetUserPwd(row.userId, value).then((response) => {
  928. if (response.code === 200) {
  929. this.msgSuccess("修改成功,新密码是:" + value);
  930. }
  931. });
  932. })
  933. .catch(() => {});
  934. },
  935. /** 提交按钮 */
  936. submitForm: function () {
  937. this.$refs["form"].validate((valid) => {
  938. if (valid) {
  939. if (this.form.userId != undefined) {
  940. updateUser(this.form).then((response) => {
  941. if (response.code === 200) {
  942. this.msgSuccess("修改成功");
  943. this.open = false;
  944. this.getList();
  945. }
  946. });
  947. } else {
  948. addUser(this.form).then((response) => {
  949. if (response.code === 200) {
  950. this.msgSuccess("新增成功");
  951. this.open = false;
  952. this.getList();
  953. }
  954. });
  955. }
  956. }
  957. });
  958. },
  959. /**
  960. * 同步企业微信员工
  961. */
  962. synSubmitForm() {
  963. this.synOpen=false;
  964. this.loading=true;
  965. this.msgSuccess("");
  966. let loadingRock = this.$loading({
  967. lock: true,
  968. text: '同步中.....请等待.....请不要重复点击!!',
  969. spinner: 'el-icon-loading',
  970. background: 'rgba(0, 0, 0, 0.7)'
  971. });
  972. addQwUser(this.synform.corpId).then(response => {
  973. this.msgSuccess("同步成功");
  974. this.getList();
  975. this.synOpen=false;
  976. }).finally(()=>{
  977. this.loading=false;
  978. this.synOpen=false;
  979. loadingRock.close();
  980. });
  981. },
  982. synNameSubmitForm() {
  983. this.synNameOpen=false;
  984. this.loading=true;
  985. this.msgSuccess("");
  986. let loadingRock = this.$loading({
  987. lock: true,
  988. text: '同步中.....请等待.....请不要重复点击!!',
  989. spinner: 'el-icon-loading',
  990. background: 'rgba(0, 0, 0, 0.7)'
  991. });
  992. addQwUserName(this.synNameform.corpId).then(response => {
  993. this.msgSuccess("同步成功");
  994. this.getList();
  995. this.synNameOpen=false;
  996. }).finally(()=>{
  997. this.loading=false;
  998. this.synNameOpen=false;
  999. loadingRock.close();
  1000. });
  1001. },
  1002. /**
  1003. * 同步企业微信部门
  1004. */
  1005. qwSyncDept(){
  1006. syncDept().then(response => {
  1007. this.msgSuccess("同步成功");
  1008. this.getList();
  1009. }).catch(()=>{
  1010. this.msgError("同步失败:"+response.msg);
  1011. })
  1012. },
  1013. qwSubmitForm(){
  1014. let loadingRock = this.$loading({
  1015. lock: true,
  1016. text: '绑定中.....同步客户信息中.....',
  1017. spinner: 'el-icon-loading',
  1018. background: 'rgba(0, 0, 0, 0.7)'
  1019. });
  1020. this.qwForm.id = (this.qwUser).join(',');
  1021. bindQwUser(this.qwForm).then(response => {
  1022. this.msgSuccess("绑定成功");
  1023. this.qwOpen = false;
  1024. this.getList();
  1025. this.qwUserId=null;
  1026. this.qwUser=[];
  1027. }).finally(res=>{
  1028. loadingRock.close()
  1029. });
  1030. },
  1031. /** 删除按钮操作 */
  1032. handleDelete(row) {
  1033. const userIds = row.userId || this.ids;
  1034. this.$confirm(
  1035. '是否确认删除员工编号为"' + userIds + '"的数据项?',
  1036. "警告",
  1037. {
  1038. confirmButtonText: "确定",
  1039. cancelButtonText: "取消",
  1040. type: "warning",
  1041. }
  1042. )
  1043. .then(function () {
  1044. return delUser(userIds);
  1045. })
  1046. .then(() => {
  1047. this.getList();
  1048. this.msgSuccess("删除成功");
  1049. })
  1050. .catch(function () {});
  1051. },
  1052. /** 导出按钮操作 */
  1053. handleExport() {
  1054. const queryParams = this.queryParams;
  1055. this.$confirm("是否确认导出所有用户数据项?", "警告", {
  1056. confirmButtonText: "确定",
  1057. cancelButtonText: "取消",
  1058. type: "warning",
  1059. })
  1060. .then(function () {
  1061. return exportUser(queryParams);
  1062. })
  1063. .then((response) => {
  1064. this.download(response.msg);
  1065. })
  1066. .catch(function () {});
  1067. },
  1068. // /** 导入按钮操作 */
  1069. // handleImport() {
  1070. // this.upload.title = "用户导入";
  1071. // this.upload.open = true;
  1072. // },
  1073. /** 下载模板操作 */
  1074. importTemplate() {
  1075. importTemplate().then((response) => {
  1076. this.download(response.msg);
  1077. });
  1078. },
  1079. // 文件上传中处理
  1080. handleFileUploadProgress(event, file, fileList) {
  1081. this.upload.isUploading = true;
  1082. },
  1083. // 文件上传成功处理
  1084. handleFileSuccess(response, file, fileList) {
  1085. this.upload.open = false;
  1086. this.upload.isUploading = false;
  1087. this.$refs.upload.clearFiles();
  1088. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  1089. this.getList();
  1090. },
  1091. // 提交上传文件
  1092. submitFileForm() {
  1093. this.$refs.upload.submit();
  1094. },
  1095. // 生成子域名
  1096. generateSubDomain() {
  1097. generateSubDomain().then(response => {
  1098. this.form.domain = response.data;
  1099. });
  1100. },
  1101. /** 设置单独注册会员按钮操作 */
  1102. handleSetRegister() {
  1103. this.registerOpen = true;
  1104. this.registerForm.status = false;
  1105. },
  1106. /** 提交设置单独注册会员 */
  1107. submitRegisterForm() {
  1108. setIsRegisterMember({status: this.registerForm.status}, this.ids).then(response => {
  1109. if (response.code === 200) {
  1110. this.msgSuccess("设置成功");
  1111. this.registerOpen = false;
  1112. this.getList();
  1113. }
  1114. });
  1115. },
  1116. /** 开关是否允许所有方式注册会员 */
  1117. handleAllowedAllRegister() {
  1118. this.allowedAllRegisterOpen = true;
  1119. // this.allowedAllRegisterForm.status = true;
  1120. },
  1121. // 提交
  1122. submitAllowedAllRegisterForm(){
  1123. isAllowedAllRegister({status: this.allowedAllRegisterForm.status}, this.ids).then(response => {
  1124. if (response.code === 200) {
  1125. this.msgSuccess("操作成功");
  1126. this.allowedAllRegisterOpen = false;
  1127. this.getList();
  1128. }
  1129. });
  1130. },
  1131. },
  1132. };
  1133. </script>