honor.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <view class="content">
  3. <view>
  4. <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#1c9bdc"></uni-segmented-control>
  5. <view class="content">
  6. <view v-show="current == 0">
  7. <view class="active-title-box">
  8. <!--<uni-datetime-picker
  9. class="time-select-box"
  10. type="date"
  11. :value="single"
  12. @change="change"
  13. :clear-icon="false"
  14. /> -->
  15. <picker mode="date" fields="year" @change="bindDateChange" class="picker-class">
  16. <view class="uni-input display-between items-center">{{dateYear}}年<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  17. </picker>
  18. <picker :range="arrayMonth" :value="dateMonth" @change="bindDateMonthChange" class="picker-class" style="margin-left: 2%;">
  19. <view class="uni-input display-between items-center" style="color: #707070;">{{dateMonth}}月<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  20. </picker>
  21. <picker @change="bindPickerChange" :value="index" :range="array">
  22. <view class="uni-input">{{array[index]}}</view>
  23. <image src="/static/arrow_down.svg" mode="aspectFit"></image>
  24. </picker>
  25. <button @click="goRecord()">+获奖记录</button>
  26. </view>
  27. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
  28. <view class="honor-box" v-for="(item,index) in honorList" :key="index" style="position: relative;">
  29. <view class="honor-name">{{item.name}}</view>
  30. <image :src="item.pic_url_resize" mode="aspectFill" @click="showLarge(item.pic_url)"></image>
  31. <view style="display: flex;">
  32. <view class="honor-award" style="width:120rpx;">获奖人:</view>
  33. <view class="honor-award">{{item.for_branch}} {{item.for_names}}</view>
  34. </view>
  35. <view class="honor-info-box">
  36. <text>{{item.year}}年{{item.month}}月</text>
  37. <text>|</text>
  38. <text>{{item.level_str}}</text>
  39. <text>|</text>
  40. <text>{{item.from_str}}</text>
  41. <text>|</text>
  42. <text>{{item.for_str}}</text>
  43. </view>
  44. <view class="edit-icon-box">
  45. <image src="/static/edit-icon.png" mode="aspectFit" v-show="item.edit_auth" @click="goRecord(item.id)"></image>
  46. <image src="/static/del-icon.png" mode="aspectFit" v-show="item.del_auth" @click="delRecord(item.id)"></image>
  47. </view>
  48. </view>
  49. </mescroll-body>
  50. <!-- <view v-if="!honorList.length" class="no-data-box">
  51. <image src="/static/nodata.svg" mode="aspectFit" style="width: 300rpx;height: 300rpx;"></image>
  52. </view> -->
  53. </view>
  54. <view v-if="current == 1">
  55. <view class="active-title-box">
  56. <picker mode="date" fields="year" @change="bindDateChangeSelf" class="picker-class">
  57. <view class="uni-input display-between items-center">{{dateYearSelf}}年<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  58. </picker>
  59. <picker :range="arrayMonth" :value="dateMonthSelf" @change="bindDateMonthChangeSelf" class="picker-class" style="margin-left: 2%;">
  60. <view class="uni-input display-between items-center" style="color: #707070;">{{dateMonthSelf}}月<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  61. </picker>
  62. <!-- <picker @change="bindPickerChangeSelf" :value="indexSelf" :range="arraySelf">
  63. <view class="uni-input">{{arraySelf[index]}}</view>
  64. <image src="/static/arrow_down.svg" mode="aspectFit"></image>
  65. </picker> -->
  66. <button @click="goRecord()" style="margin-left: 20%;">+获奖记录</button>
  67. </view>
  68. <view class="honor-box" v-for="(item,index) in myHonorList" :key="index" style="position: relative;">
  69. <view class="honor-name">{{item.name}}</view>
  70. <image :src="item.pic_url_resize" mode="aspectFill" @click="showLarge(item.pic_url)"></image>
  71. <view style="display: flex;">
  72. <view class="honor-award" style="width:120rpx;">获奖人:</view>
  73. <view class="honor-award">{{item.for_branch}} {{item.for_names}}</view>
  74. </view>
  75. <view class="honor-info-box">
  76. <text>{{item.year}}年{{item.month}}月</text>
  77. <text>|</text>
  78. <text>{{item.level_str}}</text>
  79. <text>|</text>
  80. <text>{{item.from_str}}</text>
  81. <text>|</text>
  82. <text>{{item.for_str}}</text>
  83. </view>
  84. <view class="edit-icon-box">
  85. <image src="/static/edit-icon.png" mode="aspectFit" v-show="item.edit_auth" @click="goRecord(item.id)"></image>
  86. <image src="/static/del-icon.png" mode="aspectFit" v-show="item.del_auth" @click="delRecord(item.id)"></image>
  87. </view>
  88. </view>
  89. <!-- <view v-if="!honorList.length" class="no-data-box">
  90. <image src="/static/nodata.svg" mode="aspectFit" style="width: 300rpx;height: 300rpx;"></image>
  91. </view> -->
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import md5 from "@/common/md5.js";
  99. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  100. export default {
  101. mixins: [MescrollMixin], // 使用mixin
  102. data() {
  103. return {
  104. id: "",
  105. details: "",
  106. items:['支部/组织荣誉','我的荣誉'],
  107. current:0,
  108. shareUrl:getApp().globalData.shareUrl,
  109. array:['全部','中央','省级','市级','区级','单位'],
  110. index:0,
  111. indexSelf:0,
  112. dateYear:new Date().getFullYear(),
  113. dateMonth:new Date().getMonth() + 1,
  114. dateYearSelf:new Date().getFullYear(),
  115. dateMonthSelf:new Date().getMonth() + 1,
  116. arraySelf:['全部','中央','省级','市级','区级','单位'],
  117. arrayMonth:["1", "2","3", "4","5", "6","7", "8","9", "10","11", "12"],
  118. imageList: [],
  119. time: "",
  120. globalUrl:getApp().globalData.shareUrl,
  121. honorList:[],
  122. myHonorList:[],
  123. page:1,
  124. pageSize:10,
  125. };
  126. },
  127. onLoad() {
  128. // this.getHonorList(this.dateYear,this.dateMonth,this.index)
  129. },
  130. onShow(){
  131. //this.getHonorList(this.dateYear,this.dateMonth,this.index)
  132. },
  133. methods: {
  134. pageRefreshHonor(object) {
  135. if (object === 'add') {
  136. if(this.current){
  137. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf)
  138. }else {
  139. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  140. }
  141. }else if (object === 'edit'){
  142. if(this.current){
  143. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf)
  144. }else {
  145. return
  146. //this.getHonorList(this.dateYear,this.dateMonth,this.index)
  147. }
  148. }
  149. else {
  150. return
  151. }
  152. },
  153. onClickItem(e){
  154. this.current = e.currentIndex
  155. this.current ?
  156. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf) :
  157. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  158. },
  159. bindDateChange(e){
  160. this.dateYear = e.target.value;
  161. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  162. },
  163. bindDateMonthChange(e){
  164. this.dateMonth = this.arrayMonth[e.target.value];
  165. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  166. },
  167. bindPickerChange(e){
  168. this.index = e.detail.value
  169. this.getHonorList(this.dateYear,this.dateMonth,e.detail.value)
  170. },
  171. bindDateChangeSelf(e){
  172. this.dateYearSelf = e.target.value;
  173. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf,this.indexSelf)
  174. },
  175. bindDateMonthChangeSelf(e){
  176. this.dateMonthSelf = this.arrayMonth[e.target.value];
  177. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf,this.indexSelf)
  178. },
  179. // bindPickerChangeSelf(e){
  180. // this.indexSelf = e.detail.value
  181. // this.getMyHonor(this.dateYearSelf,this.dateMonthSelf,e.detail.value)
  182. // },
  183. upCallback(page) {
  184. let pageNum = page.num; // 页码, 默认从1开始
  185. let pageSize = page.size; // 页长, 默认每页10条
  186. let md5Sign = md5(
  187. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  188. "&secret=" + getApp().globalData.secret
  189. );
  190. let url = getApp().globalData.shareUrl +"api/api.php" +
  191. "?method=glory&action=list&timestamp=" +
  192. getApp().globalData.globalTimestamp +
  193. "&sign=" +
  194. md5Sign;
  195. uni.request({
  196. url: url,
  197. method: "POST",
  198. header: {
  199. "content-type": "application/x-www-form-urlencoded",
  200. },
  201. data: {
  202. openid: getApp().globalData.open_id,
  203. year:this.dateYear,
  204. month:this.dateMonth,
  205. level:this.index,
  206. page:pageNum,
  207. page_size:pageSize
  208. },
  209. success: (res) => {
  210. if (res.data.code === 200) {
  211. // 接口返回的当前页数据列表 (数组)
  212. let curPageData = res.data.data.list;
  213. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  214. let curPageLen = curPageData.length;
  215. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  216. let totalPage = res.data.data.page_count;
  217. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  218. let totalSize = res.data.data.count;
  219. // // 接口返回的是否有下一页 (true/false)
  220. // let hasNext = data.xxx;
  221. if(page.num == 1) this.honorList = []; //如果是第一页需手动制空列表
  222. let list = res.data.data.list;
  223. list.forEach((item)=>{
  224. item.pic_url = this.shareUrl + item.pic_url;
  225. item.pic_url_resize = this.shareUrl + item.pic_url_resize;
  226. })
  227. this.honorList=this.honorList.concat(res.data.data.list); //追加新数据
  228. this.mescroll.endByPage(curPageLen || 0, totalPage);
  229. }
  230. },
  231. fail: () => {
  232. console.log("连接失败");
  233. this.mescroll.endErr();
  234. },
  235. });
  236. },
  237. goRecord(id){
  238. if(id){
  239. uni.navigateTo({
  240. url:'./record?id=' + id
  241. })
  242. }else {
  243. uni.navigateTo({
  244. url:'./record'
  245. })
  246. }
  247. },
  248. delRecordRequest(delId){
  249. let md5Sign = md5(
  250. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  251. "&secret=" + getApp().globalData.secret
  252. );
  253. let url = getApp().globalData.shareUrl +"api/api.php" +
  254. "?method=glory&action=del&timestamp=" +
  255. getApp().globalData.globalTimestamp +
  256. "&sign=" +
  257. md5Sign;
  258. uni.request({
  259. url: url,
  260. method: "POST",
  261. header: {
  262. "content-type": "application/x-www-form-urlencoded",
  263. },
  264. data: {
  265. openid: getApp().globalData.open_id,
  266. id:delId
  267. },
  268. success: (res) => {
  269. if (res.data.code === 200) {
  270. uni.showToast({
  271. title: "删除成功",
  272. icon: "none",
  273. duration: 2500,
  274. success:()=>{
  275. if(this.current){
  276. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf)
  277. }else {
  278. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  279. }
  280. }
  281. });
  282. }
  283. },
  284. fail: () => {
  285. console.log("连接失败");
  286. },
  287. });
  288. },
  289. delRecord(id){
  290. let that = this;
  291. uni.showModal({
  292. title: "确定删除此荣誉吗?",
  293. success(res) {
  294. if (res.confirm) {
  295. that.delRecordRequest(id);
  296. } else if (res.cancel) {
  297. console.log("用户点击取消");
  298. }
  299. },
  300. });
  301. },
  302. showLarge(src) {
  303. uni.previewImage({
  304. urls: [src],
  305. longPressActions: {
  306. itemList: ["发送给朋友", "保存图片"],
  307. success: function (data) {},
  308. fail: function (err) {
  309. console.log(err.errMsg);
  310. },
  311. },
  312. });
  313. },
  314. getHonorList(y,m,level) {
  315. let md5Sign = md5(
  316. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  317. "&secret=" + getApp().globalData.secret
  318. );
  319. let url = getApp().globalData.shareUrl +"api/api.php" +
  320. "?method=glory&action=list&timestamp=" +
  321. getApp().globalData.globalTimestamp +
  322. "&sign=" +
  323. md5Sign;
  324. uni.request({
  325. url: url,
  326. method: "POST",
  327. header: {
  328. "content-type": "application/x-www-form-urlencoded",
  329. },
  330. data: {
  331. openid: getApp().globalData.open_id,
  332. year:y,
  333. month:m,
  334. level:level,
  335. page:this.page,
  336. page_size:this.pageSize
  337. },
  338. success: (res) => {
  339. if (res.data.code === 200) {
  340. let list = res.data.data.list;
  341. list.forEach((item)=>{
  342. item.pic_url = this.shareUrl + item.pic_url;
  343. item.pic_url_resize = this.shareUrl + item.pic_url_resize;
  344. })
  345. this.honorList = list;
  346. }
  347. },
  348. fail: () => {
  349. console.log("连接失败");
  350. },
  351. });
  352. },
  353. getMyHonor(y,m) {
  354. let md5Sign = md5(
  355. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  356. "&secret=" + getApp().globalData.secret
  357. );
  358. let url = getApp().globalData.shareUrl +"api/api.php" +
  359. "?method=glory&action=my_list&timestamp=" +
  360. getApp().globalData.globalTimestamp +
  361. "&sign=" +
  362. md5Sign;
  363. uni.request({
  364. url: url,
  365. method: "POST",
  366. header: {
  367. "content-type": "application/x-www-form-urlencoded",
  368. },
  369. data: {
  370. openid: getApp().globalData.open_id,
  371. year:y,
  372. month:m,
  373. // level:level,
  374. // page:1,
  375. // page_size:10
  376. },
  377. success: (res) => {
  378. if (res.data.code === 200) {
  379. let list = res.data.data.list;
  380. list.forEach((item)=>{
  381. item.pic_url = this.shareUrl + item.pic_url;
  382. item.pic_url_resize = this.shareUrl + item.pic_url_resize;
  383. })
  384. this.myHonorList = list;
  385. }
  386. },
  387. fail: () => {
  388. console.log("连接失败");
  389. },
  390. });
  391. },
  392. },
  393. };
  394. </script>
  395. <style lang="scss" scoped>
  396. .content {
  397. .active-title-box {
  398. display: flex;
  399. align-items: center;
  400. margin-top: 10rpx;
  401. font-size: 26rpx;
  402. height: 100rpx;
  403. border-bottom: 1px solid #d7d7d7;
  404. margin-top: 10rpx;
  405. .time-select-box {
  406. width: 32%;
  407. margin-left: 5%;
  408. }
  409. picker {
  410. width: 20%;
  411. border: 1px solid #d7d7d7;
  412. height: 60rpx;
  413. line-height: 60rpx;
  414. border-radius: 10rpx;
  415. margin-left: 20rpx;
  416. padding: 0 10rpx;
  417. position: relative;
  418. image {
  419. width: 20rpx;
  420. height: 20rpx;
  421. position: absolute;
  422. top: 11px;
  423. right: 5px;
  424. }
  425. }
  426. button {
  427. width: 25%;
  428. font-size: 25rpx;
  429. background: #4988fd;
  430. color: #fff;
  431. margin-left: 20rpx;
  432. margin-right: 20rpx;
  433. }
  434. }
  435. .honor-box {
  436. display: flex;
  437. flex-direction: column;
  438. padding: 20rpx 40rpx 20rpx 40rpx;
  439. border-bottom: 1px solid #d7d7d7;
  440. image {
  441. width: 360rpx;
  442. height: 160rpx;
  443. margin: 20rpx auto;
  444. }
  445. .honor-award {
  446. width: 80%;
  447. color: #ccc;
  448. font-size: 28rpx;
  449. margin: 20rpx 0 10rpx 0;
  450. }
  451. .honor-info-box {
  452. display: flex;
  453. align-items: center;
  454. font-size: 26rpx;
  455. color: #ccc;
  456. text {
  457. margin-right: 20rpx;
  458. }
  459. }
  460. .edit-icon-box {
  461. position: absolute;
  462. right: 10px;
  463. top: 10px;
  464. image {
  465. width: 35rpx;
  466. height: 35rpx;
  467. margin-right: 10rpx;
  468. }
  469. }
  470. }
  471. .no-data-box {
  472. position: fixed;
  473. top: 100px;
  474. left: 30%;
  475. }
  476. }
  477. </style>