com-community-goods.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <?php
  2. ?>
  3. <style>
  4. .flexcenter {
  5. display: flex;
  6. justify-content: center;
  7. }
  8. .el-checkbox-list {
  9. margin: 0 0 20px;
  10. display: block;
  11. }
  12. .el-card-style {
  13. max-height: 400px;
  14. overflow-y: auto;
  15. /* margin-right: 20px; */
  16. }
  17. .span-none-style {
  18. display: none;
  19. }
  20. .div-header-style {
  21. font-size: 14px;
  22. margin-left: 6px;
  23. margin-bottom: 20px;
  24. }
  25. input.el-input__inner {
  26. height: 32px;
  27. line-height: 32px;
  28. font-size: 13px;
  29. }
  30. .el-table .warning-row {
  31. background: oldlace;
  32. }
  33. .el-table .success-row {
  34. background: #f0f9eb;
  35. }
  36. .el-table-column--selection .cell {
  37. padding-left: 10px;
  38. }
  39. .zsan-padding-style {
  40. padding: 10px 0;
  41. margin: 0;
  42. }
  43. </style>
  44. <template id="com-community-goods">
  45. <div class="com-community-goods">
  46. <el-card class="edit-card" shadow="never">
  47. <el-form :model="communityGoodsForm" size="small" @submit.native.prevent>
  48. <div>
  49. <el-form-item label="社区团购开关" prop="enable">
  50. <el-switch :active-value="1" :inactive-value="0" v-model="communityGoodsForm.enable"></el-switch>
  51. <p>开启时可选择自提点选项,关闭时默认提交订单选择方式只有快递配送</p>
  52. </el-form-item>
  53. <el-form-item label="是否开启自提退款" prop="enable_refund" v-if="communityGoodsForm.enable == 1">
  54. <el-switch v-model="communityGoodsForm.enable_refund" :active-value="1" :inactive-value="0"></el-switch>
  55. <p>订单没有核销前可退</p>
  56. </el-form-item>
  57. <el-form-item label="配送方式" prop="supported_logistics" v-if="communityGoodsForm.enable == 1">
  58. <el-checkbox-group v-model="communityGoodsForm.supported_logistics" :min="1" :max="2">
  59. <el-checkbox :label="1">快递配送</el-checkbox>
  60. <el-checkbox :label="2">站点自提</el-checkbox>
  61. <el-checkbox :label="3">送货上门</el-checkbox>
  62. </el-checkbox-group>
  63. <p>默认自动勾选快递配送和站点自提,选项最多只可选2项。</p>
  64. </el-form-item>
  65. <el-row :gutter="10" v-if="communityGoodsForm.enable == 1">
  66. <div class="div-header-style">选择自提点</div>
  67. <div class="com-district">
  68. <el-card v-loading="districtLoading" shadow="always" body-style="padding:0" style="border:0;min-height: 100px;">
  69. <div flex="dir:left box:mean">
  70. <template v-if="list.length > 0">
  71. <el-card class="el-card-style" shadow="always">
  72. <template v-for="(item, index) in list">
  73. <div class="el-checkbox el-checkbox-list" @click="selectProvince(index)">
  74. <el-checkbox @change="pickerChange(item)" v-model="item.checked" :indeterminate="item.isIndeterminate" :disabled="item.unchecked">
  75. <span class="span-none-style el-checkbox__label">{{item.name}}</span>
  76. </el-checkbox>
  77. <span class="el-checkbox__label">{{item.name}}</span>
  78. </div>
  79. </template>
  80. </el-card>
  81. <el-card class="el-card-style" shadow="always" v-if="list[p_index].children && list[p_index].children.length > 0">
  82. <template v-for="(item, index) in list[p_index].children">
  83. <div class="el-checkbox el-checkbox-list" @click="c_index = index">
  84. <el-checkbox @change="pickerChange(item)" v-model="item.checked" :indeterminate="item.isIndeterminate" :disabled="item.unchecked">
  85. <span class="span-none-style el-checkbox__label">{{item.name}}</span>
  86. </el-checkbox>
  87. <span class="el-checkbox__label">{{item.name}}</span>
  88. </div>
  89. </template>
  90. </el-card>
  91. <el-card class="el-card-style" shadow="always" v-if="list[p_index].children[c_index].children && list[p_index].children[c_index].children.length > 0">
  92. <template v-for="(item, index) in list[p_index].children[c_index].children">
  93. <div class="el-checkbox el-checkbox-list" @click="d_index = index">
  94. <el-checkbox @change="pickerChange(item)" v-model="item.checked" :disabled="item.unchecked" :indeterminate="item.isIndeterminate">
  95. <span class="span-none-style el-checkbox__label">{{item.name}}</span>
  96. </el-checkbox>
  97. <span class="el-checkbox__label">{{item.name}}</span>
  98. </div>
  99. </template>
  100. </el-card>
  101. <el-card class="el-card-style" shadow="always">
  102. <div>
  103. <el-input placeholder="请输入自提点名称" clearable v-model="searchStr" class="input-with-select" prefix-icon="el-icon-search" >
  104. </el-input>
  105. </div>
  106. <template v-if="list[p_index].children[c_index].children[d_index].children && list[p_index].children[c_index].children[d_index].children.length > 0">
  107. <template v-for="(item, index) in list[p_index].children[c_index].children[d_index].children">
  108. <div class="el-checkbox el-checkbox-list zsan-padding-style" v-show="item.show">
  109. <el-checkbox @change="pickerChange(item)" v-model="item.checked" :disabled="item.unchecked">
  110. <span class="span-none-style el-checkbox__label">(id: {{item.id}}) {{item.name}}</span>
  111. </el-checkbox>
  112. <span class="el-checkbox__label">(id: {{item.id}}) {{item.name}}</span>
  113. </div>
  114. </template>
  115. </template>
  116. </el-card>
  117. </template>
  118. </div>
  119. </el-card>
  120. </div>
  121. </el-row>
  122. <el-row :gutter="10" v-if="communityGoodsForm.enable == 1">
  123. <el-col :span=24>
  124. <div style="margin-top:30px;">商品默认全选自提点,如某个自提点不支持该商品则手动选择去掉勾。</div>
  125. </el-col>
  126. </el-row>
  127. </div>
  128. </el-form>
  129. </el-card>
  130. </div>
  131. </template>
  132. <script>
  133. Vue.component('com-community-goods', {
  134. template: "#com-community-goods",
  135. props: {
  136. goods_id: {
  137. type: Number | String,
  138. default: 0
  139. }
  140. },
  141. data() {
  142. return {
  143. SmartFormdialog: false,
  144. loading: false,
  145. communityGoodsForm: {
  146. enable: 0,
  147. enable_refund: 0,
  148. list: [],
  149. supported_logistics: [1, 2],
  150. },
  151. searchStr: '',
  152. p_index: 0,
  153. c_index: 0,
  154. d_index: 0,
  155. districtLoading: false,
  156. defaultList: [], // 所有省市区
  157. tempList: [], // 已选择待返回的省市区
  158. list: [], // 渲染页面使用省市区列表
  159. level: 3,
  160. detail: [],
  161. edit: [],
  162. params: [],
  163. seted: [],
  164. community_arr_ids: [],
  165. }
  166. },
  167. watch: {
  168. // form:{
  169. // deep:true,
  170. // immediate: true,
  171. // handler(value){
  172. // this.$emit("select", {Redpack: this.form});
  173. // }
  174. // }
  175. // 监听传入的省市区数组
  176. edit() {
  177. this.newList();
  178. },
  179. searchStr() {
  180. this.showCommunity()
  181. }
  182. },
  183. mounted: function() {
  184. this.getRegionList()
  185. if (this.goods_id) this.getList();
  186. },
  187. methods: {
  188. showCommunity() {
  189. for (let i in this.list) {
  190. for (let k in this.list[i].children) {
  191. for (let j in this.list[i].children[k].children) {
  192. for (let n in this.list[i].children[k].children[j].children) {
  193. let show = true
  194. if (this.searchStr) {
  195. show = this.list[i].children[k].children[j].children[n].name.indexOf(this.searchStr) > -1
  196. }
  197. this.list[i].children[k].children[j].children[n].show = show
  198. }
  199. }
  200. }
  201. }
  202. },
  203. getList() {
  204. let self = this;
  205. request({
  206. params: {
  207. r: 'community/community-goods/get-goods-setting',
  208. goods_id: self.goods_id
  209. },
  210. method: 'get'
  211. }).then(function(e) {
  212. if (e.data.code == 0) {
  213. self.communityGoodsForm = Object.assign(
  214. self.communityGoodsForm,
  215. e.data.data
  216. );
  217. self.edit = e.data.data.list;
  218. }
  219. }).catch(function(e) {
  220. });
  221. },
  222. getRegionList() {
  223. let self = this;
  224. self.districtLoading = true;
  225. request({
  226. params: {
  227. r: 'community/common/region-list',
  228. level: this.level
  229. },
  230. method: 'get'
  231. }).then(function(e) {
  232. self.districtLoading = false;
  233. if (e.data.code == 0) {
  234. self.defaultList = e.data.data.list;
  235. self.newList();
  236. } else {
  237. self.$message.error(e.data.msg);
  238. }
  239. }).catch(function(e) {
  240. self.districtLoading = false;
  241. });
  242. },
  243. // 根据传入数据重新获取省市区列表
  244. newList() {
  245. let defaultList = this.checkList(this.defaultList, this.edit);
  246. console.log('defaultList', defaultList);
  247. this.setDefaultSelect()
  248. let listP = this.setListUnchecked(defaultList, 1);
  249. let list = this.setListUnchecked(listP, 0);
  250. this.list = JSON.parse(JSON.stringify(list));
  251. this.communityGoodsForm.list = this.list;
  252. },
  253. // 判断哪些省市区已经选择
  254. checkList(defaultList, edit) {
  255. if (typeof defaultList == 'undefined') {
  256. return [];
  257. }
  258. let is_edit = edit.length > 0;
  259. for (let i in defaultList) {
  260. // 是否选中
  261. defaultList[i].checked = this.goods_id > 0 ? false : true;
  262. // 是否禁用
  263. defaultList[i].unchecked = false;
  264. // 是否不确定
  265. defaultList[i].isIndeterminate = false;
  266. if (typeof defaultList[i].children != 'undefined') {
  267. defaultList[i].children = this.checkList(defaultList[i].children, edit);
  268. }
  269. if (typeof edit != 'undefined') {
  270. for (let j = 0; j < edit.length; j++) {
  271. if (typeof edit[j].children != 'undefined') {
  272. deep1: for (let k = 0; k < edit[j].children.length; k++) {
  273. if (typeof edit[j].children[k].children != 'undefined') {
  274. deep2: for (let q = 0; q < edit[j].children[k].children.length; q++) {
  275. if (typeof edit[j].children[k].children[q].children != 'undefined') {
  276. deep3: for (let x = 0; x < edit[j].children[k].children[q].children.length; x++) {
  277. // if (defaultList[i].level == 4) {
  278. // console.log(defaultList[i].id, edit[j].children[k].children[q].children[x].id,
  279. // defaultList[i].id == edit[j].children[k].children[q].children[x].id)
  280. // }
  281. if (defaultList[i].level == 4) {
  282. if (this.seted.indexOf(defaultList[i].id) > -1 && defaultList[i].checked) {
  283. continue;
  284. } else {
  285. this.seted.push(defaultList[i].id);
  286. }
  287. defaultList[i].checked = defaultList[i].id == edit[j].children[k].children[q].children[x].id;
  288. }
  289. defaultList[i].unchecked = false;
  290. defaultList[i].show = true
  291. if (defaultList[i].checked) {
  292. break deep1;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. else {
  301. if (defaultList[i].id == edit[j].id) {
  302. defaultList[i].checked = true;
  303. defaultList[i].unchecked = false;
  304. break;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return defaultList;
  311. },
  312. // 重新赋值已经选择的省市区level == 1父级影响子级||level == 0子级影响父级
  313. setListUnchecked(list, level = 1) {
  314. if (typeof list == 'undefined') {
  315. return list;
  316. }
  317. for (let i in list) {
  318. if (typeof list[i].children != 'undefined') {
  319. if (level == 0) {
  320. list[i].children = this.setListUnchecked(list[i].children, 0);
  321. }
  322. let unchecked = false;
  323. let checkCount = 0;
  324. let isIndeterminateCount = 0;
  325. for (let j in list[i].children) {
  326. if (list[i].unchecked && level == 1) {
  327. list[i].children[j].unchecked = true;
  328. }
  329. if (level == 1 && list[i].children[j].level == 4) {
  330. list[i].children[j].show = true
  331. }
  332. if (list[i].children[j].unchecked) {
  333. unchecked = true;
  334. }
  335. if (list[i].checked) {
  336. list[i].children[j].checked = true;
  337. }
  338. if (list[i].children[j].checked) {
  339. checkCount++;
  340. }
  341. if (list[i].children[j].isIndeterminate) {
  342. isIndeterminateCount++;
  343. }
  344. }
  345. if (unchecked && level == 0) {
  346. list[i].unchecked = true;
  347. }
  348. if (list[i].children.length == checkCount) {
  349. list[i].checked = true;
  350. } else if (checkCount > 0) {
  351. list[i].checked = false;
  352. list[i].isIndeterminate = true;
  353. } else {
  354. list[i].checked = false;
  355. if (isIndeterminateCount > 0) {
  356. list[i].isIndeterminate = true;
  357. } else {
  358. list[i].isIndeterminate = false;
  359. }
  360. }
  361. if (level == 1) {
  362. list[i].children = this.setListUnchecked(list[i].children, 1);
  363. }
  364. }
  365. }
  366. return list;
  367. },
  368. // 将当前值的子列表的选中状态与当前值一致
  369. changeAllList(list, checked) {
  370. if (typeof list != 'undefined') {
  371. for (let i in list) {
  372. if (typeof list[i].children != 'undefined') {
  373. list[i].children = this.changeAllList(list[i].children, checked);
  374. }
  375. list[i].checked = checked;
  376. }
  377. }
  378. return list;
  379. },
  380. // 重置所有省市区的选中状态 返回已选中的省市区
  381. setTempList(list) {
  382. let newList = [];
  383. let checkCount = 0;
  384. let isIndeterminateCount = 0;
  385. for (let i in list) {
  386. if (typeof list[i].children != 'undefined') {
  387. let childList = this.setTempList(list[i].children);
  388. if (childList.isIndeterminateCount > 0) {
  389. list[i].checked = false;
  390. list[i].isIndeterminate = true;
  391. isIndeterminateCount++;
  392. newList = newList.concat(childList.newList);
  393. } else if (childList.checkCount < list[i].children.length) {
  394. list[i].checked = false;
  395. if (childList.checkCount > 0) {
  396. list[i].isIndeterminate = true;
  397. isIndeterminateCount++;
  398. newList = newList.concat(childList.newList);
  399. } else {
  400. list[i].isIndeterminate = false;
  401. }
  402. } else if (childList.checkCount == list[i].children.length) {
  403. list[i].checked = true;
  404. list[i].isIndeterminate = false;
  405. newList = newList.concat(childList.newList);
  406. } else {
  407. list[i].checked = true;
  408. list[i].isIndeterminate = false;
  409. }
  410. }
  411. if (list[i].checked) {
  412. checkCount++;
  413. newList.push(list[i]);
  414. }
  415. }
  416. return {
  417. newList: newList,
  418. checkCount: checkCount,
  419. isIndeterminateCount: isIndeterminateCount
  420. };
  421. },
  422. // 向父组件发送消息
  423. pickerChange(item) {
  424. this.changeAllList(item.children, item.checked);
  425. let tempList = this.setTempList(this.list);
  426. this.tempList = tempList.newList;
  427. this.selectItem(item)
  428. this.$emit('selected', this.tempList, this.params);
  429. },
  430. /**
  431. * 获取选择的自提点ID
  432. */
  433. selectItem(item) {
  434. if (item.level == 4) {
  435. item.checked ? this.community_arr_ids.push(item.id) : this.community_arr_ids = this.community_arr_ids.filter(function (value) {
  436. return value != item.id;
  437. });
  438. } else {
  439. let self = this
  440. item.children && item.children.forEach(function(children) {
  441. self.selectItem(children)
  442. })
  443. }
  444. },
  445. /**
  446. * 默认选中
  447. */
  448. setDefaultSelect() {
  449. let self = this
  450. this.defaultList.forEach(function(children) {
  451. self.selectItem(children)
  452. })
  453. },
  454. // 选择省份
  455. selectProvince(index) {
  456. this.p_index = index;
  457. this.c_index = 0;
  458. this.d_index = 0;
  459. },
  460. },
  461. });
  462. </script>