log.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="all-box">
  3. <div class="all" style="padding: 40px;">
  4. <div style="margin-bottom: 30px;">
  5. <div class="initia_title">工作日志积分</div>
  6. <div class="initia_title_1">
  7. 1、启用后,在钉钉发布工作日志,系统自动按“日志积分规则”奖分
  8. <br />
  9. 2、日志名称必须与“钉钉日志模板名称”一致,否则奖分不会生效
  10. <br />
  11. 3、日志支持每月、每周、每次汇报,可自行根据需要设置“日志积分规则
  12. </div>
  13. <div class="flex-box-end" style="margin-top: 20px;">
  14. <el-button v-if="$authoritys() != 'dept_manager' && $authoritys() != 'employee'" type="primary" @click="isShowLog = true">刷新汇报记录</el-button>
  15. <el-button size="small" plain @click="add()">添加日志模板</el-button>
  16. </div>
  17. </div>
  18. <el-table ref="multipleTable" :data="list" tooltip-effect="dark" align="center" v-loading="loading">
  19. <el-table-column label="序号" align="left" type="index"></el-table-column>
  20. <el-table-column label="日志名称" prop="name"></el-table-column>
  21. <el-table-column label="日志积分规则">
  22. <template slot-scope="scope">
  23. <span>{{ getMoney(scope.row.interval) }}汇报,每次奖{{ scope.row.config.point }} B分</span>
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="状态">
  27. <template slot-scope="scope">
  28. <span v-if="scope.row.enable == 0" class="yellow">已禁用</span>
  29. <span v-else class="green">已启用</span>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="操作">
  33. <template slot-scope="scope">
  34. <div class="flex-box-ce">
  35. <div @click.stop="openSet(scope.row)" style="margin-right: 10px;"><span class="lookQrcode">编辑</span></div>
  36. <div @click.stop="deleteSet(scope.row)"><span class="lookQrcode red">删除</span></div>
  37. </div>
  38. </template>
  39. </el-table-column>
  40. <template slot="empty">
  41. <noData :isSolt="true">
  42. <div>
  43. 您当前没有日志模板,去添加
  44. <span style="cursor: pointer;margin-left: 10px;" @click="add()" class="blue">添加</span>
  45. </div>
  46. </noData>
  47. </template>
  48. </el-table>
  49. </div>
  50. <el-dialog title="设置" :visible.sync="dialogVisible" top="25vh" width="520px" class="dialog">
  51. <el-alert class="el-dialog__body" title="日志名称必须与钉钉日志模板名称一致,否则设置无效,不会产生积分" type="warning" :closable="false" show-icon></el-alert>
  52. <el-form label-width="110px" :model="selectItem" ref="setForm" class="form">
  53. <el-form-item style="margin-bottom: 0px;" label="日志名称">
  54. <div class="flex-box flex-v-ce">
  55. <el-input v-if="isAdd" style="width: 200px;" v-model="selectItem.name" placeholder="请输入日志名称"></el-input>
  56. <template v-else>
  57. <div class="font-flex-word name">{{ selectItem.name }}</div>
  58. <div class="blue" @click="showName(selectItem.name)">修改</div>
  59. </template>
  60. </div>
  61. <el-dialog title="设置名称" :visible.sync="isShowName" top="25vh" width="520px" append-to-body>
  62. <div style="text-align: center;">
  63. <el-alert
  64. class="el-dialog__body"
  65. title="日志名称必须与钉钉日志模板名称一致,否则设置无效,不会产生积分"
  66. type="warning"
  67. :closable="false"
  68. show-icon
  69. ></el-alert>
  70. <el-input style="width: 200px;" v-model="nameVal" placeholder="请输入日志名称"></el-input>
  71. <div class="flex-box-end" style="margin-top: 20px;">
  72. <el-button @click="isShowName = false">取消</el-button>
  73. <el-button type="primary" @click="submitName()">确定</el-button>
  74. </div>
  75. </div>
  76. </el-dialog>
  77. </el-form-item>
  78. <el-form-item style="margin-bottom: 10px;" label="是否启用"><el-switch v-model="selectItem.enable"></el-switch></el-form-item>
  79. <template v-if="selectItem.enable">
  80. <div style="margin-top: 20px;"></div>
  81. <div class="title">日志积分规则</div>
  82. <el-form-item label="日志汇报要求" prop="interval" :rules="[{ required: true, message: '请选择汇报要求' }]">
  83. <el-select class="widthInput" v-model="selectItem.interval" placeholder="请选择">
  84. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  85. </el-select>
  86. </el-form-item>
  87. <el-form-item label="每次汇报奖励" :rules="[{ required: true, message: '请输入分值', trigger: 'change' }]" prop="config.point">
  88. <el-input
  89. class="widthInput"
  90. placeholder="请输入(1~999)"
  91. @input="checkCountry($event, 'input1')"
  92. id="input1"
  93. v-model.number="selectItem.config.point"
  94. ></el-input>
  95. <span style="margin-left: 5px;">B分</span>
  96. </el-form-item>
  97. <el-form-item label="汇报提交超过" prop="config.upper_limit" :rules="[{ required: true, message: '请输入次数' }]">
  98. <el-input
  99. class="widthInput"
  100. placeholder="请输入(1~999)"
  101. @input="checkCountry($event, 'input2')"
  102. id="input2"
  103. v-model.number="selectItem.config.upper_limit"
  104. ></el-input>
  105. <span style="margin-left: 5px;">次,不再奖励积分</span>
  106. </el-form-item>
  107. </template>
  108. <el-form-item style="text-align: right; margin-bottom: 0">
  109. <el-button @click="dialogVisible = false">取消</el-button>
  110. <el-button type="primary" :loading="setLoading" :disabled="setLoading" @click="submit('setForm')">确定</el-button>
  111. </el-form-item>
  112. </el-form>
  113. </el-dialog>
  114. <el-dialog title="刷新日志记录" :visible.sync="isShowLog" top="25vh" width="520px" class="dialog" :close-on-click-modal="false" :close-on-press-escape="false">
  115. <el-form :model="logData" ref="setForm2" label-width="110px">
  116. <el-form-item label="日志汇报要求" prop="type" :rules="[{ required: true, message: '请选择汇报要求' }]">
  117. <el-select class="widthInput" v-model="logData.type" placeholder="请选择" style="width: 250px;">
  118. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  119. </el-select>
  120. </el-form-item>
  121. <el-form-item label="选择日期" prop="target_date" :rules="[{ required: true, message: '请选择汇报要求' }]">
  122. <el-date-picker :picker-options="pickerOptions" v-model="logData.target_date" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 250px;"></el-date-picker>
  123. </el-form-item>
  124. </el-form>
  125. <span slot="footer" class="dialog-footer">
  126. <el-button @click="isShowLog = false">取 消</el-button>
  127. <el-button type="primary" @click="refresh('setForm2')">确 定</el-button>
  128. </span>
  129. </el-dialog>
  130. </div>
  131. </template>
  132. <script>
  133. import noData from '@/components/noData';
  134. export default {
  135. components: { noData },
  136. data() {
  137. return {
  138. loading: false,
  139. setLoading: false,
  140. ding_enable: true,
  141. list: [],
  142. dialogVisible: false,
  143. pickerOptions: {
  144. disabledDate(time) {
  145. return time.getTime() > Date.now() - 8.64e7;
  146. }
  147. },
  148. selectItem: {
  149. config: { point: 0, upper_limit: 0 },
  150. enable: true,
  151. id: '',
  152. interval: 1,
  153. name: '',
  154. site_id: '',
  155. type: ''
  156. },
  157. options: [
  158. {
  159. value: 1,
  160. label: '每日'
  161. },
  162. {
  163. value: 2,
  164. label: '每周'
  165. },
  166. {
  167. value: 3,
  168. label: '每月'
  169. }
  170. ],
  171. isShowName: false,
  172. nameVal: '',
  173. // 添加模板
  174. isAdd: false,
  175. isShowLog: false,
  176. logData: {
  177. type: 1,
  178. target_date: ''
  179. }
  180. };
  181. },
  182. watch: {
  183. dialogVisible(val) {
  184. if (!val) {
  185. this.isAdd = false;
  186. this.selectItem = {
  187. config: { point: 0, upper_limit: 0 },
  188. enable: true,
  189. id: '',
  190. interval: 1,
  191. name: '',
  192. site_id: '',
  193. type: ''
  194. };
  195. }
  196. }
  197. },
  198. mounted() {
  199. this.getList();
  200. },
  201. methods: {
  202. refresh(fromName) {
  203. this.$refs[fromName].validate(valid => {
  204. if (valid) {
  205. let type='';
  206. if(this.logData.type==1){
  207. type='daily'
  208. }else if(this.logData.type==2){
  209. type='weekly'
  210. }else{
  211. type='monthly'
  212. }
  213. let data = {
  214. type: type,
  215. employee_id: this.$getUserData().id,
  216. target_date: this.logData.target_date
  217. };
  218. this.$axios('post', '/api/ding/report_sync', data)
  219. .then(res => {
  220. this.$message.success('已刷新');
  221. })
  222. .finally(() => {
  223. this.logData={
  224. type: 1,
  225. target_date: ''
  226. };
  227. this.isShowLog = false;
  228. });
  229. }
  230. });
  231. },
  232. deleteSet(e) {
  233. this.$confirm('确定要删除该日志模板吗?', '提示', {
  234. confirmButtonText: '确定',
  235. cancelButtonText: '取消',
  236. type: 'warning'
  237. }).then(() => {
  238. this.$axios('DELETE', '/api/integral/report/templates', { id: e.id }).then(res => {
  239. if (res.data.code == 1) {
  240. this.$message.success('删除成功');
  241. this.getList();
  242. }
  243. });
  244. });
  245. },
  246. add() {
  247. if (this.list.length == 20) {
  248. this.$message.warning('日志模板最多有20个');
  249. return false;
  250. }
  251. this.isAdd = true;
  252. this.dialogVisible = true;
  253. },
  254. // 最大值不能大于100
  255. checkCountry(e, id) {
  256. //解决v-model与oninput同时使用失效问题
  257. var dom = document.getElementById(id);
  258. var value = dom.value;
  259. //写你自己的输入规则
  260. value = value.replace(/[^\d]/g, '');
  261. if (value > 999) {
  262. id == 'input1' ? (this.selectItem.config.point = '') : (this.selectItem.config.upper_limit = '');
  263. this.$message.warning('不能大于999');
  264. return false;
  265. }
  266. dom.value = value; //输入框赋值
  267. id == 'input1' ? (this.selectItem.config.point = dom.value) : (this.selectItem.config.upper_limit = dom.value);
  268. },
  269. submitName() {
  270. if (!this.nameVal || this.nameVal == null || this.nameVal == undefined) {
  271. this.$message.error('请输入日志名称');
  272. return;
  273. }
  274. this.selectItem.name = this.nameVal;
  275. this.isShowName = false;
  276. },
  277. showName(name) {
  278. this.nameVal = name;
  279. this.isShowName = true;
  280. },
  281. submit(fromName) {
  282. if (this.isAdd) {
  283. if (!this.selectItem.name) {
  284. this.$message.error('请输入日志名称');
  285. return false;
  286. }
  287. }
  288. if (this.selectItem.enable) {
  289. if (this.selectItem.config.point == 0) {
  290. this.$message.error('汇报奖励不能为0');
  291. return false;
  292. }
  293. if (this.selectItem.config.upper_limit == 0) {
  294. this.$message.error('提交超过次数不能为0');
  295. return false;
  296. }
  297. }
  298. this.$refs[fromName].validate(valid => {
  299. if (valid) {
  300. this.setLoading = true;
  301. let jsonItem = JSON.stringify(this.selectItem);
  302. let data = JSON.parse(jsonItem);
  303. data.enable = data.enable ? 1 : 0;
  304. data.point = data.config.point;
  305. data.upper_limit = data.config.upper_limit;
  306. if (this.isAdd) {
  307. data.type = 'other';
  308. }
  309. this.$axios('post', '/api/integral/report/templates', data)
  310. .then(res => {
  311. if (res.data.code == 1) {
  312. this.$message.success(res.data.msg);
  313. this.getList();
  314. this.dialogVisible = false;
  315. }
  316. })
  317. .finally(() => {
  318. this.setLoading = false;
  319. });
  320. }
  321. });
  322. },
  323. openSet(item) {
  324. console.log(item);
  325. var jsonItem = JSON.stringify(item);
  326. this.selectItem = JSON.parse(jsonItem);
  327. this.selectItem.enable = this.selectItem.enable == 0 ? false : true;
  328. this.dialogVisible = true;
  329. },
  330. getMoney: function(index) {
  331. var str; //1-每日 2-每周 3-每月
  332. switch (index) {
  333. case 1:
  334. str = '每日';
  335. break;
  336. case 2:
  337. str = '每周';
  338. break;
  339. case 3:
  340. str = '每月';
  341. break;
  342. }
  343. return str;
  344. },
  345. getList() {
  346. this.loading = true;
  347. this.$axios('get', '/api/integral/report/templates/list')
  348. .then(res => {
  349. this.list = res.data.data.list;
  350. })
  351. .finally(err => {
  352. this.loading = false;
  353. });
  354. }
  355. }
  356. };
  357. </script>
  358. <style scoped lang="scss">
  359. .el-dialog__body {
  360. position: relative;
  361. top: -20px;
  362. }
  363. .widthInput {
  364. width: 150px;
  365. }
  366. .title {
  367. margin: 10px 0;
  368. margin-top: 0;
  369. font-size: 14px;
  370. font-weight: 700;
  371. padding-left: 13px;
  372. }
  373. .initia_title {
  374. font-size: 20px;
  375. color: rgba(48, 49, 51, 1);
  376. font-family: PingFangSC-Regular;
  377. }
  378. .initia_title_1 {
  379. color: #e6a23c;
  380. font-size: 14px;
  381. margin-top: 10px;
  382. }
  383. .lookQrcode {
  384. color: #606266;
  385. cursor: pointer;
  386. transition: all 0.3s;
  387. font-weight: 700;
  388. }
  389. .lookQrcode:hover {
  390. color: #2490fd;
  391. }
  392. .name {
  393. max-width: 200px;
  394. margin-right: 10px;
  395. }
  396. </style>