利用js的閉包原理做對象封裝及調用方法

創建一個js文件,名為testClosure.js:

?

1

2

3

4

5

6

7

8

9

(function () {

??function a()

??{

????alert('i am a');

??}

??outFunc = function () {

????a();

??}

})();

這里不論寫多少個function,a b c d ...外面都調用不到,包括這里面var定義的變量也都調用不到,那么你在里面盡情的寫,就不用擔心這些函數名變量名跟外界沖突;

只需要暴露一個outFunc這個函數供外界調用。這個函數呢沒有用var定義,就變成一個全局變量,外界就可以調用的到,利用這一點,讓這個函數變成匿名函數和外界溝通的橋梁。

再利用js面向對象的方法,就可以封裝出非常好用的組件。

示例一:不需要繼承的js組件

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

(function()

{

??var arrAuthItem = new Array();

??var isInited = false;

??var syncTableObj=findObj("sync-table-id",document);

?

??var newTR=null;

?var checkBox=null;

?var authTable = null;

?var selfPicUrl=null;

?var selfItem=null;

?

?var isAuthItemEnabled=false;

??var isSelfItemEnabled=false;

?

??function getAuthShopCurrent()

??{

???return $("#"+globalSyncVars.serverComClientId.AuthShopListId).val();

??}

?

??function getSyncFieldCurrent()

??{

???return $("#"+globalSyncVars.serverComClientId.SyncFieldListId).val();

??}

???

??function setTitle()

??{

???$("#sync-table-title-id").html("從“"+getAuthShopCurrent()+"”同步");

??}

?

??function getNumIidFrom(numIidTo)

??{

?????var curRowData = jQuery("#listItemDefine").jqGrid('getRowData', numIidTo);

?????return curRowData.NumIidFrom;

??}

?

??function insertRows()

??{

???deleteAll();

?

???for(var i=0;i<arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""].length;i++)

???{

???newTR=syncTableObj.insertRow(syncTableObj.rows.length);

???// 0 checkbox

???checkBox=newTR.insertCell(0);

???// 1 auth table

???authTable=newTR.insertCell(1);

???// 2 self picurl

???selfPicUrl=newTR.insertCell(2);

???// 3 self item

???selfItem=newTR.insertCell(3);

?

???isSelfItemEnabled=setterSelfItem(i);

???isAuthItemEnabled=setterAuthItem(i);

????

???if(isAuthItemEnabled&&isSelfItemEnabled)

????setterEnableStatus(true,i);

???else

????setterEnableStatus(false,i);

???}

??}

?

??function setterAuthItem(i)

??{

???var isEnabled=false;

?

???if (!stringToBoolean(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["HasSameItem"]))

?{

??authTable.innerHTML='<table class="inner-table-class inner-table-from-class"><tr><td class="inner-table-td-radio-class"></td><td class="inner-table-td-class main-img-class"></td><td class="inner-table-td-class" style="padding-top:21px;padding-bottom:21px;">此寶貝沒有對應的授權寶貝</td><td class="inner-table-td-class sync-img-class"><span class="icon-no-class"/></td></tr></table>';

??return isEnabled;

?}

?

?var arr = arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["ListItemFrom"];

?var strHead = '<table class="inner-table-class inner-table-from-class">';

?var strTr = "";

?var isBinded = false;

?

?

?// 如果已經綁定了,標記一下,是否已經授權過也標記

????var numIid = getNumIidFrom(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["NumIidTo"]);

????if(numIid!="none")

????{

??????for(var j=0;j<arr.length;j++)

??????{

????????if(arr[j]["NumIid"]==numIid)

????????{

??????????isBinded=true;

??????????break;

????????}

??????}

????}

??

?

?for(var p=0;p<arr.length;p++)

?{

??var isSharedFrom = stringToBoolean(arr[p]["IsFromItemHasShareFrom"]);

??var isSharedTo = stringToBoolean(arr[p]["IsFromItemHasShareTo"]);

??var picUrl='<a href="http://item.taobao.com/item.htm?id=' + arr[p][" rel="external nofollow" NumIid"] + '" target="_blank"><img class="icon" style="padding:0px;width:60px" src="' + arr[p]["PicUrl"] + '_sum.jpg" title="' + arr[p]["Title"] + '" /></a>';

??if(getEnabledStatus(isBinded,!isSharedTo,isSelfItemEnabled))

??isEnabled = true;

??strTr+='<tr><td class="inner-table-td-radio-class">'+getRadioCode(isBinded,!isSharedTo,isSelfItemEnabled,i,arr.length)+'</td><td class="inner-table-td-class main-img-class">'+picUrl+'</td><td class="inner-table-td-class">'+getAuthItemCode(arr[p],isSharedFrom,isSharedTo,i)+'</td><td class="inner-table-td-class sync-img-class">'+getEnabledCode(isBinded,!isSharedTo,isSelfItemEnabled,arr[p],numIid)+'</td></tr>';

?}

?authTable.innerHTML = strHead+strTr+'</table>';

?return isEnabled;

??}

??// 返回auth寶貝詳情html代碼

??function getAuthItemCode(obj,isSharedFrom,isSharedTo,i)

??{

???var labelStr = "";

???if(isSharedFrom) labelStr = '<span style="color:red;">【源】</span>';

???if(isSharedTo) labelStr = '<span style="color:red;">【受】</span>';

???return '<span style="line-height:20px;" columnName="NumIid">'+labelStr+'ID:' + obj["NumIid"] + '</span>'

???????+ '<span style="padding-left:14px;" columnName="OuterId">商家編碼:' + obj["OuterId"] + '</span>'

???????+ '<span style="padding-left:14px;color:'+getPriceColor(obj["Price"],i)+'" columnName="Price">價格:' + obj["Price"] + '</span>'

???????+ '<br><span style="line-height:20px;" columnName="Title">' + obj["Title"] + '</span>';

??}

??// 返回self寶貝詳情html代碼

??function getSelfItemCode(obj)

??{

???var labelStr = "";

???if(stringToBoolean(obj["IsToItemHasShareFrom"])) labelStr = '<span style="color:red;">【源】</span>';

???if(stringToBoolean(obj["IsToItemHasShareTo"])) labelStr = '<span style="color:red;">【受】</span>';

???return '<span class="sync-table-td-class"><span style="line-height:20px;" columnName="NumIid">'+labelStr+'ID:' + obj["NumIidTo"] + '</span>'

???????+ '<span style="padding-left:14px;" columnName="OuterId">商家編碼:' + obj["OuterIdTo"] + '</span>'

???????+ '<span style="padding-left:14px;color:black;" columnName="Price">價格:' + obj["PriceTo"] + '</span></span>'

???????+ '<br><span class="sync-table-td-class" style="line-height:20px;" columnName="Title">' + obj["TitleTo"] + '</span>';

??}

??// 返回綁定關系圖標的html代碼

??function getEnabledCode(isBinded,isAuthEnabled,isSelfEnabled,obj,numIid)

??{

???if(isBinded)

???{

??????// 如果是綁定狀態,還要看當前item是否為綁定的item

??????// 在這種情況下,判斷是否可綁定,不需要用到selfItem

??????if(obj["NumIid"]==numIid)

????????return '<span class="icon-bind-class"/>';

??????else

??????{

????????if(stringToBoolean(obj["IsFromItemHasShareTo"]))

??????????return '<span class="icon-no-class"/>';

????????else

??????????return '<span class="icon-ok-class"/>';

??????}

???}else

???{

???if(isAuthEnabled&&isSelfEnabled)

????return '<span class="icon-ok-class"/>';

???else

????return '<span class="icon-no-class"/>';

???}

??}

??// 是否可以綁定

??function getEnabledStatus(isBinded,isAuthEnabled,isSelfEnabled)

??{

???if(isBinded) return false;

???if(isAuthEnabled&&isSelfEnabled)

????{

???return true;

????}

???else

????{

???return false;

????}

??}

??// 返回radio的html代碼

??/**

??*? isBinded 是否已經綁定

??*? isAuthEnabled auth是否可同步

??*? isSelfEnabled self是否可同步

??*? 當前rows的index

??*? 當前auth-list的長度(如果是一對一,當然不需要radio)

??*/

??function getRadioCode(isBinded,isAuthEnabled,isSelfEnabled,i,length)

??{

???if(isBinded) return "";

????if(length==1) return "";

???if(isAuthEnabled==false||isSelfEnabled==false) return "";

?return '<input type="radio" name="radio'+i+'">';

??}

?

?

??function setterSelfItem(i)

??{

???var isEnabled=true;

???var picUrl='<a href="http://item.taobao.com/item.htm?id=' + arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+" rel="external nofollow" "][i]["NumIidTo"] + '" target="_blank"><img class="icon" style="padding-left:11px;width:60px" src="' + arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["PicUrlTo"] + '_sum.jpg" title="' + arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["TitleTo"] + '" /></a>';

????

???selfPicUrl.innerHTML = picUrl;

???selfItem.innerHTML = getSelfItemCode(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]);

?

???if(stringToBoolean(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["IsToItemHasShareFrom"])) isEnabled = false;

???if(stringToBoolean(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["IsToItemHasShareTo"])) isEnabled = false;

???return isEnabled;

??}

?

??function getPriceColor(price,i)

??{

???if(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["PriceTo"]==undefined) return "black";

???if(price==undefined) return "black";

???return (price==arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["PriceTo"])?"black":"red";

??}

?

??function setterEnableStatus(isEnabled,i)

??{

???if(isEnabled)

???checkBox.innerHTML='<input class="enableCheckbox" type="checkbox" checked="checked" index="'+i+'"/>';

???else

???checkBox.innerHTML='<input type="checkbox" disabled="true"/>';

??}

?

??function stringToBoolean(str)

??{

???if (str==undefined) return false;

???switch(str.toLowerCase())

???{

???case "true": case "yes": case "1": return true;

???case "false": case "no": case "0": case null: return false;

???default: return Boolean(str);

???}

??}

?

??function deleteAll()

??{

???for(var i=syncTableObj.rows.length-1;i>2;i--)

???{

???syncTableObj.deleteRow(i);

???}

??}

?

??function selectAll(isSelect)

??{

???if(isSelect)

???{

???$(".enableCheckbox").prop("checked",true);

???}else

???{

???$(".enableCheckbox").prop("checked",false);

???}

??}

?

??function findObj(theObj, theDoc)

?{

?var p, i, foundObj;

?if(!theDoc) theDoc = document;

?if((p = theObj.indexOf("?")) > 0 && parent.frames.length)

?{

??theDoc = parent.frames[theObj.substring(p+1)].document;

??theObj = theObj.substring(0,p);

?}

?if(!(foundObj = theDoc[theObj]) && theDoc.all)

?foundObj = theDoc.all[theObj];

?for (i=0; !foundObj && i < theDoc.forms.length; i++)

??foundObj = theDoc.forms[i][theObj];

?for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)

??foundObj = findObj(theObj,theDoc.layers[i].document);

?if(!foundObj && document.getElementById)

??foundObj = document.getElementById(theObj);

?return foundObj;

?}

?

?function refrash()

?{

?deleteAll();

?

?if(!isInited)

??return;

?

?setTitle();

?

?//現在js還沒有數據的,去取值

?if(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""]==null)

?{

??var urledit="./x.aspx?method=GetAuthItem&rmd="+Math.random();

??$.post(urledit,$("#"+globalSyncVars.serverComClientId.form1).serialize())

??.done(function(myJsonResult) {

???????var data = $.evalJSON(myJsonResult);

???????ajaxResponseResult(data);

???????if (data.IsSuccess) {

?????????arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""]=data.rows;

?????????insertRows();

?????????$("#sync-table-id").css("display","inline-table");

???????}

?????})

?????.fail(function(data) {

???????ajaxResponseResult(data);

?????})

?????.always(function(myJsonResult) {

?????});

?}else

?{

??insertRows();

?}

?}

?

?function checkIsEnabledBind(i)

?{

?if(stringToBoolean(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["IsFromItemHasShareTo"])) return false;

?if(stringToBoolean(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["IsToItemHasShareFrom"])) return false;

?if(stringToBoolean(arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][i]["IsToItemHasShareTo"])) return false;

?return true;

?}

?

?function setSyncValueToCom()

?{

?var numIidsSelf="";

?var numIidsAuth="";

?var isBind="";

????var isRadioUnChecked = false;

?

?$(".enableCheckbox:checked").each(function()

?{

??if(checkIsEnabledBind($(this).attr("index")))

??{

????????var checkBoxIndex = $(this).attr("index");

????????var radioIndex = 0;

????????isRadioUnChecked = false;

????????// 通過[0]判斷radio是否存在

??if($('input:radio[name=radio'+checkBoxIndex+']')[0])

????????{

??????????var isCheckedLabel = false;

??????????// 檢查每個radio選項是否被選擇

??????????$('input:radio[name=radio'+checkBoxIndex+']').each(function()

??????????{

????????????if($('input:radio[name=radio'+checkBoxIndex+']')[radioIndex].checked)

????????????{

??????????????isCheckedLabel = true;

??????????????// 這里是跳出each循環(里層)

??????????????return false;

????????????}

????????????radioIndex++;

??????????});

??????????if(!isCheckedLabel)

????????????isRadioUnChecked = true;

??????????// 如果存在checkbox有選擇,但是radio沒選擇,應該提醒

??????????// 然后就退出了,沒有后續的提交

??????????if(isRadioUnChecked)

??????????{

????????????checkBoxIndex++;

????????????alert("第"+checkBoxIndex+"個寶貝有多個對應的授權寶貝,應該仔細查看并選擇合適的寶貝同步!");

????????????// 這里跳出循環(外層)

????????????return false;

??????????}

????????}

?

????????var arrAuth = arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][checkBoxIndex]["ListItemFrom"]

?

????????if(numIidsSelf=="")

??{

???numIidsSelf+=arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][checkBoxIndex]["NumIidTo"];

??}else

??{

???numIidsSelf+=","+arrAuthItem[getAuthShopCurrent()+getSyncFieldCurrent()+""][checkBoxIndex]["NumIidTo"];

??}

?

??if(numIidsAuth=="")

??{

???numIidsAuth+=arrAuth[radioIndex]["NumIid"];

??}else

??{

???numIidsAuth+=","+arrAuth[radioIndex]["NumIid"];

??}

??}

?});

?

?isBind=$("#isBind:checked").val()=="on"?"true":"false";

?

?$("#"+globalSyncVars.serverComClientId.HfNumIidsSelf).val(numIidsSelf);

?$("#"+globalSyncVars.serverComClientId.HfNumIidsAuth).val(numIidsAuth);

?$("#"+globalSyncVars.serverComClientId.HfIsBind).val(isBind);

?

????if(isRadioUnChecked) return -1;

????if(numIidsSelf=="") return 0;

????else return 1;

?}

?

?initTable=function()

?{

?refrash();

?isInited=true;

?}

?

?onSelectAllCheckbox=function()

?{

?if($("#selectAllCheckbox:checked").val()=="on")

?{

??selectAll(true);

?}else

?{

??selectAll(false);

?}

?}

?onPreview=function()

?{

?refrash();

?}

?

?onAldsItemSync=function(sender,jqgridObjRefresh)

?{

????var callbackCode = setSyncValueToCom();

?if(callbackCode == 0)

?{

??alert("沒有可以同步設置的寶貝!");

??return;

?}else if(callbackCode == -1)

????{

??????// 當存在沒有選擇的radio時

??????return;

????}

?var urledit="./x.aspx?method=SaveSyncItem&rmd="+Math.random();

?$.post(urledit,$("#"+globalSyncVars.serverComClientId.form1).serialize())

?.done(function(myJsonResult) {

??????var data = $.evalJSON(myJsonResult);

??????ajaxResponseResult(data);

?

??????if (data.IsSuccess)

??????{

????????showPrompt(data.PromptMsg);

?

????????if(sender)

????????{

?????????$(sender).dialog("close");

?????????$(sender).dialog("destroy");

????????}

????????if(jqgridObjRefresh)

????????{

?????????$(jqgridObjRefresh).trigger("reloadGrid");

????????}

??????}

????})

????.fail(function(data) {

??????ajaxResponseResult(data);

????})

????.always(function(myJsonResult) {

????});

?}

})();

示例二:有繼承關系的js組件

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

(function(){

?//____________________________批量修改的基類_________________________________

?function BatchModify(){}

?//選擇了什么id

?BatchModify.prototype.numIids=null;

?BatchModify.prototype.addis=null;

?BatchModify.prototype.oneIid=null;

?BatchModify.prototype.skuIds=null;

?BatchModify.prototype.selectedItemData=null;

?BatchModify.prototype.maxHeightVal=$(window).height()*0.9;

?

?// 完全克隆一個數組

?BatchModify.prototype.cloneArr=function(arr)

?{

?var arrNew = [];

?for(var i=0;i<arr.length;i++)

?{

??arrNew.push(arr[i]);

?}

?return arrNew;

?}

??

?// 通過jqGrid('getGridParam','selarrrow');取值是不可靠的,經常會變動

?// 在設置jqGrid('setSelection',bindedArr[i]);之后取出來的值經常會變化,要么長度變化,要么順序變化

?BatchModify.prototype.cancelBindedItem=function()

?{

?var tempNumIids=jQuery("#listItemDefine").jqGrid('getGridParam','selarrrow');

?var tempNumIidsClone = this.cloneArr(tempNumIids);

?var isAlert=false;

?for(var i=0;i<bindedArr.length;i++)

?{

??for(var j=0;j<tempNumIidsClone.length;j++)

??{

??if(tempNumIidsClone[j]==bindedArr[i])

??{

???isAlert=true;

???jQuery("#listItemDefine").jqGrid('setSelection',bindedArr[i]);

???break;

??}

??}

?}

?if(isAlert) alert("已經綁定了數據來源的寶貝不能修改寶貝設置,如果需要修改請先點擊寶貝最右欄的解綁按鈕解綁!");

?}

?

?BatchModify.prototype.setNumIids=function()

?{

?this.numIids=jQuery("#listItemDefine").jqGrid('getGridParam','selarrrow');

?};

?//拼裝addi的json串并賦值給addi

?BatchModify.prototype.setAddis=function()

?{

?var _addis="{rows:{";

?

???for(var i=0;i<this.numIids.length;i++)

???{

?????_addis+='"'+this.numIids[i]+'":"';

?????var tempVal=$("#addiTextId"+this.numIids[i]).val();

?????var val=tempVal.replace(/\"/ig,"\'");

?????_addis+=val;

?????_addis+='"'

?

?????if(i!=this.numIids.length-1)

?????{

???????_addis+=',';

?????}

???}

???_addis+="}}";

???this.addis=_addis;

?};

?//(單個)修改頁面傳進來的一個id

?BatchModify.prototype.setOneIid=function()

?{

?this.oneIid=$("#"+itemEditVars.itemEditClientId.HfNumIid).val();

?};

?//sku的所有已選id(一個字符串)

?BatchModify.prototype.setSkuIds=function()

?{

?this.skuIds=jQuery("#listSkuDefine").jqGrid('getGridParam','selarrrow');

?};

?

?//設置numIids的值到服務器組件

?BatchModify.prototype.setNumIidsToCom=function()

?{

?$("#"+globalVars.serverComClientId.HfItemDefineIdsSelect).val(this.numIids);

?};

?//設置addis的值到服務器組件

?BatchModify.prototype.setAddisToCom=function()

?{

?$("#"+globalVars.serverComClientId.HfAddiStr).val(this.addis);

?};

?//檢查是否有勾選寶貝

?BatchModify.prototype.checkIsSelected=function()

?{

???if (this.numIids == "") {

?????alert("請選中要批量修改的行!");

?????return false;

???}

???return true;

?};

?//批量生成描述

?BatchModify.prototype.batchGenerateDesc=function(alertResult)

?{

?this.setNumIidsToCom();

????var urledit = "x.aspx?method=BatchGenerateDesc&rdm=" + Math.random();

????if (alertResult)

??????urledit += "&generateByManual=true";

?

????this.postData(urledit,alertResult);

?};

?//post數據

?BatchModify.prototype.postData=function(urledit,alertResult)

?{

?$.post( urledit, $("#"+globalVars.serverComClientId.formAldsItemDefine1).serialize())

????.done(function(myJsonResult) {

??????var data = $.evalJSON(myJsonResult);

??????ajaxResponseResult(data);

?

??????if (data.IsSuccess) {

????????if (!data.rows)

??????????showPrompt("寶貝描述生成修改成功!");

??????}

??????if(alertResult && data.ErrMsg && $.trim(data.ErrMsg) != "")

????????alert("提醒:\n\n" + data.ErrMsg);

????})

????.fail(function(data) {

??????ajaxResponseResult(data);

????})

????.always(function(myJsonResult) {

????});

?};

?

?BatchModify.prototype.removeDialog=function()

?{

?try{ $("#descTempDiv").remove(); } catch(e){}

?}

??

?function myInherits(Child,Parent)

?{

???function F(){}

???F.prototype=Parent.prototype;

???Child.prototype=new F();

???Child.prototype.constructor=Child;

?}

??

?function createobject(proto)

?{

???function F(){}

???F.prototype=proto;

???return new F();

?}

?//_________________________批量修改(附言,確認收貨后發消息,好評后發消息)類_________________________________

?function BatchMsgModify(title,tableId,paperId,fieldName,editUrl,containerDivStr)

?{

?BatchModify.call();

?this.title=title;

?this.tableId=tableId;

?this.paperId=paperId;

?this.fieldName=fieldName;

?this.editUrl=editUrl;

?this.containerDivStr=containerDivStr;

?}

?

?myInherits(BatchMsgModify,BatchModify);

?//彈窗

?BatchMsgModify.prototype.popUpDialog=function()

?{

?$(this.containerDivStr).dialog({

??title: this.title,

?????closeText: '關閉',

?????width: 980,

?????maxHeight: $(window).height() * 0.98,

?????minHeight: $(window).height() * 0.7,

?????modal: true,

?????show: { effect: "fade", duration: 300 },

?????hide: { effect: "fade", duration: 300 },

?????buttons: {

???????確定: function() {

?????????currentInstance.confirmCallback(this);

???????},

???????關閉: function() {

?????????$(this).dialog("close");

???????}

?????}

?});

?};

?//創建表格

?BatchMsgModify.prototype.createTable=function()

?{

?$("#"+this.tableId).jqGrid({

?????viewrecords: true, // show the current page, data rang and total records on the toolbar

?????datatype: 'local',

?????rowNum:100,

?????rowList:[100],

?????height: "auto",

?????pager: "#"+this.paperId,

?????colNames:['主圖','寶貝','NumIid','Price','OuterId',this.title.indexOf("批量修改")>=0?this.title.substring(4):this.title],

?????colModel:[

???????{name:'PicUrl', index: 'PicUrl', width: 60, align: "center", sortable: false, formatter: imgFormatter, unformat:imgUnFormat},

???????{name:'Title',index:'OuterId', width:430, sortable: true, formatter: itemDescFormatter, unformat:itemDescUnFormat},

???????{name:'NumIid',index:'NumIid', width:100, hidden:true, key:true},

???????{name:'Price',index:'Price', width:100, hidden:true},

???????{name: 'OuterId', index: 'OuterId', width: 100, hidden: true },

???????{name: this.fieldName, index: this.fieldName, width: 440, sortable: true, hidden: false, formatter:this.formatter}

?????]

???});

?};

?//把表格填充進數據

?BatchMsgModify.prototype.initTable=function()

?{

?var gridArrayData=[];

???for(var i=0;i<this.numIids.length;i++)

???{

?????var curRowData=jQuery("#listItemDefine").jqGrid('getRowData',this.numIids[i]);

?

?????var obj=new Object();

?????obj["PicUrl"]=curRowData.PicUrl;

?????obj["Title"]=curRowData.Title;

?????obj["NumIid"]=curRowData.NumIid;

?????obj["Price"]=curRowData.Price;

?????obj["OuterId"]=curRowData.OuterId;

?????obj[this.fieldName]=curRowData[this.fieldName];

?????gridArrayData.push(obj);

???}

???$("#"+this.tableId).jqGrid('setGridParam',{data:gridArrayData});

???$("#"+this.tableId).trigger('reloadGrid');

?};

?//格式化字段

?BatchMsgModify.prototype.formatter=function(cellvalue,options,rowdata)

?{

?return "<TextArea id='addiTextId"+rowdata.NumIid+"' style='width:98%;' rows='4'>"+rowdata[currentInstance.fieldName]+"</TextArea>";

?};

?//重寫post函數

?BatchMsgModify.prototype.postData=function(urledit,sender)

?{

?$.post( urledit, $("#"+globalVars.serverComClientId.formAldsItemDefine1).serialize())

???.done(function(myJsonResult)

???{

?????var data = $.evalJSON(myJsonResult);

?????ajaxResponseResult(data);

?????if (data.IsSuccess) {

???????if (!data.rows)

?????????showPrompt(currentInstance.title+"成功"+currentInstance.numIids.length+"個!");

???????$("#listItemDefine").trigger('reloadGrid');

???????setTimeout(function () { $(sender).dialog("close"); }, 0);

???????setTimeout(function () { $(sender).dialog("destroy"); }, 1000);

?????}

?????if(data.ErrMsg && $.trim(data.ErrMsg) != "")

???????alert(currentInstance.title+"出錯:\n\n" + data.ErrMsg);

???})

???.fail(function(data) {

?????ajaxResponseResult(data);

???})

???.always(function(myJsonResult) {

???});

?};

?

?//確認按鈕的回調函數

?BatchMsgModify.prototype.confirmCallback=function(sender)

?{

???this.setAddis();

???this.setNumIidsToCom();

???this.setAddisToCom();

???this.postData(this.editUrl+"&rdm=" + Math.random(),sender);

?};

?

?//實例

?

?var batchAddi=null;

?var batchMsgTradeSuccess=null;

?var batchMsgRatedGood=null;

?var currentInstance=null;//指向當前對象,當this指向失效的時候可以使用這個

?

?openBatchMsgDialogType={batchAddi:0,batchMsgTradeSuccess:1,batchMsgRatedGood:2};

?openBatchMsgDialog=function(typeCode)

?{

?

?

?if(typeCode==openBatchMsgDialogType.batchAddi)

?{

??if (batchAddi==null)

??batchAddi=new BatchMsgModify("批量修改附言","tableEditContent","tablePaper","Additional","x.aspx?method=UpdateMsgAdditional","<div id='editBatchDiv'><table id='tableEditContent'></table><div id='tablePaper'></div></div>");

??currentInstance=batchAddi;

??batchAddi.cancelBindedItem();

??batchAddi.setNumIids();

??if(!batchAddi.checkIsSelected())

??return;

??????batchAddi.popUpDialog();

??????batchAddi.createTable();

??????batchAddi.initTable();

?}else if (typeCode==openBatchMsgDialogType.batchMsgTradeSuccess)

?{

??if (batchMsgTradeSuccess==null)

??batchMsgTradeSuccess=new BatchMsgModify("批量修改確認收貨后發消息","tableEditMsgTradeSuccessContent","tableMsgTradeSuccessPaper","MsgTradeSuccess","x.aspx?method=UpdateMsgTradeSuccess","<div id='editBatchDiv'><table id='tableEditMsgTradeSuccessContent'></table><div id='tableMsgTradeSuccessPaper'></div></div>");

??currentInstance=batchMsgTradeSuccess;

??batchMsgTradeSuccess.cancelBindedItem();

??batchMsgTradeSuccess.setNumIids();

??if(!batchMsgTradeSuccess.checkIsSelected())

??return;

??????batchMsgTradeSuccess.popUpDialog();

??????batchMsgTradeSuccess.createTable();

??????batchMsgTradeSuccess.initTable();

?}else if (typeCode==openBatchMsgDialogType.batchMsgRatedGood)

?{

??if (batchMsgRatedGood==null)

??batchMsgRatedGood=new BatchMsgModify("批量修改好評后發消息","tableEditMsgRatedGoodContent","tableMsgRatedGoodPaper","MsgRatedGood","x.aspx?method=UpdateMsgRatedGood","<div id='editBatchDiv'><table id='tableEditMsgRatedGoodContent'></table><div id='tableMsgRatedGoodPaper'></div></div>");

??currentInstance=batchMsgRatedGood;

??batchMsgRatedGood.cancelBindedItem();

??batchMsgRatedGood.setNumIids();

??if(!batchMsgRatedGood.checkIsSelected())

??return;

??????batchMsgRatedGood.popUpDialog();

??????batchMsgRatedGood.createTable();

??????batchMsgRatedGood.initTable();

?}

?}

?//_______________________________批量修改寶貝類(彈出單獨頁面,只要彈窗即可)_________________________________

?function BatchItemModify(){}

?

?myInherits(BatchItemModify,BatchModify);

?//重寫

?BatchItemModify.prototype.popUpDialog=function()

?{

?var urledit = "./x.aspx?NumIids="+this.numIids+"&rdm="+Math.random();

????$.get(urledit, {}, function (data, textStatus, object) {

??????var str = "<div id='editBatchDiv'>" + object.responseText + "</div>";

??????$(str).dialog({

????????dialogClass: "untitle",

????????closeText: '關閉',

????????width: 800,

????????height: 400,

????????maxHeight: $(window).height() * 0.9,

????????modal: true,

????????show: { effect: "fade", duration: 300 },

????????hide: { effect: "fade", duration: 300 },

????????buttons: {

??????????確定: function() {

????????????submitAldsItemEditBatch(this, $("#listItemDefine")); //在x.aspx定義

????????????currentInstance.batchGenerateDesc();

??????????},

??????????關閉: function() {

????????????$( this ).dialog( "close" );

??????????}

????????}

??????});

????});

?}

?

?//實例

?var batchItem=null;

?openBatchItemDialog=function()

?{

?if (batchItem==null)

??batchItem=new BatchItemModify();

?currentInstance=batchItem;

?batchItem.cancelBindedItem();

?batchItem.setNumIids();

?if(!batchItem.checkIsSelected())

??return;

?batchItem.popUpDialog();

?}

?//_______________________________批量生成寶貝描述__________________________________________

?function BatchDescModify(){}

?

?myInherits(BatchDescModify,BatchModify);

?

?BatchDescModify.prototype.generating=function()

?{

?if (!confirm("提醒。\n\n是否繼續?"))

??????return;

????this.batchGenerateDesc(true);

?};

?

?//實例

?var batchDesc=null;

?onBatchDesc=function()

?{

?if(batchDesc==null)

??batchDesc=new BatchDescModify();

?currentInstance=batchDesc;

?batchDesc.setNumIids();

?if(!batchDesc.checkIsSelected())

??return;

?batchDesc.generating();

?}

?//_____________________________________修改模板______________________________________________

?onDescMouldDialog=function()

?{

?var urledit = "./x.aspx?rdm="+Math.random();

????$.get(urledit,{},function(data,textStatus,object){

??????var str="<div id='descTempDiv'>"+object.responseText+"</div>";

??????$(str).dialog({

????????title:'修改描述模板',

????????closeText:'關閉',

????????width:850,

????????maxHeight:$(window).height() * 0.98,

????????modal:true,

????????show:{effect:"fade",duration:300},

????????hide:{effect:"fade",duration:300},

????????buttons:{

??????????確定:function()

??????????{

????????????onTempParaChangeHandler(this);

??????????},

??????????關閉:function()

??????????{

????????????$(this).dialog("close");

??????????}

????????}

??????});

?????

????});

?}

?//___________________________________批量修改sku_______________________________________

?function BatchSkuModify(){}

?

?myInherits(BatchSkuModify,BatchModify);

?

?BatchSkuModify.prototype.popUpDialog=function()

?{

?var urledit = "./x.aspx?NumIids="+this.oneIid+"&SkuIds="+this.skuIds+"&IsSkuEditBatch=true&rdm="+Math.random();

????$.get(urledit, {}, function (data, textStatus, object) {

??????var str = "<div id='descTempDiv'>" + object.responseText + "</div>";

??????$(str).dialog({

????????dialogClass: "untitle",

????????closeText: '關閉',

????????width: 800,

????????height: 400,

????????maxHeight: $(window).height() * 0.9,

????????modal: true,

????????show: { effect: "fade", duration: 300 },

????????hide: { effect: "fade", duration: 300 },

????????buttons: {

??????????確定: function() {

????????????submitAldsItemEditBatch(this, $("#listSkuDefine")); //在x.aspx定義

??????????},

??????????關閉: function() {

????????????$( this ).dialog( "close" );

??????????}

????????}

??????});

????});

?};

?

?BatchSkuModify.prototype.checkIsSelected=function()

?{

???if (this.skuIds == "") {

?????alert("請選中要批量修改的SKU!");

?????return false;

???}

???return true;

?};

?//實例

?var batchSku=null;

?

?openBatchSkuDialog=function()

?{

?if(batchSku==null)

??batchSku=new BatchSkuModify();

?currentInstance=batchSku;

?batchSku.setOneIid();

?batchSku.setSkuIds();

?batchSku.removeDialog();

?if(!batchSku.checkIsSelected())

??return;

?batchSku.popUpDialog();

?}

?//_______________________________批量修改SKU附言__________________________________________________

?

?function BatchSkuMsgModify(title,tableId,paperId,fieldName,editUrl,containerDivStr)

?{

?BatchModify.call();

?this.title=title;

?this.tableId=tableId;

?this.paperId=paperId;

?this.fieldName=fieldName;

?this.editUrl=editUrl;

?this.containerDivStr=containerDivStr;

?}

?myInherits(BatchSkuMsgModify,BatchModify);

?

?BatchSkuMsgModify.prototype.popUpDialog=function()

?{

?$(this.containerDivStr).dialog({

??title: this.title,

?????closeText: '關閉',

?????width: 980,

?????maxHeight: this.maxHeightVal,

?????// height: this.maxHeightVal>750 ? 750 : this.maxHeightVal,

?????modal: true,

?????show: { effect: "fade", duration: 300 },

?????hide: { effect: "fade", duration: 300 },

?????buttons: {

???????確定: function() {

?????????currentInstance.confirmCallback(this);

???????},

???????關閉: function() {

?????????$(this).dialog("close");

???????}

?????}

?});

?};

?//重寫-創建表格

?BatchSkuMsgModify.prototype.createTable=function()

?{

?$("#"+this.tableId).jqGrid({

?????viewrecords: true, // show the current page, data rang and total records on the toolbar

?????datatype: 'local',

?????rowNum:100,

?????rowList:[100],

?????height: "auto",

?????pager: "#"+this.paperId,

?????colNames:['SkuId','屬性名',this.title.indexOf("批量修改")>=0?this.title.substring(4):this.title],

?????colModel:[

?????{name:'SkuId',index:'SkuId', width:400, hidden:true, key:true},

?????{name:'PropertiesName',index:'PropertiesName', width:400,sortable:false, editable: false, hiden:false},

?????{name: this.fieldName, index: this.fieldName, width: 440, sortable: true, hidden: false, formatter:this.formatter}

?????]

???});

?};

?//把表格填充進數據

?BatchSkuMsgModify.prototype.initTable=function()

?{

?var gridArrayData=[];

???for(var i=0;i<this.skuIds.length;i++)

???{

?????var curRowData=jQuery("#listSkuDefine").jqGrid('getRowData',this.skuIds[i]);

?

?????var obj=new Object();

?????obj["SkuId"]=curRowData.SkuId;

?????obj["PropertiesName"]=curRowData.PropertiesName;

?????obj[this.fieldName]=curRowData[this.fieldName];

?????gridArrayData.push(obj);

???}

?

???$("#"+this.tableId).jqGrid('setGridParam',{data:gridArrayData});

???$("#"+this.tableId).trigger('reloadGrid');

?};

?//重寫-格式化字段

?BatchSkuMsgModify.prototype.formatter=function(cellvalue,options,rowdata)

?{

?return "<TextArea id='addiTextId"+rowdata.SkuId+"' style='width:98%;' rows='4'>"+rowdata[currentInstance.fieldName]+"</TextArea>";

?};

?//重寫post函數

?BatchSkuMsgModify.prototype.postData=function(urledit,sender)

?{

?$.post( urledit, $("#"+itemEditVars.itemEditClientId.formAldsItemEdit1).serialize())

???.done(function(myJsonResult)

???{

?????var data = $.evalJSON(myJsonResult);

?????ajaxResponseResult(data);

?????if (data.IsSuccess) {

???????if (!data.rows)

?????????showPrompt(currentInstance.title+"成功"+currentInstance.skuIds.length+"個!");

???????$("#listSkuDefine").trigger('reloadGrid');

???????setTimeout(function () { $(sender).dialog("close"); }, 0);

???????setTimeout(function () { $(sender).dialog("destroy"); }, 1000);

?????}

?????if(data.ErrMsg && $.trim(data.ErrMsg) != "")

???????alert(currentInstance.title+"出錯:\n\n" + data.ErrMsg);

???})

???.fail(function(data) {

?????ajaxResponseResult(data);

???})

???.always(function(myJsonResult) {

???});

?};

?//重寫-拼裝json

?BatchSkuMsgModify.prototype.setAddis=function()

?{

?var _addis="{rows:{";

?

???for(var i=0;i<this.skuIds.length;i++)

???{

?????_addis+='"'+this.skuIds[i]+'":"';

?????var tempVal=$("#addiTextId"+this.skuIds[i]).val();

?????var val=tempVal.replace(/\"/ig,"\'");

?????_addis+=val;

?????_addis+='"'

?

?????if(i!=this.skuIds.length-1)

?????{

???????_addis+=',';

?????}

???}

???_addis+="}}";

???this.addis=_addis;

?};

?//重寫-設置numIids到組件

?BatchSkuMsgModify.prototype.setNumIidsToCom=function()

?{

?$("#"+itemEditVars.itemEditClientId.HfNumIid).val(this.oneIid);

?};

?

?//新增-設置skuids到組件

?BatchSkuMsgModify.prototype.setSkuIdsToCom=function()

?{

?$("#"+itemEditVars.itemEditClientId.HfSkuIds).val(this.skuIds);

?};

?//重寫

?BatchSkuMsgModify.prototype.setAddisToCom=function()

?{

?$("#"+itemEditVars.itemEditClientId.HfSkuAddiStr).val(this.addis);

?};

?

?//確認按鈕的回調函數

?BatchSkuMsgModify.prototype.confirmCallback=function(sender)

?{

???this.setAddis();

???this.setNumIidsToCom();

???this.setSkuIdsToCom();

???this.setAddisToCom();

???currentInstance.postData(this.editUrl+"&rdm=" + Math.random(),sender);

?};

?//

?BatchSkuMsgModify.prototype.checkIsSelected=function()

?{

???if (this.skuIds == "") {

?????alert("請選中要批量修改附言的SKU!");

?????return false;

???}

???return true;

?};

??

?//實例

?var batchSkuAddi=null;

?openBatchSkuMsgDialogType={batchSkuAddi:0};

?openBatchSkuMsgDialog=function(typeCode)

?{

?if (typeCode==openBatchSkuMsgDialogType.batchSkuAddi)

?{

??if (batchSkuAddi==null)

??batchSkuAddi=new BatchSkuMsgModify("批量修改SKU附言","tableEditContent","tablePaper","Additional","x.aspx?method=UpdateMsgAdditional","<div id='descTempDiv'><table id='tableEditContent'></table><div id='tablePaper'></div></div>");

??currentInstance=batchSkuAddi;

??batchSkuAddi.removeDialog();

??batchSkuAddi.setOneIid();

??batchSkuAddi.setSkuIds();

??if(!batchSkuAddi.checkIsSelected())

??return;

??????batchSkuAddi.popUpDialog();

??????batchSkuAddi.createTable();

??????batchSkuAddi.initTable();

?}

?}

?//_______________________________生成描述_________________________________________________

?var descBatchModify=null;

?

?batchGenerateDesc=function(descNumIds,alertResult)

?{

?if(descBatchModify==null)

??descBatchModify=new BatchModify();

?descBatchModify.numIids=descNumIds;

?descBatchModify.setNumIidsToCom();

?descBatchModify.batchGenerateDesc(alertResult);

?}

?

?

?//_______________________________同步類(彈出單獨頁面,只要彈窗即可)_________________________________

?function SyncModify(){}

?

?myInherits(SyncModify,BatchModify);

?//重寫

?SyncModify.prototype.popUpDialog=function()

?{

?var urledit="./x.aspx?rdm="+Math.random();

?

?$.post(urledit,{numIids:this.numIids.toString()},function(data,textStatus,object){

??var str = "<div id='descTempDiv'>" + object.responseText + "</div>";

??????$(str).dialog({

???????title:"同步設置",

????????closeText: '關閉',

????????width: 1150,

????????height: 800,

????????maxHeight: $(window).height() * 0.9,

????????modal: true,

????????show: { effect: "fade", duration: 300 },

????????hide: { effect: "fade", duration: 300 },

????????buttons: {

??????????同步: function() {

????????????onAldsItemSync(this, $("#listItemDefine")); //在x.aspx定義

??????????},

??????????取消: function() {

????????????$( this ).dialog( "close" );

??????????}

????????}

??????});

?});

?}

?

?var syncModify=null;

?openSyncDialog=function()

?{

?if(syncModify==null)

??syncModify=new SyncModify();

?currentInstance=syncModify;

?syncModify.setNumIids();

?if(!syncModify.checkIsSelected())

??return;

?syncModify.removeDialog();

?syncModify.popUpDialog();

?}

?//____________________________同步SKU設置(彈出單獨頁面,只需彈窗)___________________________________

?function SyncSkuModify(){}

?myInherits(SyncSkuModify,BatchModify);

?

?SyncSkuModify.prototype.popUpDialog=function()

?{

?var urledit="./x.aspx?rdm="+Math.random();

?

?$.post(urledit,{numIid:currentInstance.oneIid.toString(),skuIds:currentInstance.skuIds.toString()},function(data,textStatus,object){

??var str = "<div id='descTempDiv'>" + object.responseText + "</div>";

??????$(str).dialog({

???????title:"同步SKU設置",

????????closeText: '關閉',

????????width: 1150,

????????height: 800,

????????maxHeight: $(window).height() * 0.9,

????????modal: true,

????????show: { effect: "fade", duration: 300 },

????????hide: { effect: "fade", duration: 300 },

????????buttons: {

??????????同步: function() {

????????????onAldsSkuSync(this, $("#listSkuDefine")); //在x.aspx定義

??????????},

??????????取消: function() {

????????????$( this ).dialog( "close" );

??????????}

????????}

??????});

?});

?}

?

?SyncSkuModify.prototype.checkIsSelected=function()

?{

???if (this.skuIds == "") {

?????alert("請選中要同步設置的SKU!");

?????return false;

???}

???return true;

?};

?

?var syncSkuModify=null;

?openSkuSyncDialog=function()

?{

?if($("#"+itemEditVars.itemEditClientId.HfNumIidFrom).val()=="none")

?{

??alert("沒有找到已經綁定的寶貝!要同步SKU設置,需要先綁定對應的寶貝,才能同步寶貝下面的SKU!");

??return;

?}

?if(syncSkuModify==null)

??syncSkuModify=new SyncSkuModify();

?currentInstance=syncSkuModify;

?syncSkuModify.setOneIid();

?syncSkuModify.setSkuIds();

?if (!syncSkuModify.checkIsSelected())

??return;

?syncSkuModify.removeDialog();

?syncSkuModify.popUpDialog();

?}

?//__________________________item批量(及單獨)解除綁定_________________________________

?function BatchDisBindingItem(){}

?myInherits(BatchDisBindingItem,BatchModify);

?

?// 對非綁定item取消勾選,是為了下一步批量解除綁定

?BatchDisBindingItem.prototype.cancelFreeItem=function()

?{

?var isAlert = false;

?var isBinded = false;

?var tempNumIids = jQuery("#listItemDefine").jqGrid('getGridParam', 'selarrrow');

?var tempNumIidsClone = this.cloneArr(tempNumIids);

?for (var i = 0; i < tempNumIidsClone.length; i++) {

???var numIidTmp = tempNumIidsClone[i];

???var curRowData = jQuery("#listItemDefine").jqGrid('getRowData', numIidTmp);

???if (curRowData.NumIidFrom == "none") {

?????isAlert = true;

?????jQuery("#listItemDefine").jqGrid('setSelection', numIidTmp);

???}

?}

?if (isAlert)

?{

???alert("未綁定的寶貝不能作解綁的動作!");

???// return true 表示已經alert了

???return true;

?}

?return false;

?}

?BatchDisBindingItem.prototype.popUpDialog=function()

?{

?var showStr='<div id="descTempDiv"><span style="color:red;">注意:您正在批量解除綁定,如果您解除了綁定,今后數據源寶貝設置有更新您的寶貝設置將不會同步更新!</span></div>';

?

????$(showStr).dialog({

??????title: "解除綁定",

??????closeText: '關閉',

??????width: 600,

??????height:300,

??????maxHeight: $(window).height() * 0.98,

??????minHeight: $(window).height() * 0.7,

??????modal: true,

??????show: { effect: "fade", duration: 300 },

??????hide: { effect: "fade", duration: 300 },

??????buttons: {

????????解綁: function() {

??????????disBindingItem(currentInstance.numIids,this);

????????},

????????關閉: function() {

??????????$(this).dialog("close");

????????}

??????}

????});

?}

?

?var batchDisBindItemInstance = null;

?batchDisBindingItem=function()

?{

?var isAlerted = false;

?if(batchDisBindItemInstance==null)

??batchDisBindItemInstance=new BatchDisBindingItem();

?currentInstance=batchDisBindItemInstance;

?if(batchDisBindItemInstance.cancelFreeItem())

??isAlerted = true;

?batchDisBindItemInstance.setNumIids();

?

?if(isAlerted)

?{

??if(currentInstance.numIids=="") return;

?}

?

?if(!batchDisBindItemInstance.checkIsSelected())

??return;

?batchDisBindItemInstance.removeDialog();

?batchDisBindItemInstance.popUpDialog();

?}

?disBindingItem=function(myNumIids,sender)

??{

????var urledit = "./x.aspx?method=DisBinding&NumIids="+myNumIids+"&rdm="+Math.random();

????$.get(urledit, {}, function (dataString, status, object) {

??????var data = $.evalJSON(dataString);

??????ajaxResponseResult(data);

??????if(data.IsSuccess==true)

??????{

????????$(sender).dialog("close");

????????$("#listItemDefine").trigger("reloadGrid");

??????}

????});

??}

??//____________________________sku批量及單獨解除綁定____________________________________________

??function BatchDisBindingSku(){}

??myInherits(BatchDisBindingSku,BatchSkuModify);

?

??BatchDisBindingSku.prototype.cancelFreeItem=function()

??{

???var tempNumIids = jQuery("#listSkuDefine").jqGrid('getGridParam','selarrrow');

?var tempNumIidsClone = this.cloneArr(tempNumIids);

?var isAlert=false;

?var isBinded = false;

?for(var i=0;i<tempNumIidsClone.length;i++)

?{

??isBinded = false;

??for(var j=0;j<bindedSkuArr.length;j++)

??{

??if(tempNumIidsClone[i]==bindedSkuArr[j])

??{

???isBinded = true;

???break;

??}

??}

??if(!isBinded)

??{

??isAlert = true;

??jQuery("#listSkuDefine").jqGrid('setSelection',tempNumIidsClone[i]);

??}

?}

?

?if(isAlert)

?{

??alert("未綁定的SKU不能作解綁的動作!");

??// 返回true表示已經彈出alert了

??return true;

?}

?return false;

??}

?

??BatchDisBindingSku.prototype.popUpDialog=function()

?{

?var showStr='<div id="descTempDiv"><span style="color:red;">注意:您正在批量解除SKU綁定,如果您解除了綁定,今后數據源寶貝設置有更新您的寶貝設置將不會同步更新!</span></div>';

?

????$(showStr).dialog({

??????title: "解除綁定",

??????closeText: '關閉',

??????width: 600,

??????height:300,

??????maxHeight: $(window).height() * 0.98,

??????minHeight: $(window).height() * 0.7,

??????modal: true,

??????show: { effect: "fade", duration: 300 },

??????hide: { effect: "fade", duration: 300 },

??????buttons: {

????????解綁: function() {

??????????disBindingSku(currentInstance.oneIid,currentInstance.skuIds,this);

????????},

????????關閉: function() {

??????????$(this).dialog("close");

????????}

??????}

????});

?}

?

?var batchDisBindSkuInstance = null;

?// 批量

?batchDisBindingSku=function()

?{

?var isAlerted = false;

?if(batchDisBindSkuInstance==null)

??batchDisBindSkuInstance=new BatchDisBindingSku();

?currentInstance=batchDisBindSkuInstance;

?if(batchDisBindSkuInstance.cancelFreeItem())

??isAlerted = true;

?batchDisBindSkuInstance.setOneIid();

?batchDisBindSkuInstance.setSkuIds();

?

?// 如果已經彈過一次了,那再次判斷是否沒有勾選的時候,就不要再彈了

?if(isAlerted)

?{

??if(currentInstance.skuIds == "") return;

?}

?

?if(!batchDisBindSkuInstance.checkIsSelected())

??return;

?batchDisBindSkuInstance.removeDialog();

?batchDisBindSkuInstance.popUpDialog();

?}

??// 單獨

??disBindingSku=function(numIid, skuIds, sender) {

????var urledit = "./x.aspx?method=DisBinding&NumIid=" + numIid + "&SkuIds="+skuIds+"&rdm=" + Math.random();

????$.get(urledit, {}, function (dataString, status, object) {

??????var data = $.evalJSON(dataString);

??????ajaxResponseResult(data);

??????if (data.IsSuccess == true) {

????????$(sender).dialog("close");

????????$("#listSkuDefine").trigger("reloadGrid");

??????}

????});

??}

?

})();

以上這篇利用js的閉包原理做對象封裝及調用方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/249185.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/249185.shtml
英文地址,請注明出處:http://en.pswp.cn/news/249185.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Flask系列06--(中間件)Flask的特殊裝飾器 before_request,after_request, errorhandler

一.使用 Flask中的特殊裝飾器(中間件)方法常用的有三個 app.before_request # 在請求進入視圖函數之前app.after_request # 在請求結束視圖函數之后 響應返回客戶端之前app.errorhandler(404) # 重定義錯誤信息before_request def func():passafter_request def func(ret): # …

Flask 中內置的 Session

Flask中的Session非常的奇怪,他會將你的SessionID存放在客戶端的Cookie中,使用起來也非常的奇怪 1. Flask 中 session 是需要 secret_key 的 from flask import session app Flask(__name__) app.secret_key "DragonFire" secret_key 實際上是用來加密字符串的,如果…

CSS像素、物理像素、邏輯像素、設備像素比、PPI、Viewport

最近看了很多這方面的文章&#xff0c;能搜到的基本看了個遍&#xff0c;但感覺還是似懂非懂&#xff0c;知道這個東西&#xff0c;很難說出這是個什么東西&#xff0c;先整理一些概念&#xff0c;慢慢消化&#xff0c;以后慢慢探索其中的原因。 1、PX(CSS pixels) 1.1 定義 …

【轉】10條你不可不知的css規則

10條你不可不知的css規則 Posted on 2006-12-20 10:33 雨中太陽 閱讀(343) 評論(1) 編輯 收藏 &#xff1a;【譯】10條你不可不知的css規則正文&#xff1a; Published December 6th, 2004 in CssStaff Tags: No Tags. 原文地址&#xff1a;Ten CSS Tricks You May not Know k…

Python 面向對象【1】

對象 屬性 方法面向對象特征&#xff1a;分裝 繼承 多態【不同對象對同一方法響應不同行動】類定義class xxx:........類對象類對象支持兩種操作&#xff1a;屬性引用和實例化 屬性引用 使用和 Python 中所有的屬性引用一樣的標準語法&#xff1a;類對象名.屬性名 類對象創建…

【前端面試】HTML5+CSS3初級面試1

最近剛好在看前端的面試&#xff0c;把看到的內容總結一下&#xff0c;方便大家一起學習。 1、簡單說一下對HTML5CSS3的了解。 HTML5和CSS3不僅是兩項新的Web技術標準&#xff0c;而且代表了下一代HTML和CSS技術。其未來的發展前景已經可以預見&#xff0c;那就是HTML5必將被越…

福大軟工 · 第八次作業(課堂實戰)- 項目UML設計(團隊)

1、隊伍信息&#xff1a; 隊伍名稱&#xff1a;彳艮彳亍團隊 學號名本次作業博客鏈接031602219奇豪(隊長)https://www.cnblogs.com/S031602219/p/9822576.html041602209毓明http://www.cnblogs.com/mingsonic/p/9820702.html041602204水源http://www.cnblogs.com/littlenorthwe…

【轉發】實現yolo3模型訓練自己的數據集總結

原文鏈接&#xff1a;實現yolo3模型訓練自己的數據集總結 經過兩天的努力&#xff0c;借鑒網上眾多博客&#xff0c;在自己電腦上實現了使用yolo3模型訓練自己的數據集并進行測試圖片。本文主要是我根據下面參考文章一步步實施過程的總結&#xff0c;可能沒參考文章中那么詳細&…

詳解 vue-cli 的打包配置文件代碼(帶注釋)

一、前言 對于webpack基礎不好&#xff0c;node指令不通的童鞋。估計對自己搭建Vue、react腳手架是相當頭疼的&#xff0c;有種無從下手的感覺。然而&#xff0c;從頭看這2塊&#xff0c;耗時太長&#xff0c;而且說實話得練才行&#xff0c;不練練手看不明白。那大多數人就采取…

NoClassDefFoundError

技術之路最公平也最殘酷的原因是&#xff1a;沒有捷徑&#xff0c;需要日積月累的積累&#xff0c;以及對技術持久的熱情。NoClassDefFoundError這個錯誤一般就兩種情況&#xff1a;1、沒有引入相應的jar包2、兩個jar包中都有這個class&#xff0c;無法確認是引用的哪一個&…

【記錄一下】從0到1 我的python開發之路

請設計實現一個商城系統&#xff0c;商城主要提供兩個功能&#xff1a;商品管理、會員管理。商品管理&#xff1a;- 查看商品列表 - 根據關鍵字搜索指定商品 - 錄入商品會員管理&#xff1a;【無需開發&#xff0c;如選擇則提示此功能不可用&#xff0c;正在開發中&#xff0c;…

Python10/22--面向對象編程/類與對象/init函數

類&#xff1a; 語法: class關鍵字 類名# 類名規范 大寫開頭 駝峰命名法class SHOldboyStudent: # 描述該類對象的特征 school "上海Oldboy" name "矮根" age 68 gender "unknown" # 在定義階段 # 只要包含該類的py被…

Django Form和ModelForm組件

Form介紹 我們之前在HTML頁面中利用form表單向后端提交數據時&#xff0c;都會寫一些獲取用戶輸入的標簽并且用form標簽把它們包起來。 與此同時我們在好多場景下都需要對用戶的輸入做校驗&#xff0c;比如校驗用戶是否輸入&#xff0c;輸入的長度和格式等正不正確。如果用戶輸…

ESLint 規則詳解

前端界大神 Nicholas C. Zakas 在 2013 年開發的 ESLint&#xff0c;極大地方便了大家對 Javascript 代碼進行代碼規范檢查。這個工具包含了 200 多條 Javascript 編碼規范且運行迅速&#xff0c;是幾乎每個前端項目都必備的輔助工具。可是&#xff0c;這么多規則&#xff0c;每…

全文搜索引擎 ElasticSearch 還是 Solr?

原文鏈接 最近項目組安排了一個任務&#xff0c;項目中用到了全文搜索&#xff0c;基于全文搜索 Solr&#xff0c;但是該 Solr 搜索云項目不穩定&#xff0c;經常查詢不出來數據&#xff0c;需要手動全量同步&#xff0c;而且是其他團隊在維護&#xff0c;依賴性太強&#xff0…

對局匹配

問題描述小明喜歡在一個圍棋網站上找別人在線對弈。這個網站上所有注冊用戶都有一個積分&#xff0c;代表他的圍棋水平。小明發現網站的自動對局系統在匹配對手時&#xff0c;只會將積分差恰好是K的兩名用戶匹配在一起。如果兩人分差小于或大于K&#xff0c;系統都不會將他們匹…

NodeJS作為Web架構中間層的使用

截至2016年12月&#xff0c;中國網民規模已達7.31億。傳統的網站系統是否能夠支撐得起如此龐大的且不斷增長的用戶訪問并且為用戶提供體驗友好的頁面&#xff1f; 一、傳統的前后端&#xff1a; 二、傳統的前后端分離問題&#xff1a; 性能問題&#xff1a; 1、渲染、數據都在…

Springboot項目修改html后不需要重啟---springboot項目的熱部署

一、spring-boot-devtools 在pom中直接引入依賴 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional> </dependency> 設置以下兩項&#xff08…

Hibernate中session的get方法和load方法的區別

一.發送SQL時機&#xff1a; load方法采用延遲加載&#xff08;lazy懶加載&#xff09;&#xff0c;執行到這行代碼的時候&#xff0c;不會發送SQL語句&#xff0c;當真正使用這個對象的數據&#xff08;對象的數據不包括主鍵&#xff09;的時候才發送SQL語句&#xff1b; get…

Node.js Web 開發框架大全《中間件篇》

這篇文章與大家分享優秀的 Node.js 中間件模塊。Node 是一個服務器端 JavaScript 解釋器&#xff0c;它將改變服務器應該如何工作的概念。它的目標是幫助程序員構建高度可伸縮的應用程序&#xff0c;編寫能夠處理數萬條同時連接到一個&#xff08;只有一個&#xff09;物理機的…